Sunday, July 26, 2015

Module 10: Custom tools

 
The ability to turn a script into a custom tool was this week's topic.  To do that, the following basic steps were followed:

1.      Create and save a .py script
2.      Create a custom toolbox for storing it
3.      Add a script tool to the custom toolbox with the AddScript wizard, selecting the saved .py script
4.      Modify the code in the script so it can receive the parameters set by the tool dialog box
5.      Set up the parameters in the tool’s properties
6.      Edit script using GetParameterAsText and GetParameter functions to set up parameter Dialog box for script tool

 
Here is a screenshot of the parameter Dialog box that allows input to the script tool.  Here there are 4 parameters, two of them already showing default locations for input and output files.  These are examples of workspace type parameters.  Two feature class parameter types are also listed: clip boundary feature and input features.  The latter was set to have a MultiValue property, since more than one .shp was used in this situation. 
 
 
 
Before the script tool ran, we edited it once more, adding AddMessages statements so that they would print in the results window, as shown below.

 
This lab was especially useful in showing how all the work of creating scripts can be used in a more simple, direct, and integrated way in ArcMap.

Wednesday, July 22, 2015

Module 9: Rasters

Last week we worked with Vectors, this week we learned how to write scripts for Raster data.  The functions and classes found in the arcpy.sa module are used to list, describe, create, and modify rasters.

ListRaster is used to find out what rasters exist in a workspace - Esri GRID and geodatabase rasters do not have file extensions; .img, .tif, and .jpg are returned for other image formats.

Describe returns general and specific properties of raster datasets.  The elements that can be described are datasets, bands, and catalogs.  Different properties are available depending on which element is being described.

Once a raster object is created, it can be used in other Python statements and map algebra statements.  Properties include band count, cell height and width, spatial reference, pixel type, and more.  The raster object has only one method possible - save.  This is used to make a temporary raster object permanent after ArcMap has closed.

In order to be able to use the tools in the arcpy.sa module directly, all the functions can be imported.  This can be helpful especially when using map algebra operators.

Several classes in the arcpy.sa module were introduced, including Remap and Neighborhood.  There are 8 others.

This week's lab asked us to create a raster from 2 existing rasters: elevation and landcover.  To start, we wrote code to see if the spatial analyst extension was available, then checked out the spatial analyst extension.  Next we reclassified the landcover raster so that 3 forest landcover classifications were changed to 1.  Then we created temporary rasters for elevation that had slope between 5-20 degrees, and aspect between 150-270 degrees.  The combined temporary rasters were saved to a final raster in a newly created geodatabase, and the spatial analyst extension was checked back in.  Below is the result, seen in ArcMap.

Monday, July 20, 2015

Using GIS for landscape archaeology


Sam Turner, Jim Crow, “Unlocking Historic Landscapes: Two Pilot Studies Using Historic Landscape Characterisation” in Antiquity 84(2010): 216 – 229


This article explains how GIS is being used to recreate historic landscapes and to analyze and interpret their development.  Historic Landscape Characterisation (HLC) is the term for “mapping landscape with particular reference to its historic character and development”.  The archaeologists in this example are using GIS to explore two locations in the Aegean, focusing on field systems and how they evolved over time.

Recently there has been a shift to focus less on either of the two prevailing approaches to the study of past, present and future landscapes - economic/functional or social/symbolic, and instead to look at “multifunctionality”.  HLC uses satellite images, aerial photography, and historic maps to “map, analyze, compare and contrast the perceptions of a wide range of people working within the landscape” using GIS.

HLC is not new, but in the past data storage had been an issue when working with such large projects.  GIS provides a solution, allowing a range of map sources, the ability to adjust scale, and the analysis tools which enhance interpretation.   With GIS, features of the historical landscape at a particular period are bundled together, creating visible groupings and patterns that characterize that period.  It is possible to do retrogressive analysis, and to add explanatory text connected to a database.  Also, GIS is flexible and adaptable to projects and research questions of any size or topic.

The two examples of the use of GIS in HLC in this article are from Greece and Turkey.  In Greece, the fields are terraced, and modeling can expose patterns of land use over time.  In Turkey, coaxial fields were used, and again, maps show a chronological progression of land development.

I chose this article for this assignment because it is along the lines of a project I’d like to put together once I’ve learned enough to do it. 

 

 

 

Thursday, July 16, 2015

Working with Geometries

 
In Module 8, we explored how to work with geometries - points, lines and polygons.  The use of geometry tokens to simplify some operations was one topic; SHAPE@LENGTH and SHAPE@XY were two of the tokens we worked with. We also learned how to parse points and polylines in order to get at the values within the geometry. The last part of the lesson focused on reading and writing geometries.
 
Below are the results of a script we worked on this week.  Each line contains data about a point or vertex in a feature.  The shapefile that provided the data was of rivers in Hawaii.  The script retrieved information including the object ID, x and y coordinates, and name of the river for each point, then created a new text file and wrote the information to that text file.
 
 
 
 
I had some trouble with the last part of the lab, writing to the text file.  My two issues were that I didn't put the writing part of the script inside the most nested loop - I had it all the way out, not indented.  Also I was using double quotes around by variables, so I kept getting the name to print and not the values of the variables.

Wednesday, July 8, 2015

Cursors and Dictionaries


This week we investigated ways to explore and manipulate spatial data.  The Describe function allows the user to discover what data exists as well as to examine the properties of that data.  Tuples and dictionaries were introduced.  We then went on to learn how to manipulate data by using cursors to access and iterate over rows in a table, or to insert or delete records.  One use of the SearchCursor function we practiced in the lab was in creating a SQL statement, which in our case gave us the name and population of all county seats in New Mexico.  We used this table to create a dictionary of keys (cities that were county seats) and values (their population).  One other topic this week was working with text, which was not part of the lab.

This screenshot shows the results of a script which created a geodatabase, copied data (shapefiles) into that geodatabase, selected the name, feature and population fields of the cities feature class, then narrowed that down to just those cities which were county seats.  The last part of the script created a dictionary and populated it with this information and printed it.

It took a while to get the correct syntax for the SQL statement, since the correct type and number of brackets and quotation marks is critical.  However, I got stuck on the part of the code where the dictionary was to print the name and population.  Finally, with some excellent tips and guidance, I was able to make it work.