1

I can create a centroid latitude field in ArcMap10.1 using "Calculate Geometry..." in the attribute table, but when I try the same thing using: arcpy.CalculateField_management(bins_WGS84, "cent_lat", "!SHAPE.CENTROID.Y!", "PYTHON_9.3"),

I get the following error: arcgisscripting.ExecuteError: ERROR 000539: Error running expression: GPVARIANTOBJECT0.CENTROID.Y. It only happens occasionally, but kills my script and costs me lots of time/data. On the particular dataset I'm testing, it happens about 10 rows in, although the geometry looks fine and Arcmap doesn't complain when finding the centroid.

I know it is possible, because it's working for the same dataset in ArcMap, however, this action does not show up in the Results window.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 19, 2014 at 21:25

1 Answer 1

2

I would guess there's something wrong with your geometry.

Try using RepairGeometry_management prior to your field calculation.

If this doesn't do the trick, a workaround is probably needed.

I would use FeatureToPoint_management, followed by AddXY_management, followed by SpatialJoin_analysis.

Edit: The best method might be via an UpdateCursor. Then you can use a try/except to find out just which features are causing the issue, and investigate further.

cursor = arcpy.da.UpdateCursor (bins_WGS84, ["cent_lat", "OID@", "SHAPE@TRUECENTROID"])
for row in cursor:
 try:
 row[0] = row[2][1]
 cursor.updateRow(row)
 except:
 print "Could not add Y value to", row[1]
del row
del cursor
answered Dec 19, 2014 at 23:07
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.