Calling ArcGIS from Python

1. Introduction to Calling ArcGIS Functions

If we are going to have scripts of any level of complexity we are going to have to get out of the Python Window within ArcGIS and into a more complete development environment. The following script will create an "aspect" raster from an existing raster (GRID). The aspect tool replaces each pixel of a DEM with a value indicating the direction that pixel is facing. We're showing aspect because it is one of the simplest processes. You can use the same example code if you download a DEM from the "Data" web page at left or use the HSU data hub. To have this run somewhat fast, you'll want to use a relatively small DEM.

Here are some sample DEMs to try with the code below:

import arcpy

# Check out the ArcGIS Spatial Analyst extension license

# This allows us to run the script repeatedly without deleting the intermdiate files

# Path to the data (you can also set a workspace instead), change this to point to your data
# run the aspect tool"Temp.img") # save to an IMAGINE (img) file"Aspect.img") # Print out something so we know we've finished print("Done")

Notice in the script above that we call the Aspect tool by using This is because the Aspect tool is inside the Spatial Analyist toolbox.

Now be a good time to try additional functions to make sure you're comfortable with them. Try creating a slope raster and even a hillshade. Then you'll be able to write complete script for processing a single rasters.

© Copyright 2018 HSU - All rights reserved.