Wednesday, July 20, 2016

Geog 491: Exercise 4- Working with Fields and Selections

Goal and Background

To use python to add a field, calculate a field and apply and SQL statement.  The objectives for this exercise are stated below,

  • Set up the script and import the modules.
  • Set up smart variables.
  • Add a field and calculate a field.
  • Select features based on an SQL statement.
  • Add a field and calculate for selected features.
Methods

The comments in green were added along the way in order to keep the script in order.  Add and field and calculate field were used along with an SQL statement in order to produce results to be used in a future exercise.  From these fields, a select tool was used and in the end compactness was calculated.  Below is the script written for this exercise.  Exercise 3 data was used.

Results


#-------------------------------------------------------------------
# Name:        Exercise 4
# Purpose:     Find ideal locations for a ski resort by calculating #              compactness
#
# Author:      Laura Hartley, hartlelj
#
# Date:        7/18/2016
#-------------------------------------------------------------------

#Ensure the program is working
print "script initialized"

#import system modules
import arcpy
from arcpy import env
import os
import time
import datetime

#Allow the script to overwrite existing files
arcpy.env.overwriteOutput = True

#Create variables
print "Creating Variables"
,datetime.datetime.now().strftime("%H:%M:%S")
#input variables
ex3geodatabasePath = "C:\Users\lhartley13\Documents\ArcGIS\EX3\EX3.gdb"

#This filename will be used for the subsequent 'dissolve output' fc name
intersectName = "IntersectedFcs"
dissolveOutput = os.path.join(ex3geodatabasePath,intersectName)+"_Dissolved"

#output variables
selectName = "DissolveFC_Selected"
finalSelect = os.path.join(ex3geodatabasePath,selectName)

print "Adding a field to the dissolve fcs" ,datetime.datetime.now().strftime("%H,%M,%S")
#Add field
arcpy.AddField_management(dissolveOutput, "Area_km2", "FLOAT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

print "Calculating the area in km2" ,datetime.datetime.now().strftime ("%H:%M:%S")
#Calculate field
arcpy.CalculateField_management(dissolveOutput, "Area_km2",  
"[Shape_Area] / 1000000", "VB", "")

print "Selecting only polygons with areas greater than 2km" ,datetime.datetime.now().strftime ("%H:%M:%S")
#Select (4)
arcpy.Select_analysis(dissolveOutput, finalSelect, "Area_km2 >2")

print "Adding a field for calculating compactness" ,datetime.datetime.now().strftime("%H:%M:%S")
#Add field (2)
arcpy.AddField_management(finalSelect,"Compactness_Float", "FLOAT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

print "Calculating compactness" ,datetime.datetime.now().strftime("%H:%M:%S")
#Calculate field (2)
arcpy.CalculateField_management(finalSelect, "Compactness_Float"
"[Shape_Area] / ([Shape_Length] )", "VB", "")

print "Calculations complete" ,datetime.datetime.now().strftime("%H:%M:%S")

Geog 491: Exercise 3- Introduction to Geoprocessing with Python

Goal and Background

The main goal of this exercise is to export a geoprocessing model as a script and add multiple smart variables and modify the exported script.  The objectives needed to follow in order to complete this exercise were:

  • Export a geoprocessing model as a python script.
  • Importing modules and setting up a script.
  • Creating smart variables.
  • Setting up a geoprocessing workflow.

Methods

The exercise 1 data was used in this exercise in order to further manipulate the data.  Green comments in the script below were used to describe what was happeneing in the process below it.  Print statements along with time stamps were used to keep track of when the tools began running along with getting more familiar with print and time statements.  Below is the script used in exercise 3 in order to produce the above stated objectives.

Results

#-------------------------------------------------------------------
# Name:        Exercise 3
# Purpose:     To export a geoprocessing model as a script, add     #              several smart
#              variables and modify the exported script.  Finding   #              ideal areas for
#              ski resorts
#
# Author:      Laura Hartley, hartlelj
#
# Date:        7/15/2016
#-------------------------------------------------------------------
#ensure the program is working
print "script initialized"

#import arcpy and set up the environments
import arcpy
from arcpy import env
import os
import time
import datetime

#overwrite allows us to overwrite files and save over them
arcpy.env.overwriteOutput = True

#create variables
print "Creating Variables"
,datetime.datetime.now().strftime("%H:%M:%S")

#input geodatabse
ex1geodatabasePath = "C:\Users\lhartley13\Documents\ArcGIS\EX1\Ex1.gdb"

#input names
nfsLand = "NFS_Land"
snowDepth = "SnowDepth_in"
temp = "Temperature_F"
studyArea = "StudyArea"
airports = "Airports"

#linking geodatabse with name
nfsInput = os.path.join(ex1geodatabasePath,nfsLand)
snowDepthInput = os.path.join(ex1geodatabasePath,snowDepth)
tempInput = os.path.join(ex1geodatabasePath,temp)
studyAreaInput = os.path.join(ex1geodatabasePath,studyArea)
airportsInput = "C:\Users\lhartley13\Documents\ArcGIS\EX1\Ex1.gdb\Airports_project"

#output Variables
ex3geodatabasePath = "C:\Users\lhartley13\Documents\ArcGIS\EX3\EX3.gdb"

#clip the layers
nfsLandClip = os.path.join(ex3geodatabasePath,nfsLand) + "_Clip"
snowDepthClip = os.path.join(ex3geodatabasePath,snowDepth) + "_Clip"
tempClip = os.path.join(ex3geodatabasePath,temp) + "_Clip"
airportsClip = os.path.join(ex3geodatabasePath,airports) + "_Clip"

#select the layers
snowDepthSelected = os.path.join(ex3geodatabasePath,snowDepth) + "_Selected"
tempSelected = os.path.join(ex3geodatabasePath,temp) + "_Selected"
airportsSelected = os.path.join(ex3geodatabasePath,airports) + "_Selected"

#buffer output
airportsBuffered = os.path.join(ex3geodatabasePath,airports) + "_Buffer"

#intersect output
intersectName = "IntersectedFcs"
intersectOutput = os.path.join(ex3geodatabasePath,intersectName)

#dissolve output
dissolveOutput = os.path.join(ex3geodatabasePath,intersectName) + "_Dissolved"

#final select
finalSelect = os.path.join(ex3geodatabasePath,intersectName)+ "_MoreThan2km2"

#Begin processing
print "Starting to process" ,datetime.datetime.now().strftime("%H:%M:%S")

print "Clipping fcs to within the study area" ,datetime.datetime.now().strftime("%H:%M:%S")
#clip all of the feature classes to the study area
#clip snow depth
arcpy.Clip_analysis(snowDepthInput, studyAreaInput,
snowDepthClip, "")

#clip temperature
arcpy.Clip_analysis(tempInput, studyAreaInput, tempClip, "")

#clip nfs land
arcpy.Clip_analysis(nfsInput, studyAreaInput, nfsLandClip, "")

#clip airports
arcpy.Clip_analysis(airportsInput, studyAreaInput, airportsClip, "")

#select meaningful values froom the clipped classes
print "Selecting meaningful values from the clipped classes",datetime.datetime.now().strftime("%H:%M:%S")
arcpy.Select_analysis(snowDepthClip,snowDepthSelected, "gridcode >= 250")

#process: select(2)
arcpy.Select_analysis(tempClip, tempSelected, "gridcode<32")

#process: select(3)
arcpy.Select_analysis(airportsClip, airportsSelected, "OwnerType = 'Pu' AND hasTower = 'Y'")

print "Buffering selected airports" ,datetime.datetime.now().strftime("%H:%M:%S")
#process: buffer
arcpy.Buffer_analysis(airportsSelected, airportsBuffered, "40 Miles", "FULL", "ROUND", "ALL", "", "PLANAR")

print "Intersecting the fcs" ,datetime.datetime.now().strftime("%H:%M:%S")
#process: intersect (2)
arcpy.Intersect_analysis([snowDepthSelected, tempSelected, nfsLandClip, airportsBuffered], intersectOutput, "ALL", "", "INPUT")

print "Dissolving the intersected fcs" ,datetime.datetime.now().strftime("%H:%M:%S")
#process dissolve (2)
arcpy.Dissolve_management(intersectOutput, dissolveOutput, "", "", "SINGLE_PART", "DISSOLVE_LINES")


print "Calculations complete",datetime.datetime.now().strftime("%H:%M:%S")

Tuesday, July 12, 2016

Geog 491: Exercise 2- Advanced Model Builder

Goal and Background

The purpose of this lab was to gain experience with more advanced model builder processes. Specifically inline variable substitution and model iterator.

Methods

A model iterator was used in order to perform a certain calculation on Slope, Aspect, and DEM rasters.  This was also used with inline variable substitution to firstly create a buffer.  Then zonal statistics were calculated for all three rasters.  After these processes, the selection tool was used to extract the four different run types: beginner, intermediate, advanced, and expert.  Figure 1 shows the model building process used to create the map shown in Figure 2.
Figure 1: Model used in exercise 2.

Figure 2: Map of the ski runs.
Results

These results shown in Figure 2 may be off by a bit.  Throughout the process, many troubles were run in to.  In the end the map looks correct, but it ultimately could be wrong.

Geog 491: Exercise 1- Review Geoprocessing and Basic Model Builder


Goal and Background

This exercise was used as a refresher for model builder skills and reviewing standard geoprocessing workflows.  The objectives within this exercise consisted of finding suitable areas in the Rocky Mountains for a new ski resort.  The area must follow certain criteria,
  • Snowfall greater than 240 inches.
  • Mean winter temperature below 32 degrees Fahrenheit.
  • 40 miles from a public airport with a tower.
  • Within National Forest Land.
Methods

Below in Figure 1 shows the model builder process of the methods.  First the layers NSF (National Forest Land) land, snow depths polygons, and temperature had to be clipped to the study area.  The Airports feature class also had to be projected into the same coordinate system as the other layers. 

Once this was successfully done, the select tool was used in order to start forming areas based on the above criteria.  Snowfall greater than 240 inches, and mean winter temperature below 32 degree Fahrenheit were selected.  Another selection that needed to be done was to find airports that were public and had a tower.  Once these were selected, a buffer of 40 miles was created around them.

Next, overlay analysis was used in order to find the areas that met the above criteria.  After those processes were finished a new field was added to the new layers data table.  One of the new fields calculated area for kilometers squared and then found any area greater than 2 km^2.  Another field was added in order to calculate the compactness of the resulting polygon. 

Once all of these tools were added to the model it was run successfully and all added to the map.  Figure 1 displays the model used to create the map in Figure 2 of the areas suitable for a new ski resort in the Rocky Mountains.

Figure 1: Exercise 1 model.


Figure 2: Suitable ski areas map.

Monday, May 16, 2016

GIS II: Lab 8- Raster Modeling

Goal and Background

The purpose of this lab was to learn various raster geoprocessing tools in order to build models for sand mining sustainability and sand mining impacts of environmental and culturals risks.  The modeling took place in Trempealeau County, Wisconsin.  The main outcomes of this project include:

  • Building a sand mine suitability model
  • Build a sand mining risk model
  • Overlay the results of the two models to find the best locations for sand mining with minimal environmental and community impact.
Methods

Suitability for mining
1. Generate a spatial data layer to meet geologic criteria 
2. Generate a spatial data layer to meet land use land cover criteria 
3. Generate a spatial data layer to meet distance to railroads criteria 
4. Generate a spatial data layer to meet the slope criteria 
5. Generate a spatial data layer to meet the water-table depth criteria 
6. Combine the five criteria into a suitability index model 
7. Exclude the non-suitable land cover types 

The first part of the lab had us create a mine suitability model based on watershed, land cover, distance to railroad, geology, and slope of Trempeaulau county.  Below in Figure 1 is my model I created in order to produce the results in Figure 2.  Each of these required me to reclass and project the rasters.  This was a difficult process, but ultimately helped me better understand model builder and these tools I used many times throughout the lab.

Figure 1: Model used to create Mine suitability model.
Figure 2: Mine Suitability model.
I also created a table  below in Figure 3 of the layers I mapped in order to give a better understanding of the map.

Figure 3: Suitability layer descriptions.


Risk for mining

8. Generate a spatial data layer to measure impact to streams
9. Generate a spatial data layer to measure impact to prime farmland
10. Generate a spatial data layer to measure impact to residential or populated areas
11. Generate a spatial data layer to measure impact to schools
12. Generate a spatial data layer to measure impact on one variable of your choice
13. Combine the factors into a risk model
14. Examine the results in proximity to prime recreational areas

The second part of this lab required us to create a suiltability risk model for these potential new mines.  I once again created the individual layers using model builder.  The risk factors that were mapped were farmland, residential areas, school areas, wildlife areas, and streams.  I ran into less problems in this section but that doesn't mean I didn't have any.  Below in Figure 4 is my model that created my mine impact model in Figure 5.

Figure 4: Model to create mine impact model.
Figure 5: Mine Impact model.
I created another table in Figure 6 in order to give a better understanding of how I mapped these layers.

Figure 6: Mine risk layer descriptions.
Results and Discussion

The optimal locations for these potential mines have to take a lot into consideration.  There are environmental and health risks that many don't realize.  I think it would be interesting to see what the true suitability model looks like of this area or a different area.

Saturday, April 23, 2016

GIS II: Lab 7- Network Analysis

Goal and Background

The main purpose of this lab was to introduce the concept of network analysis.  A network is a system of interconnected elements which are used for modeling transportation, rivers, utilities, etc.  In section 1 of this lab we created a python script that would find active mines within Wisconsin that didn't have a rail loading station on-site and were at least 1.5 kilometers away from a rail line.  In section 2, we used the mines that fit this criteria and used network analysis to route the sand from the mines to the rail terminal.  The results from this were then calculated to see the impact that sand transportation has on roads.  All of the results are hypothetical, but can give a good estimation of the costs.

Methods

For the second section of this lab we needed to find the quickest route from the sand mines to a rail terminal.  Once we practiced with network analysis a bit, we realized it was quite easy to use.  In order to make the lab more challenging, we were instructed to create it all in model builder.  The first step was to create a Make Closest Facility Layer.  This is the type of network analysis model we want to use in order to find the closest rail terminal for each sand mine.  In order to do this we needed to add locations and make one layer the facilities and one layer incidents.  In this case, the facilities were the rail terminals and incidents were the mines.  In order to create the routes, the solve tool was used.  The model was run and added to the map in order to make sure everything ran properly.  Everything ran smoothly on the first try so it was time to move onto the next part of the model.  Next we needed to use a model only tool called Copy Features.  This is basically the same as exporting a selected feature in a mapping session.

Next we needed to project these new layers into a better coordinate system.  Before the were in a coordinate system that used decimal degrees.  We can't calculate miles from this so I projected all of the new layers into a better suited coordinate system for this project.  In the model below in Figure 1, it only shows that wi_counties layer projected, but I also projected the other layers.  I just chose to not include them in the model.  Next we needed to calculate the total road length for the routes by county.  This was done using the tabulate intersection tool.  Once that was calculated I added a field in order to convert the measurements for each county from feet to miles.  Next I created another field where I took the length in miles * 100 * 0.022.  The 100 represents the yearly truck trips from the mine to the rail terminal.  There are 50 yearly trips, but it had to be changed to 100 because the truck do round trips and not just one way.  The 0.022 represents the hypothetical costs per truck mile which is $0.22.  Once again, this model can be seen below in Figure 1.

Figure 1: The model used in order to calculate trucking impacts on roads.

Results and Discussion

After the model was created I put together a map which shows the final results.  This map is shown below in Figure 2.

Figure 2: Trucking routes between suitable mines and rail stations.

As shown above, not all of the routes are within the Wisconsin states lines, two of the routes let to Minnesota.  Many of the routes also went to the same railroad station.  In Figure 3 below, the length in feet and miles are calculated and it shows the final hypothetical trucking costs.  In Figure 4 below the table, I created a graph in order to show which counties are causing the most damage to roads through trucking sand to the rail terminals.


Figure 3: Trucking lengths and costs for each county with a mine.
Figure 4: Trucking costs per county.

As seen above, Chippewa, Barron, and Eau Claire have the highest trucking costs.  By looking at the map we can see that most of the mines and rail terminals are within or surrounds these counties.  The impact that these trucks have on the roads and environment are causing quite a bit of damage.  So we have to ask, is the damage worth it?

Conclusions

This was definitely one of the more difficult labs we've done.  I took a lot of thinking about what tools need to be used and how to use them.  Model builder made things more difficult, but I am glad I got the extra practise with it.  As for the results of this lab, I was interested to see how much these trucking costs would turn out to be.  It was no surprise that the costs were higher in more populated areas like Eau Claire.  I just wonder whether these companies that are involved with sand mining know the damage they're doing to roads and the environment?  I would like to know more about the sand mining industry after doing these labs.  It seems like a huge industry, but are they helping or hurting the environment around them?  It would be interesting to know.

Data Sources

Hart, Maria V., Teresa Adams, and Andrew Schwartz.  "Transportation Impacts of Frac Sand Mining in the MAFC Region: Chippewa County Case Study." University of Wisconsin- Madison, 2013. Web.

Wednesday, April 13, 2016

GIS II: Lab 7 Part 1- Python

Goal

The purpose for this python script is to prepare data for network analysis that will happen in part 2 of this lab.  The script was used to select mines with the following criteria:

1. The mine must be active
2. The mine must not have a rail loading station on-site
3. The mine must not be within 1.5 km of railroads.

The finished product will then be used in the next part of the lab in which we will calculate the impact of trucking sand from mines to rail terminal on local roads.  The script I created for this portion of the lab is pictured below in Figure 1.

Figure 1: Python script for Lab 7.