Friday, July 25, 2014

GIS 5103 Module 9: Debugging and Error Handling



This week's module formally introduced us to the tools and tasks involved in debugging scripts.  While I'm sure we have all been forced to debug our scripts throughout the course, this module taught us how best to handle the inevitable errors that will plague us in our careers.  The debugging tool in PythonWin and try-except statements in particular will be useful in the future.

This assignment differed from previous ones in that we were given three scripts and tasked with debugging them.  The first two scripts contained several errors we needed to locate and correct for them to run properly.  For the final script, we were to insert a try-except statement that would trap the error in part A, print the error message to the interactive window, and continue to run part B of the script.  Below are screenshots of the interactive window messages resulting from my corrected scripts.



Script 1 interactive window after debugging.

Script 2 interactive window after debugging.


Script 3 interactive window after adding try-except statement.

Friday, July 18, 2014

GIS 5103 Module 8: Working with Rasters

This week saw us experiment with manipulating raster data using Python script.  As we did previously with vector data, we learned how to return information on raster files, such as spatial reference and cell size.  Because rasters are often large files, Python script will reference a raster object and create temporary rasters rather than create multiple raster files.  This is efficient, but it does require one to remember to save the final raster, otherwise nothing will remain after the script is complete.  

As in previous modules, our assignment required us to utilize many of the tools learned about in the exercise and expand them a bit further.  After creating a for loop to ensure the Spatial Analyst extension was available, our script needed to go through several steps.  First, it needed to use the RemapValue and Reclassify functions to collapse three separate classification of the landcover raster to one.  It then needed to create temporary rasters that would be used to create a final output between specific ranges of slope and aspect.  To do this, we needed to create four temporary rasters.  Two of the rasters were to define the slope range, with one including slope less than the maximum value while the other included slope above the minimum value.  The other two rasters would do the same for aspect.  These four rasters were to be combined, along with the reclassified landcover raster, using the "&" operator.  This would create a final raster with slope and elevation between the specified ranges along with the reclassified landcover data.  This final raster then needed to be saved in order to be permanent.  A screenshot of this raster can be seen above.  We were also required to insert print statements in our script to show in the interactive window the process of the script as it was run (see screenshot below).






Wednesday, July 16, 2014

GIS 5265 Module 9: Remote Sensing



I was already looking forward to working with remotely sensed data next semester, so I found this module an enjoyable introduction.  Our task this week was to download a DEM of the Cahokia region and produce two raster classifications of that image.  The classification process divides the target image into categories that, ideally, reflect categories of land cover on the ground.  An unsupervised classification creates the classified raster automatically, with the user defining the number of categories and other limited variables.  A supervised classification, on the other hand, bases the output classified raster on a classification scheme provided by the user.  In this case, we created a new point shapefile composed of 30 points placed within our intended land cover categories.  This shapefile functioned as the input for the "Create Signatures" tool to create the classification file used with the "Maximum Likelihood Classification" tool.  If we were successful in our placement of control points, the output classified raster would expand the classification to cover the image.

Both my unsupervised and supervised classified rasters succeeded in some areas of classification while failing in others.  The biggest problem was the expansion of some categories to include areas I would rather be classified differently.  The unsupervised classification captured a wide range of land cover types in the two categories representing the most reflective objects, notably including Monk's Mound.  Perhaps additional classes would have teased out light grass, bare ground and the mound from roads and buildings.

I attempted to create a category specifically for Monk's Mound in the supervised classification; unfortunately, as can be seen above, the mound was still mostly classified along with roads, buildings, and light grass.  This isn't completely surprising since the mound is covered in grass, but I had hoped to capture some difference with the supervised classification.  As in the unsupervised classification, however, Monk's Mound does show up quite clearly as a distinct shape.  More tweaking of the input classification scheme would likely lead to a more accurate output.  Even as they are, both classified rasters could be useful if one were looking for new sites or interested in an overview of the land cover around Cahokia.

Thursday, July 10, 2014

GIS 5103 Module 7: Working with Geometries


The week saw us going further with the use of cursors and nested for loops.  Our exercise and assignment allowed us to explore getting coordinate data from points, lines, polygons and multipart features.  Although I was a little confused on the exact function of cursors when they were first introduced, this module helped me get a better understanding of their syntax and use.
An additional task required by the assignment was to create and write to a text file (see screenshot above).  This was covered in a previous chapter, so I am glad to get experience with editing text files in Python this week.  It is interesting to see how the syntax learned in previous modules is incorporated in new tasks each week.  I have even begun experimenting with Python in my internship, with varying levels of success.

Below is a copy of the pseudocode from my process summary.  Pseudocode is something I have neglected a bit throughout the course, but I can see how useful it would be as scripts increase in complexity.



Start
    import modules
    allow overwrite of previous data
    set workspace

    variable1 = "rivers.shp"
    set search cursor to retrieve variable1's "OID"  and "NAME" fields + full geometry object
    create/open writable text file "rivers_tevans.txt" in S:\GISProgramming\Module7\Data
   
    begin for loop for cursor:
                print "NAME" field
                set index variable/vertex ID
                for loop for point in row with .getPart function
                        add 1 to index variable
                        write to text file row's OID, Vertex ID, X coordinate, Y coordinate, and name
                        print OID, Vertex ID, X coordinate, Y coordinate, and name
  close text
  delete row and cursor

End

Wednesday, July 9, 2014

GIS 5265 Module 8: 3D Modeling


This week introduced us to the use of ArcScene for creating and displaying archaeological data.  We were given a study area and shovel test data; from this we created three-dimensional layouts showing shovel test depth as well as the relative depths of three soil strata.  We went further by creating interpolated surfaces from the shovel test data depicting the surfaces of each stratum (above).  These surfaces gave us a better idea of the trajectory of the strata than the shovel tests alone.  However, to make the differences in depth stand out, we used a high vertical exaggeration value.
An additional task for grad students was to create another three-dimensional scene with a cross-section of strata depth data derived from the interpolated raster surfaces.  For both layouts, I went with textual scale information rather than a visual scale due to the distortion of the 3D image as well as the vertical exaggeration.



We were also introduced to the Fly tool of ArcScene.  Below is a recording of a fly-through of the shovel test data.  While I can imagine the Fly tool would not be something used on every project, it does allow the user to view data from different perspectives; recording a fly-through gives others the opportunity for multiple perspectives as well.


Fly-through of shovel tests.


While not part of the assignment, a note in the lab instructions briefly described how to incorporate elevation data into ArcScene.  Although I did not have much time to experiment, I was able to successfully incorporate elevation data from a DEM (downloaded from USGS.gov) into our shovel test data and create interpolated surfaces.  For this image I set the vertical exaggeration to 10 rather than 20.
 


Friday, July 4, 2014

GIS 5103 Module 6: Exploring & Manipulating Spatial Data


This week's module took us deeper into working with GIS data using Python scripts.  An important initial task was to explore how to check for the existence of data files and, if they exist, to look at their attributes (datatype, for example).  This is something one can do without much thought through the ArcCatalog GUI, but Python also provides easy access if the correct syntax is known.  We then further explored the use and manipulation of lists, tuples, dictionaries, and cursors.  It took me some time to understand how cursors work; they provide access to the rows of GIS attribute tables.  Like lists, cursors can be used in loops to iterate through each row for particular tasks.  The last major task of our assignment was to populate a dictionary using a search cursor and for loop.  The cursor was required to return only certain rows that met the criteria of an SQL query and then return two particular fields from those rows.  The dictionary was then populated with the data from these two fields.  A finishing touch this week was to add print messages throughout the script to provide updates in the interactive window on the status of the operations being run (see screenshot below).  This can be useful with scripts such as this that can take some time to finish.  Without the messages, one will be left in the dark on the status of the script's run.  

This was a challenging assignment that took some time and thought to work out properly.  I appreciated the extra time provided for this module.  



Wednesday, July 2, 2014

GIS 5265 Module 7: Surface Interpolation




The main focus of this week's module was to experiment with a variety of surface interpolation methods in interpreting artifact and population density.  Surface interpolation produces a continuous surface from point data.  This could be useful if, as in our readings, one were attempting to identify large-scale communities or social interaction over distances that may not be obvious from point data.  In the above maps of Volcan Baru, for example, the surface interpolations were derived from shovel test point data, specifically the number of artifacts from each shovel test.  These interpolations may give us some idea of the social interaction of what may at first appear to be separate sites.

In addition to surface interpolation, we also were required to convert text and AutoCAD data into more GIS friendly formats.  This is something GIS specialists deal with quite often, and I was glad to get some practice working with them.

Graduate students were also required to do some more experimentation with the inverse distance weighted interpolation method.  By doing so, we saw first hand that tweaking the parameters of interpolation methods can have a significant effect on the outcome.  By changing the power parameter, the surface interpolation goes from extremely smooth with little detail (power of 0.5) to being little better than the original point data (power of 10).  The default power of 2 seemed the right balance to see potential community interactions without stretching the data too far.