Monday, June 22, 2015

Python and Geoprocessing

 
 
This week's lesson focused on writing Python script for geoprocessing tools. While these tools can be used in ArcMap, writing custom scripts can increase the potential of tools. 

The lecture, readings, and exercise that prepared us to write our own script included material on importing Arcpy modules, classes, functions and tools.  We practiced setting a workspace, creating variables, working with parameters, learning syntax for commonly used code, working with messages, and using a few geoprocessing tools.  Then we wrote our own geoprocessing code in order to create a 1000 meter buffer around hospitals, dissolving the overlapping perimeter lines.  We also set the XY coordinates for each hospital. After each geoprocessing tool was run, a line of code asked for a message to be printed, allowing the user to see if each step had run successfully. The image above shows that the script ran successfully in PythonWin.  In ArcMap, running the script produced the new shapefiles and added them as layers to the map.

This week's reading assignment was Chapter 5, and for me it was the most essential one so far, giving me several "ah-ha" moments as I finally understood some of the concepts and language that have been frustrating me up to this point.  Up until now, I didn't really get how the code we were writing actually made things run.  Things are clicking a bit better now.

Thursday, June 18, 2015

Geoprocessing in ArcGIS

 
 
In Module 5, the lesson addressed the following objectives:
  • creating a toolbox
  • creating a tool using ModelBuilder
  • setting model parameters
  • exporting a script from ModelBuilder
  • updating a model-derived script to work outside of ArcMap
  • creating a script tool
The task was to use ModelBuilder to clip a "soils" layer to the extent of another layer, "basin", then to select soils within the clipped output that were not prime farmland and to erase them.  The image above shows the result.
 
Using ModelBuilder was straightforward and fun (compared to writing the script from scratch), and it helped me visualize the process so that when we did have to update the script to work outside of ArcMap, I actually understood what was written.  The three tools, Clip, Select, and Erase, were linked with inputs and outputs whose parameters we manipulated.  This also clarified the process for me. 


Thursday, June 11, 2015

Fixing things

 This is the result of running the first code once I had fixed a few syntax errors.  Little things like capitol vs. lower-case letters, or an added letter in a word make a difference, and code won't run if it's incorrect.
 This script had eight errors to fix.  I commented-out all but the top and ran through the code bit by bit, looking at the error messages in the interactive window and correcting the code based on the message.  Some errors were syntax errors, others were problems with objects and functions.
This script shows the result of using a try-except statement to catch an error.  It took a while to get the except message written and placed correctly, but it finally worked.

The lab this week was very helpful, and I'm glad it came earlier on in the course.  I wish I had learned it for last week's lab!

Tuesday, June 9, 2015

Using lidar to uncover archaeological landscapes at Angkor


Article: “Uncovering archaeological landscapes at Angkor using lidar”

Damian H. Evans, Roland J. Fletcher, Christophe Pottier, et al


While there has been a long history of archaeological investigation of the structures associated with Angkorian civilization, our understanding of the complex system of civic-ceremonial centers, high-density and low-density urban environments, water management systems, and agricultural space has been incomplete and flawed.  One major reason for this is the thick forest that covers the structural remains.  With the development of lidar, the vegetation is, in effect, removed.  This article describes the use of lidar and ArcGIS processing in Cambodia at the site of the medieval Khmer Empire complex of Angkor.

In 2012, a block of territory covering the forested area within most of the Angkor World Heritage site was scanned to map variations in surface topography in both horizontal and vertical planes.  Locations were recorded using GPS.  Data points were processed using a method specifically developed for archaeological surveys in forest environments.  These were processed into DEMs, hillshade models, and local relief models using ArcGIS, and there were then analyzed and interpreted.   Archaeologists then went out into the field to verify the results using data loaded into portable GIS units. 

To illustrate a portion of the analytical part of this process, the article includes two visual examples.  In Fig. 2 two layers are presented, one a digital orthophoto mosaic showing elevation from the lidar digital surface model, and a layer showing the extruded lidar DTM with 2x vertical exaggeration.  Modern roads and canals are also shown.  In Fig. 3, a lidar DTM, a conventional satellite image showing limited features due to the vegetation, and a map of previously documented archaeological features shows the extent to which lidar has revealed new structures.

This use of GIS processing, with the precision of GPS location technology and the ability of lidar to strip away vegetation and reveal even slight variations in the ground surface, has transformed our knowledge of the extent and layout of the Angkorian complex.  First, it revealed that the urban center was at least 35 square km in area, rather than the 9 square km that was previously thought to be its extent.  It also revealed that the urban landscapes are not confined within the enclosed or walled city, but extend far beyond.  Much of the extended urban landscape features conform to what was known to be a predictably aligned formation in a grid pattern, but lidar revealed some new types of urban features which have no apparent agricultural, occupational, or hydrological function.

As a result of this study, crucial areas have now been mapped and analyzed, and our understanding of the layout and extent of the Khmer civilization at Angkor, and the factors associated in its decline, has greatly increased.

Friday, June 5, 2015

If, then, while, else

If I had all the time in the world, then I would be able to handle this assignment much better.
If I had been taught even a little bit of coding in my educational past, then I would not be so confused and inept.
While I am in school this summer I will try my hardest, even though that isn't cutting it at the moment.
Else I will fail, and that is not an option.
Print result.

 
This week we learned about conditional statements and loops, and then got to try them out.  First we imported the module random, then fixed some code that was already written so that it printed out the loop above concerning dice being thrown.  Then we created a loop to print a random list of 20 integers between 0 - 10, and then another conditional statement and loop to remove a certain number from the list. 
 
Never have I spent so much time trying and trying and trying, all for only partial success, and that only with some coaching by a very helpful instructor.  I'm sure that if I had more time, and could really practice each thing we learned this week in small pieces, several times each with variations, this would make more sense, and perhaps I would have been successful at the last piece of code.  However, I ran out of time.  Life intervened.  The lawn had to be mowed before it rained again, and my kids needed their mother back.  So it goes.  I'll keep trying, for what it's worth.