Masthead

Assignment: Calling ArcGIS from Python

1. Processing Rasters

Create a Python script that will take a DEM and:

Below is some code to get you started. Notice that in one function call you'll specify an input and output file path while in another, ArcGIS returns a raster "object" which you then save to a file. You'll need to change the file paths and you'll have to determine the format and values for the "clipping bounds".

Note: Don't worry about the final raster calculation ending up with nothing in the raster. I am only concerned about you getting the code functional.

import arcpy # connect to ArcGIS

arcpy.CheckOutExtension("Spatial") # Make sure the spatial extension is checked out
arcpy.env.overwriteOutput=True # Allows us to run the script repeatedly without deleting the intermdiate files

# Create a DEM with sinks filled
FilledRaster=arcpy.sa.Fill(ProcessingFolder+"DemClip3.img")
FilledRaster.save(ProcessingFolder+"FilledRaster.img")

Warning, do not use a large raster for this or you will never finish the assignment. Use a tiny raster (<1 meg) to get started and then test the code with a medium sized raster (<100 meg).

2. Processing Vectors

Create a Python script that will take two shapefiles with polygons and:

3. Functions

Create a function to compute the rasters from the first section and another function to compute the vectors from the second section. Place the function in a module (separate file).

Turn-in:

  1. A finished Python script with documentation and exception handling
  2. A Python module with the two funtions

Note: Remember to place the overall script in a "try/except" block and fully document both files.

© Copyright 2018 HSU - All rights reserved.