Thursday 13 July 2017

arcpy - Interpolating points along line in Python for ArcGIS Desktop?


I am building a Python geoprocessing script for ArcGIS 9.3. In the script, I have a simple LINE feature class with one row, one line.


How can I use a linear referencing system to interpolate a point along the path?


I can use a cursor to access the feature geometry, and get the vertex geometries. But I can't find anything that could help me interpolate points along it.



Note: this is ridiculously simple with Shapely:


import shapely.wkt
line = shapely.wkt.loads('LINESTRING (380 60, 360 130, 230 350, 140 410)')
line.interpolate(0.0).xy # (array('d', [380.0]), array('d', [60.0]))
line.interpolate(100.0).xy # (array('d', [346.16312174913622]), array('d', [153.41625550146173]))
# ... etc

line with point at 100 m


Is there any equivalent in ArcGIS?


I have all the common ArcGIS extensions to my disposal.



Or should I just bring the geometry over to Shapely to do the work?


The geometry processing needs to eventually go back to ArcGIS.



Answer



I've done this in ArcObjects with the ICurve interface (see QueryPoint method), but this old esri thread suggests ICurve isn't exposed through Python. If that's true just keep it in Shapely. ..besides, your Shapely solution seems more fun anyway. ::grin::


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...