Sunday, May 17, 2015

An Introduction to Python & Computer Programming for GIS

A new semester, a new challenge- and this summer finds your humble blog author embarking on an endeavor to learn the basics of writing script for GIS with Python- ESRI's scripting language of choice for ArcGIS.  It is probably relevant to point out here that my prior experience with scripting in GIS, in its totality, involved listening to a particularly vocal co-worker complain about simple VBA operations for the version 9.2 ArcGIS we were using in those years, and I do recall him mentioning Python a few times as well.  Now (many years later) we are on ArcGIS version 10.2, and Python has been declared the victor in becoming the go-to script for automating various tasks in ArcGIS.

Python lists being open source and relatively simple/user-friendly among its advantages, and it is essential for any competent GIS professional to be at least familiar with its workings.  Even better, though, is to be at least somewhat well-versed in its use for automating geoprocessing tools, and that is the aim of this course.  We begin with learning the basics of opening the scripting and interaction windows in our Python editor- PythonWin.  From there we move on to becoming familiar with some of the basics on problem solving processes with scripts, and modeling with pseudocode and flowcharts.  Like any language, Python has its idiosyncratic ins and outs, and familiarity with some of their fundamentals is necessary as a start.



The above is a screenshot of a directory of folders that was created with a Python script.  The script was run, and the folders created, on the remote desktop that we use to access ArcGIS Desktop.  ESRI does, however, provide a free-of-charge, trial version of the software for students, good for one year.  Working on the remote desktop can be slow at times, especially on weekends when it seems that everyone in class is finishing their work, so it's often easier to use the software version run locally, without the remote connection.  The script provided for this week's exercise, that creates a directory of folders that will be used this semester, specifically references the drive used on the remote desktop connection though, and as-is must be run there to work.  Upon opening the script file in the PythonWin editor I found the specific line that does this with the simple command of "courseFolder = x:\xxx."  Running the script locally, on my laptop, I changed the location referenced (the "x"s in my example here) to the information for my personal hard drive, and ran the script there.  Lo and behold, it created the file directory (as in the screenshot above) right where I specified- on my computer.  This small triumph of successfully modifying provided code is to be savored, for the impression that these will be relatively rare this semester is rather striking.  Onward and upward we will continue though, on this exploration into the arcane and hallowed world of computer programming... 



No comments:

Post a Comment