Friday, May 30, 2014

GIS Programming Module 2 - Geoprocessing in ArcGIS

Polygon of suitable farmlands, created in ModelBuilder
In this assignment for GIS Programming, we created a model in ArcGIS ModelBuilder.  Data for soils, as well as the attributes for the small basin outside Hawley, MN, were the original output data.  A model was then created which can automate the employment of tools which will first select the soil parcels in the study area which are not prime farmland, then create a new layer from which those parcels have been excluded.  That layer is then clipped to the extent of the basin.  The result is the pink polygon in the map to the left.  This is the area of all lands in that small basin that are currently or potentially suitable for farming.

After the model was created in ModelBuilder, it was exported as a Python script and modified (by addition of full file paths to input data).  The resulting script can be run in PythonWin, outside the ArcGIS environment, create the output layers, and store them in the appropriate Results folder, to be added to an ArcMap .mxd file at any time.


The steps involved in creating the output dataset of suitable farmlands in the basin are listed below:

1. First, define the task to be performed:  Select the areas within the basin that have soils that area suitable         for farming.
2. Procedure: Select the polygons from the Soils shapefile that are classified as “not prime farmland” and           erase that selection from the Soils shapefile.  Then, clip the resulting layer to the extent of the basin.
3. Add the Basin and Soils layers from the Data folder to the blank .mxd.
4. After creating a toolbox in the Module 2 folder, Rt.Click > New > Model.
5. In the ModelBuilder window:  Model > Model Properties: Name and label the model, and provide a             description of what it does: SoilErase, Soil Erase, and that it will remove the polygons from the Soils             shapefile that are not prime farmland, and clip them to the basin layer extent.
6. Drag the Basin and Soils features from the Table of Contents into the Model Builder window
7. Open the Arc Toolbox window.   Navigate to the Select tool (Analysis > Extract) and drag it into the           modelbuilder window.  Then, double click on the Select box.
8. Fill in the parameters for the select tool:  Input: soils.  Output: will be called soils_Select.shp.
9. The SQL expression for the selection is “FARMLNDCL” = ‘not prime farmland’   Click Okay.
10. The output element will appear with the output file name.
11. Drag the Erase tool (Analysis > Overlay) into the ModelBuilder window and double-click it.
12. Input: soils.  Erase feature: soils_Select.shp.  Output feature: soils_Erase.shp.  Click Okay.
13. Drag the clip tool into the ModelBuilder window.  Double click it.
14. Input: soils_Erase.shp. Clip feature: basin.  Output: soils_Erase_Clip.shp.  This is the final output.  All             elements are now in color which means they are ready; none are white.  They contain the data and                 filepaths that they need.  Original input data is blue, output is green, and tools are yellow.
15. Rt.Click on each of the input and output elements, including the final output, and click Model Parameter         for each one.  There are five in all (does not include tools).
16. Save the model at the top menu of the ModelBuilder window.
17. To run the model, click on the small blue triangle arrow on the right end of the main menu bar of the               ModelBuilder window.  The tool and output elements will have a gray drop-shadow once they have run         successfully (the original input data elements will not).
18.  After creating the model and script, I discovered how to use the Dissolve tool to aggregate the polygons        within the Soils_Erase_Clip (Data Management Tools > Generalization > Dissolve).  This tool was not          included in the model or the script however.


Model to create a suitable soils layer, using ArcGIS ModelBuilder

Monday, May 26, 2014

Module 1 - Applications in GIS

In this week's Applications in GIS lab, we delineated streams and watersheds using a DEM, or digital elevation model.
This map shows the Hanamaulu Stream and its watershed in eastern Kauai, Hawaii.  The dark gray stream system and the red-bordered watershed area have been modeled from the Digital Elevation Model.  The blue stream system and light green polygon feature are drawn from analysis of aerial photos of the actual area.

 In this procedure, the theoretical flow of water is modeled on the raster of elevation data, and based on the D8 mode of analysis.  Water flows from each 30' x 30' plot on the ground, to the lowest of its eight neighboring cells. In this way, a model of flow patterns across a landscape is established.  From the flow direction raster, we then produce a flow accumulation raster, in which the water from all uphill cells progressively accumulates in the downhill cells.  The accumulation does not have real units; each cell's contribution to downhill cells is assigned a value of 1.  The cells along the top of drainage divides have an accumulation of zero.
If we set a minimum threshold of accumulation for cells, for example, 100, we can model a network of stream channels based on theoretical flow and accumulation of water as a factor of elevation.  It is then possible to define the theoretical watershed for all drainage above a particular outlet, or pour point.

It is interesting to compare the modeled stream system and watershed with the actual existing features in the same area, which were digitized from aerial photos.  We can see that the Hanamaulu watershed (with red outline), derived from the National Hydrologic Database and based on existing features, has a large area to the northeast that is not included in the light green modeled watershed.  A modeled stream system was created in this area (dark gray lines) from the analysis, but according to the existing stream data, there are very few stream channels (blue lines) in most of that area.  Because this area is very flat, based on the DEM, it is likely that runoff across that area disperses itself across many ephemeral channels which may not be visible in aerial imagery.




Friday, May 23, 2014

GIS Programming Module 1 - Introducing Python

In the first week of GIS Programming, we were introduced to Python by running a script which created a folder structure for our coursework.  We examined the script first, to get an idea of what it generally looks like. Other than practicing a couple of print commands in the Scripting Window, however,we are only running script at this point, not yet writing it.

On the left is an image of the folder structure that I created on my S:\ drive by running the Python script provided by our professor.  The parent folder is called GISProgramming, and contains 12 subfolders, for modules 1-12 of this course.  In turn, each of those folders contains three folders for Data, Scripts, and Results.  Rather than take a long time creating these 36 subfolders by hand, we were able to run the Python script and have them all appear in less than a second.  Once we can write script of our own, we'll be able to automate any number of tedious and time-consuming chores which might be much worse than this small task!

Here is my process summary of how I ran the script to create my folder structure:
 Running the script in PythonWin
1.       This script, CreateModuleFolders.py, will create a folder called GISProgramming, with subfolders, within the main S:\ drive.  There is no need to create any other folder before running the script.
2.       First, copy the script CreateModuleFolders.py from the R:\ repository drive into the student S:\ drive.  (I have a subfolder gds but I put the script at that same level,in the main S:\ drive.) 
3.       Go to the S:\ drive and Rt.Click the CreateModuleFolders.py file.
4.       Select Edit with PythonWin.
5.       A window for PythonWin will come up, with the script window open within it.
6.       Two ways to run the script: 1) Ctrl-R;  2) click on the runner icon at the top of the PythonWin window.  The script can be double-clicked from where it’s stored, as well.
7.       A little confirmation dialog box comes up.  Click on the Run button without changing anything. 

8.       The folder structure of S:\GISProgramming is created, with its 12 Module subfolders.  Each subfolder in turn has 3 empty folders in which to store Data, Results and Scripts from the 12 modules of this class.

Thursday, May 15, 2014

Introduction: Applications in GIS

Hi, this is Gail Sease.  This is the first post for the Applications in GIS, Summer Session in GIS, 2014.

Introduction: GIS Programming

Hi, I am Gail Sease.  This is the first post for the GIS Programming course, Summer Session in GIS, 2014.