Thursday, November 12, 2009

Generating Elevation Profile (Part 1)

Elevation Profiles are a nice was to see the topography over a given line. This can be used for planning things like roads, easiest routes of travel, etc...

In Part 1, I will discuss how to develop a Geoprocessing Script to publish to ArcGIS Server to get the elevation profile data. I will be using spatial analyst to extract and transform the data. Next I will take the values and write them to a csv, which will be returned to a user.

Let's get started:

1). Create a new model. Make sure spatial analyst is enabled.

2). Add Extract by Mask and Raster to Point tools from ArcToolbox

3). Create a feature set object and provide a polyline shapefile as the schema reference. Make the schema of the data as follows: OBJECTID, SHAPE, ELEVATION

Now that you have that, you model should look like this:

Now you need to create the script that will return a csv table to the user from your ArcGIS Server Service.

4). Create a new python file and call it

5). Add the following Code:
# Import system modules
import arcgisscripting, os, sys

# Create the Geoprocessor object
gp = arcgisscripting.create()
gp.overwriteoutput = 1

InputPtFC = sys.argv[1]
pnt = gp.CreateObject("Point")
rows = gp.SearchCursor(InputPtFC)
filename = gp.scratchworkspace + os.sep + r"test.csv"

myfile = open(filename, 'w')
myfile.write("X,Y,ELEVATION" + "\n")
row =
while row:
feat = row.shape
pnt = feat.GetPart()
myfile.write(str(pnt.x) + "," + str(pnt.y) + "," + str(row.getvalue("GRID_CODE")) + "\n")
row =
gp.Addmessage(filename + " Completed")
gp.setparameterastext(1, filename)

6). Save your file, open catalog -> add this script to your toolbox -> Input Parameters - Feature Class and Output Parameter - Table

7). Add the newly create script to your orginal model

8). Save the model

9). Publish to ArcGIS Server

The resulting model should look like this: