# Replicate elevation profile extraction (3D Analyst toolbar) in ArcPy

How can I replicate in ArcPy the 3D Analyst Toolbar operations which extract an elevation profile from a transect line drawn atop an elevation layer? This will be incorporated into an automated workflow that will loop ~500K times. Hence, streamlining is critical.

Here's the procedure using the toolbar:

1. Point toolbar to the elevation layer
2. Click 'Interpolate Line' to draw the cross-section
3. Click 'Profile Graph' to generate the profile
4. Right-click graph, 'Export', 'Data'

(Inputs: elevation layer, transect. Outputs: graph, XY table.)

Rather than manually drawing a transect, as in the toolbar functions, I need the ability to specify the transect start & end by entering coordinates. Similar to the tool, I want the output to be XY pairs (ideally a numpy array), with x=0 being the transect origin, X-values being distance from origin, and Y-values being elevation.

• Take a look at the stack profile tool as a starting point. This sample here shows the tool being used with input line. You could hack it to accept xy and make a line yourself using arcpy geometry. arcgis.com/home/item.html?id=9eb7c69d9d124a488a76e2cf5fe401e9 Feb 17, 2016 at 2:58
• @KHimba: I just wanted to circle back and thank you for putting me on the right track. I've been able to use StackProfile exactly as I'd hoped. Sep 8, 2016 at 7:36
• Can you post your answer so we can see what you did? Sep 9, 2016 at 17:56
• @Matthew: See updated answer. Sep 12, 2016 at 21:59

Following up, the extremely straightforward solution (offered up by KHimba) is a built-in function that I was unfamiliar with, called StackProfile in the 3D Toolbox. Here's a condensed version of how I implemented it into my script:

out_prof = r'F:\Joe_School\Thesis\scripts\Jerry\scratch.gdb\testprof'

import arcpy, os
from arcpy import env
import arcpy.ddd as DDD

#env.overwriteOutput = True
env.outputCoordinateSystem = arcpy.Describe(patch).spatialReference
env.workspace = os.path.dirname(out_prof)

#Extract profile, save graph & table
arcpy.CheckOutExtension('3D')
tablename = 'prof_tablex'
graphname = 'prof_graphx'
prof = DDD.StackProfile(out_prof, patch, tablename, graphname)
DM.SaveGraph(graphname, graphname + '.bmp')
arcpy.CheckInExtension('3D')

In my full script, I was able to feed it a custom-built transect, and output the XY data into a numpy array, as originally intended.