Saturday, July 30, 2016

GIS5103 - Module 11 - Sharing Tools

In Module 11, our final module for GIS Programming, we were tasked with editing a provided toolbox, script tool, and script.  The purpose of the script tool was to create randomly placed points inside/along a boundary feature and then create a buffer feature around those points.  Parameters for the tool were read in the script using sys.argv[] .   This function is similar to the arcpy.GetParameter() and GetParameterAsText() functions but has a character limit.  The provided script had the input boundary file and output file paths hardcoded in the script.   We had to edit the script to accept a parameter using the sys.argv[] code.  After making the script modifications, the tool ran successfully.
Module 11 Random Buffer Tool Dialog Window
Next we had to edit the Item Description for the tool.  This enables the script author to provide an explanation and description of the tool, its purpose, limitations, and parameter explanations.   Providing this information to the end user makes the tool more user friendly.  Prior to sharing our tool we embedded the script.   This allows us to only have to share the toolbox file and eliminates the need to compress the toolbox file with the script file.  Once the script has been imported by the tool, it is also possible to password protect the tool.   Password protection prevents others from copying or editing your tool without your permission.  After running the tool again, I created the following map displaying the boundary feature (NuevoLeon.shp) and the two output features created by the tool (random points and buffer around random points).
Module 11 Random Buffer Tool Output Features with Boundary Feature

This module was valuable in showing the importance of using a standard format for file organization as well as the importance of relative paths.  Providing documentation to the script tool user is a vital part of the tool creation.

Difficult to believe this is our last module assignment.   I did not know what to expect about Python programming, but have enjoyed this class.   It had been over 20 years since I had taken a programming class and over a decade since I had edited or worked directly with code.   I enjoyed using Python.  Object oriented languages appeal to my way of learning.   As I continue my journey towards GIS certification, I can see how a solid knowledge of Python can enhance a GIS project.   Whether scripting is used to automate geoprocessing tasks or to generate tools to be shared by others, I realize what a powerful component Python is to GIS analysis.


Sunday, July 24, 2016

GIS5103 - Module 10 - Creating Custom Tools

In this module we were tasked to create a custom clipping tool.   Turning your Python script into a tool is an easy way to share the functionality of your script with others.  

The first step was to create a Python script.   We were provided a template script to modify.   Secondly, a new toolbox had to be created.  After adding a script tool to the toolbox we setup the tool properties.   The our modified Python script was the script file and four parameters were created; input file location, clip boundary feature, input features, and output file location.  Setting up the Data Type and Values was an important step.  Full filepaths are required but quotation marks are not needed.  

Module 10 MultiClip Tool dialog box

Once the tool properties were set, we needed to edit our Python script to allow for users to input the parameters.   Using the GetParameter() and GetParameterAsText() functions caused some difficulty for me.   I needed to understand if the object being returned was a string or not.  Our input features parameter was a multivalue, meaning more than one value or a list could be provided.  The Python script used a "for" loop to iterate over each input feature in the list.  We also had to replace the Python script's original "print" statements with the AddMessage function.   Using AddMessage statements enabled messages to appear in the tool progress dialog box and results window.

Module 10 MultiClip Tool Results
For each input feature the name of the feature is printed.  After the Clip Analysis is performed the name of the newly created clipped feature is printed.

I chose to check to see if the tool also worked with a different boundary feature.   I created a map displaying both the Durango clipped features and the NuevoLeon clipped features.

Module 10 Final Map -
mex_rivers, mex_roads, mex_rails, and mex_urban input features clipped to both the Durango and NuevoLeon features.
Finally, I created a flow chart of the script used in the tool.

Module 10 MultiClip Script Flowchart
For this assignment, I had to use ArcGIS help resources to better understand the functions in the script and their respective arguments.   Seeing code samples was helpful.   I also noticed there was a difference sometimes in documentation between pro.arcgis.com and desktop.arcgis.com  

This assignment really helped me see the usefulness of tools.   It makes it so easy to replicate a tool among multiple features and also different parameters.

Wednesday, July 20, 2016

GIS5103 - Module 9 - Working with Rasters

Last week we worked with Vector features and this week's focus was working with Rasters.

Our text discussed how to list rasters and describe properties of raster features.  We learned that the arcpy raster class enables us to create a raster object by referencing an existing raster on disk or using map algebra statements.   The raster object output is temporary.   If the user desires to save the an output raster they must use the .save() method to make the raster object permanent.   Using the Spatial Analyst module the user has access to geoprocessing tools and map algebra operators.  The four categories of map algebraic operators are: Arithmetic, Bitwise, Boolean, and Relational.

Working with feature classes (landcover and elevation) in a provided geodatabase we were tasked with creating a new raster that included only forested lands with slopes between 5-20 degrees and aspects of 150-270 degrees.   After importing necessary modules and setting the workspace environment and overwriteOutput option we had to create an "if" conditional statement to check for the spatial analyst license.  We then had to reclassify the "landcover" feature class to show only forested lands.   I had to take time to visually see and understand the remap and reclassify functions.   I displayed the landcover feature class in ArcMap and looked at its attribute table.  The reclassified landcover feature was a temporary raster that was assigned a name.   

Next, using the Slope and Aspect tools we created two more temporary rasters.  Using relational map algebra operators I created four statements to meet the required slope and aspect conditions.   

Finally, I used the boolean "and" operator to combine the reclassified landcover raster with the conditional slope and aspect rasters to create a new raster.  I chose to create a new geodatabase and save my new raster as a feature class of this geodatabase.

I actually found an error in my code writing this blog.   I realized I used the wrong relational operators for my aspect statements and had to rerun the script.   The most difficult part of this lab was taking time to really understand the classes/tools/functions and what output they created.   Being able to visually see the feature classes in ArcMap helped, but even that did not keep me from making my mistake.   Hopefully, in a real world scenario there would be more than one set of eyes on a project and I would be more familiar with the data being used.

Shown below is a screen shot of my final raster feature and the flowchart for the Python script.


Module 9 Flow Chart for Script

Sunday, July 10, 2016

GIS5103 - Peer Review Assignment #2

A programmable information system for management and analysis of aquatic species range data in California, Nicholas R. Santos, Jacob V.E. Katz, Peter B. Moyle, Joshua H Viers
I found this peer reviewed article via the UWF library resources.   I found it interesting and pertinent because my school district just passed a resolution of support for the establishment of a Choctawhatchee Bay Estuary Program.
The research described in the article is the creation of a GIS dependent database and software program whose outputs can be used to map or tabulate freshwater species information in California.  The U.S. Dept. of Agriculture Forest Service (FS) is California's largest land holder, accounting for approximately 20% of the state's land surface.  The FS is responsible for identifying and monitoring aquatic species.  Prior to the research discussed in this article the FS relied on maps created with early GIS technology that were created using expert knowledge rather than verifiable data.  The previous maps also could not be readily updated with new information.   
The decision support software system, called PISCES, "uses Python 2.6, ArcGIS and a MS Access geodatabase for data processing and storage."  This enabled their product to work on a standalone, portable computing device, made it easy to import new data and provide updated maps as available.   Additionally, new functions or configurations could be customized to accommodate future needs.  
The researchers methodology "is designed to aggregate and convert diverse spatial data for California native fish species" to U.S. Geological Survey subwatersheds as their areal units (http://water.usgs.gov/GIS/regions.html).  Their mapping code within PISCES was designed to be flexible, allowing for user created maps provided by specifying general parameters.  The species database was seeded with some empirical data, but very little exists, most was captured from expert knowledge based and was reviewed by species experts.
The PISCES software and subsequent output provided maps and information that was much more useful than the previous GIS maps, especially "at regional and watershed-level scales."  The new system also enabled FS management to be capable of providing revisions and regional analysis.   Multiple sources could now verify a species' presence.
One of the limitations of using the USGS Hydrologic Unit Code (HUC12) as the areal unit was that some species were limited to one lake or stream, making it difficult to convey that a species reach was found only in this limited range.
Researchers tried to control or understand the sources for errors with the most difficult being the expert judgement required for non-empirical data in their database.   A system such as that designed by the creators of PISCES is an excellent management tool to aid conservationists in capturing and reporting native species ranges and information.  Although this system was designed specifically to solve management issues in California's FS lands (range maps for 67 of California's 129 native fish species were produced), the basic framework could be adapted to meet the needs of other environmentalists and wildlife management officials.
More information about National Estuary Programs can be found at:

GIS5103 - Module 8 - Working with Geometries

Module 8 required us to edit an existing script template to understand how to work with geometry objects.   Our assignment taught us how to work with spatial data using a specified shapefile, rivers.shp.   We learned you can access the entire geometry object or use geometry tokens to as shortcut to access certain geometry properties.  Using search cursors and for loops you can iterate over rows and arrays to provide specific information about individual points/vertices.  Point feature classes have a single point object for each feature but polyline and polygon feature classes have an array of points/vertices for each feature. 

The assignment required us to create a search cursor to locate/call the OID/Feature # field, the SHAPE geometry object, and the NAME field.   We used the token SHAPE@ token to return the full geometry of our rivers shapefile features.  Next we used the "open" command to create a text file set in writing mode that could be written to.   Using nested for loops we first used the cursor to locate each feature and then in the next for loop used the "getPart()" method to call for five items for each vertices for each river feature.   The five items (OID#, VertexID, XCoord., YCoord, and River Name) were then written to the newly created text file on their own line.   Creating a vertexID variable to act as a counter enabled us to keep track of all the vertices in each river feature.   After successfully running the modified script, the completed text file contained 26 different features with a total of 247 vertices.

The most difficult part of this lab was wrapping my head around arrays and how search cursors can be used to call/locate fields and geometry objects in the arrays.    Having examples from the text and exercise help tremendously in ensuring the correct syntax is used to call the needed items.  

Below is the flowchart for the Module 8 script I modified.


Flowchart Module 8 Script


Here are the screenshots from opening the text file that contained the five items for all of the vertices for each feature in the rivers shapefile.




Module 8 Text File Screenshots