Monday 18 April 2016

geometry - Get shortest distance between two geometries in ArcPy


I'm using ArcPy and using a cursor to step through one polygon feature class. For each of these 'source' polygons, I am creating a SearchCursor to find all polygons in a second feature class that share a common attribute. For each of these matching polygons, I want to measure the distance between it and the search polygon. I also plan on measuring other geometry differences (to determine if it has just been shifted, rotated, scaled, etc).


The purpose of this work is to build up a change history between polygon datasets representing features at different times.


I've seen the ReturnDistance method mentioned in ArcObjects, but can't figure out how to run this using ArcPy. Is it possible, and if so, can anyone help with some rough sample code? If not, I'll probably resort to measuring the change in centroid position between the polygons.



Thanks, Steve



Answer



This answer may not be considered as correct as it exclude use of ArcPy. I am not sure, if you can access ReturnDistance in ArcPy. However, you can access ArcObjects from Python directly. This guide by Mark Cederholm will help you start http://www.pierssen.com/arcgis/upload/misc/python_arcobjects.pdf. It will require from you some object orientated programming skills, if you do know basics, should be enough. Otherwise read the guide. In references you'll find some links to code snippets, if you are patient enough you'll figure it out.


Here you'll have some different approaches to ArcObjects in Python: Accessing ArcObjects from Python?


And here is an example of ArcObjects in Python (my struggle with this problem): Arcobjects in Python: assign interface to objects with feature (shape) geometry


It took me roughly 3 days to write my own program and I did not have any clue about object orientated programming, good luck.


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