Friday, May 23, 2014

GIS Programming Module 1 - Introducing Python

In the first week of GIS Programming, we were introduced to Python by running a script which created a folder structure for our coursework.  We examined the script first, to get an idea of what it generally looks like. Other than practicing a couple of print commands in the Scripting Window, however,we are only running script at this point, not yet writing it.

On the left is an image of the folder structure that I created on my S:\ drive by running the Python script provided by our professor.  The parent folder is called GISProgramming, and contains 12 subfolders, for modules 1-12 of this course.  In turn, each of those folders contains three folders for Data, Scripts, and Results.  Rather than take a long time creating these 36 subfolders by hand, we were able to run the Python script and have them all appear in less than a second.  Once we can write script of our own, we'll be able to automate any number of tedious and time-consuming chores which might be much worse than this small task!

Here is my process summary of how I ran the script to create my folder structure:
 Running the script in PythonWin
1.       This script, CreateModuleFolders.py, will create a folder called GISProgramming, with subfolders, within the main S:\ drive.  There is no need to create any other folder before running the script.
2.       First, copy the script CreateModuleFolders.py from the R:\ repository drive into the student S:\ drive.  (I have a subfolder gds but I put the script at that same level,in the main S:\ drive.) 
3.       Go to the S:\ drive and Rt.Click the CreateModuleFolders.py file.
4.       Select Edit with PythonWin.
5.       A window for PythonWin will come up, with the script window open within it.
6.       Two ways to run the script: 1) Ctrl-R;  2) click on the runner icon at the top of the PythonWin window.  The script can be double-clicked from where it’s stored, as well.
7.       A little confirmation dialog box comes up.  Click on the Run button without changing anything. 

8.       The folder structure of S:\GISProgramming is created, with its 12 Module subfolders.  Each subfolder in turn has 3 empty folders in which to store Data, Results and Scripts from the 12 modules of this class.

No comments:

Post a Comment