In this video, Jennifer Harrison explains the difference between a scripting language and a programming language. Learn what Python scripting is and how scripts are useful to the GIS professional.
- [Instructor] A scripting language is a programming language that you can use to write scripts. We use scripts in RGIS to automate data management and to manipulate maps. What is a script? Scripts are a sequence of instructions written as plain text that can be run to perform a task or a series of tasks. Scripts can discover data, they can make decisions, they can manipulate software and data; and they can automate tasks, saving us a lotta time.
For example, a script can do many things: load the CSV file into a file geodatabase feature class, project it to UTMs on 15 North, add a date field, and calculate it to today's date. We just run the script, and it does all the work for us. What is the difference between a scripting language and a programming language? Scripts are programs that are typed in as plain text and executed directly as a text file. They're compiled on the fly by a compiler on a local machine.
This means that if I write a Python script and email it to my colleague, my colleague will have to have a Python compiler loaded on their machine in order to run the script. Scripts can be very short and often succinct. Scripting languages usually require less setup. Programming, however, involves writing more complex code that results in an actual application. Programs must be compiled and converted to executable files before they can be executed.
This means that I can email my program, which will have a .exe extension, to a colleague; and that colleague can execute the file without having any specific software on their machine. So the program is compiled by the programmer when it's written. So why do we script in the ArcGIS world? Scripts help us manipulate large amounts of data. For example, we could run a script that'll search through 10,000 streets and see if there are any overlapping address ranges.
That would take a tremendous amount of time to do manually. Scripts can also discover hidden information about our data. For example, we can write a script that'll traverse an entire directory tree and make a unique list of all the coordinate systems used by all the featured classes in the entire directory tree. And these next three are all pretty similar. They all involve running a workflow multiple times. With scripts we can automate repeatable processes.
For example, go out to this FTP site and download this data every Sunday night, unzip it, and load it into SDE. We can also use scripts to test alternate scenarios. For example, what happens if I do the same thing, but I change my buffer size to a hundred miles? So we have a script capturing the process, and we just run the script, and let it do the whole job for us. And, finally, our scripts can execute complex or tedious tasks while eliminating user error.
So, for example, we'll give John a dropdown list to choose from when he runs his process so he doesn't type in the wrong information.
- Writing and running Python scripts in IDLE
- Making scripts flexible with variables
- Commenting scripts
- Manipulating string data
- Object-oriented programming in Python
- Creating loops
- Reading and writing text files
- Capturing input at runtime
- Documenting your scripts