0

Tried reading through everything else related to the distanceTo tool on SE, but im still running in to trouble.

Basically, my input Feature Class is a collection of polygons with begin/end lat/long. There is one BEGIN_LAT,BEGIN_LON,END_LAT,END_LON for each record. These lat/long pairs do not relate to the actual shape of the polygon (they might, but most will be different). Trying to find the minimum distance value for each polygon to the beginning LAT/LON point and end LAT/LON point. Eventually I am going to use the distance to compute time values, but for now I would just like to see the value print out properly :)

Code block as follows:

cursor = arcpy.da.SearchCursor(inFC,
['SHAPE@',"BEGIN_LAT","BEGIN_LON","END_LAT","END_LON"])

for row in cursor:
    polygonshape = row[0]
    beginpoint = arcpy.Point(row[2],row[1])
    begingeometry = arcpy.PointGeometry(beginpoint)
    distance = polygonshape.distanceTo(begingeometry)
    print distance

I'm getting the generic error of:

ValueError: <geoprocessing describe geometry object object at 0x05F17D40>

I also print the type of polygonshape and begingeometry.... Polygon and Point respectively.

  • maybe try putting the polygonshape variable through a polygon geometry constructor – ziggy Mar 28 '17 at 18:36
  • what do you mean by this? It already is a polygon. – cjl5108 Mar 28 '17 at 18:49
  • try this: replace your SHAPE@ token with SHAPE@wkt – ziggy Mar 28 '17 at 18:51
  • then: polygonshape = arcpy.FromWKT(row[0]) – ziggy Mar 28 '17 at 18:52
  • Check if point inside environment extent and perhaps add spatial reference to point geometry – FelixIP Mar 28 '17 at 19:06
1

Ziggy's suggestion led me down the right path.

Changed to print out WKT, which allowed me to see that my polygon features were actually being stored as MultiPolygon. I assume this happened a little earlier in my code unknowingly, and was the cause of the error.

Below is code that is working properly. Note: All projections were set in WGS84

cursor = arcpy.da.UpdateCursor(inFC+"2",['SHAPE@wkt',"BEGIN_LAT","BEGIN_LON","END_LAT","END_LON","BeginDist","EndDist","TotalDist"])
for row in cursor:
    polygonshape = arcpy.FromWKT(row[0])
    beginpoint = arcpy.Point(row[2],row[1])
    endpoint = arcpy.Point(row[4],row[3])
    begingeometry = arcpy.PointGeometry(beginpoint)
    endgeometry = arcpy.PointGeometry(endpoint)
    begindistance = polygonshape.distanceTo(begingeometry)
    enddistance = polygonshape.distanceTo(endgeometry)
    totaldistance = begingeometry.distanceTo(endgeometry)
    row[5] = begindistance
    row[6] = enddistance
    row[7] = totaldistance
    cursor.updateRow(row)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.