# 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

-

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: How do I access 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.

-
I suspected this might be what I needed to do. Thanks for all the links and the info about your experience with this. Will give it a go myself. – Steve Dec 14 '11 at 22:46

This answer is 3 years late so you've probably got a workaround by now. But for completeness, here's an arcpy method to measure the distance between 2 objects.

Geometry has a method `distanceTo` which:

Returns the minimum distance between two geometries. If the geometries intersect, the minimum distance is 0.

Both geometries must have the same projection.

-