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:
- Point toolbar to the elevation layer
- Click 'Interpolate Line' to draw the cross-section
- Click 'Profile Graph' to generate the profile
- 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.
Answer
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:
patch = r'F:\Joe_School\Thesis\data\grid_extract\mask400_1'
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.
No comments:
Post a Comment