GEOG 485:
GIS Programming and Software Development

Error message

Notice: unserialize(): Error at offset 14 of 14 bytes in variable_initialize() (line 1255 of /net/www/www.e-education.psu.edu/htdocs/drupal7/includes/bootstrap.inc).

2.1 More Python fundamentals

PrintPrint

At this point, you've learned most of what you need to know about ModelBuilder, and this may be enough to address many of the GIS tasks that you face in your work. However, as useful as ModelBuilder is, you'll find that sometimes you need Python to build extra intelligence into your geoprocessing. For example, you may need to construct complex query strings, or employ conditional logic. You may need to read, or parse, varying types of user input before you can send it to a tool as a parameter. Or you might need to do complex looping that, at some threshold, probably becomes easier to write in Python than to figure out with ModelBuilder.

In Lesson 1, you saw your first Python scripts and were introduced to the basics, such as importing modules, using arcpy, working with properties and methods, and indenting your code in try/catch blocks. In the following sections, you'll learn about more Python programming fundamentals such as working with lists, looping, if/then decision structures, manipulating strings, and casting variables.

Although this might not be the most thrilling section of the course, it's probably the most important section for you to spend time understanding and experimenting with on your own, especially if you are new to programming.

Programming is similar to playing sports: if you take time to practice the fundamentals, you'll have an easier time when you need to put all your skills together. For example, think about the things you need to learn in order to play basketball. A disciplined basketball player practices dribbling, passing, long-range shooting, layup shots, free throws, defense, and other skills. If you practice each of these fundamentals well individually, you'll be able to put them together when it's time to play a full game.

Learning a programming language is the same way. When faced with a problem, you'll be forced to draw on your fundamental skills to come up with a workable plan. You may need to include a loop in your program, store items in a list, or make the program do one of four different things based on certain user input. If you know how to do each of these things individually, you'll be able to fit the pieces together, even if the required task seems daunting.

Take time to make sure you understand what's happening in each line of the code examples, and if you run into a question, please jot it down and post to the forums.