Friday, July 25, 2014

Module 9: Debugging and Errors

Errors are an inevitable part of scripting.  It's not a matter of if they will happen, but when and where.  Knowing how to find the when and where is a vital part of scripting.  Syntax errors, exceptions, and logic errors are all possible types of errors. There are a number of ways to find where errors exists.  The PythonWin toolbar is a good place to start.  It can tell you if a an error occurred and on what line.  The debugger tool in PythonWin is also another useful tool in finding errors.  Being able to step through lines of code one at a time can pinpoint the location that a script stops working.  Commenting out lines of code and adding print statements are also helpful in finding errors.  Lastly, the try-except tool can be used to allow a script to run even if specific sections of code contain an error.

This weeks assignment was to locate script errors and correct them and to use the try-except command to show how a script can run even with an error present.

The first script contained two errors that needed to be found and fixed to display the names of the airports from module 6 data.
Script1_Results

The second script contained 8 errors that needed to be corrected.  I was able to locate the errors by using selective commenting and interpreting the interactive window results.

Script2_Results

The third script contained an error, but instead of fixing the error, we were to insert a try-except command that would allow the script to run even though there was an error in part A.

Script3_Results

Friday, July 18, 2014

Working with Rasters

Raster files are images that are used in ArcMap.  They can come from a variety of sources and formats including .img, .tif, and .jpg formats to name a few.  Python can be used to describe components of a raster file, to remap and reclassify landcover, and to calculate slope and aspect.  The most commonly used extension in working with raster files is the Spatial Analyst extension.  Within Python, the arcpy.sa module is most used and all functions should be imported.

Our lab this week had us use a number of arcpy.sa functions to remap and reclassify landcover as well as calculate a desired slope and aspect of the elevation raster file.  My final result can be seen in Results1.

Results1

I actually understood most of this lab.  Not sure why this week was so much more different than the previous weeks.  I still struggle with retaining the code and its proper usage, so I spend a lot of time looking for examples.  I would love to find a way to remember some of this stuff as it would be useful in my everyday work with ArcMap.  Not so much the spatial analyst, but definitely some of the other modules and functions we have seen up to this point.

Monday, July 14, 2014

Working with Geometries

Geometries can best be described as the bits and pieces that make up a feature.  This includes everything from a point or vertices that display the feature to the attribute data that contains the information on where those points should be placed.  Features such as polylines and polygons contain an array of point geometry.

This weeks lab we were to create a text file from an existing shp file.  A for loop with a .getPart() method was used to get all parts of the line feature class.  The second column of data shows each vertex point that was used to create the polyline for each river.

Mod7 Results

I'm not of fan of programming.  I find that it's the little mistakes that are sending me headlong into a brick wall every week.  But, for some reason, walking away from it for a day or two always seems to make things more clear.

Friday, July 4, 2014

Exploring and Manipulating Spatial Data

This week, we used Python to explore and manipulate data.  I still do not think I am getting the hand of for loops.  However, I did manage to create a half working script. These are the results of my script:


Results
I'm not entirely sure what I am doing wrong.  But, it's the 4th of July and I'm off to celebrate with some fireworks.  I hope you do too.