Wednesday 31 May 2017

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.



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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...