Friday, July 26, 2013

Creating Custom Tools



Pretty easy (if you do the exercises) and useful lab this week.  We took an existing script that will clip multiple input files and turned it into an ArcGIS tool.  First we created a toolbox in ArcCatalog and added a new script tool to the toolbox.  Then we associated the tool with our existing script.  We needed to make a couple modifications to the script to connect the tool's input fields with inputs that the script needed.  Finally we modified the script's print messages into arcpy.AddMessage() so the messages would appear in the dialog's own message space.

Overall, pretty quick but a good basis for how to make ArcGIS custom tools in the future.

Wednesday, July 17, 2013

Debugging and Error Handling


This week's assignment covered debugging and error handling.  This is a topic that is useful in any form of programming, not just when writing GIS scripts.  Our first exercise (above) involved correcting some syntax errors in a simple script that reads out the names of various airports in a shapefile.  Nothing too difficult here and the IDE that I use (PyCharm) helps point out many of those errors.


The second part of the assignment similarly needed corrections.  This script used some of the functions we learned last week in the Map Scripting module, so it was interesting to try to find the syntax errors in that code which we've not used much.


Finally, the grads had the chance to implement a couple try-except statements on code that contained errors. We didn't fix the errors, but implemented the try-excepts so that the code would still run, even if it ran into a problem.  This is a super useful tool to have as the exception can return good information about the error and prevent things from running off the rails entirely.  

Overall, a good week, lots of useful tools for the toolkit.

Monday, July 15, 2013

Remote Sensing


This week's assignment focused on using remote sensing resources and raster classification (both unsupervised and supervised) methods in an attempt to locate unknown archaeological sites.  Our first attempt (above) was an "unsupervised" classification of land cover by the ArcGIS program.  Unsupervised means that the program basically tried to divide the region up into classes (we asked for 8 classes) based on the coloration of our aerial (which was gray-scale).  This led to a lot of errors and redundancy.  Specifically, water bodies (which seem to be quite green) and forest areas were frequently confused. In the same way, the mounds at Cahokia Mounds State Park, and specifically Monk's Mound, were classified along with field grass and roads and buildings.

In the second part of the assignment, we created a point shapefile and selected land cover around the map.  I added over 60 points and manually classified them as water, forest, fields, roads, buildings and mounds. Unfortunately, the results of this "supervised" classification were not much better than the unsupervised.  There was still a lot of redundancy and errors in areas with similar color (water/forests) and some areas (like residential areas) were classified as a mix of water and forest rather than building sites.  It was interesting to try these methods, but I'm doubtful on whether they can be effective for archaeological work.

Finally, the grads played around with chi-square tests.  This test is super useful and I've used it in classes in the past.  The key seems to be finding or setting up data in a way that allows the use of this test.  That is a tool that I want to be ready and able to use when analyzing field results.

Sunday, July 14, 2013

Geometry and Rasters


We're starting to get into the nuts and bolts of reading and writing feature classes now. Part 1 of the assignment this week involved reading out the components of a shapefile and writing those to a text file.  This was a pretty straightforward assignment, though there are some subtleties with getting the "parts" of the geometry out of the shapefile.

Part 2 involved working with rasters.  I really wish we had more time for this topic as I think I will be working with rasters a lot in the future and I feel like we are only scratching the surface here.  The goal was to read in a raster and then apply various raster functions (slope, aspect - with varying conditionals) to create a new raster based on the combination of temporary rasters.  The end result appears above.

Finally, for grad students, Part 3 involved reading in the "parts" that we originally wrote out to a text file in Part 1 and build a new feature class.  This was actually pretty challenging.  While my code works and appears to match the desired outcome, I'm not completely happy with it.  One thing I don't understand is why the rows in the attribute table do not match the order that they are read in (and the order of the OID that they had in the text file).  I imagine there is some sort of object referencing/ordering going on that is outside our control, but it is somewhat troubling not having that level of control.  Overall, a good assignment this week and exposed a lot of the power of arcpy and GIS programming.