I am struggling to get the arcpy point class method
distanceTo to function with dynamically generated geometries with a Python addin.
I have used the default tool addin function and set self.shape (in
__init__) to shape. Selecting a polyline feature class in a drop down enables it.
class DrawLine(object): """Implementation for testaddin_addin.drawline (Tool)""" def __init__(self): self.enabled = False self.shape = "Line"
The user is able to draw a line, with a spatial reference automatically set to the data frame SR. I use the line to perform a SelectLayerByLocation query and extract the intersecting geometries to a feature layer (MakeFeatureLayer).
For the tool, the order of intersection is important, so I grab the starting point of the drawn line and create a new point geometry:
start = arcpy.PointGeometry(arcpy.Point(line_geometry.firstPoint.X, line_geometry.firstPoint.Y))
Finally I iterate over the intersecting features and attempt to call
while row: geom = row.getValue(shpfieldname) print type(start) print start.distanceTo(geom) row = rows.Next()
start is type
<class 'arcpy.arcobjects.geometries.PointGeometry'>, so I know that I am working with a point geometry.
I am returning:
File "c:\arcgis\desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 809, in distanceTo return convertArcObjectToPythonObject(self._arc_object.DistanceTo(*gp_fixargs((other,)))) ValueError: <geoprocessing describe geometry object object at 0x2868B4A0>
Has anyone gotten
distanceTo to work? How about with a dynamic geometry?
Note: The input shapefile is simple polylines, single part, composed of pairs of vertices, i.e. as simple as possible.