0

I have vector data not in geographical coordinate system (i.e. not in WGS 1984).

How to calculate object's centroids using arcpy without reprojecting the data itself?

I have tried to do this but it doesn't work (centroids are in meters):

arcpy.CalculateField_management(feature, fieldName, "!SHAPE.CENTROID.X!","PYTHON_9.3")
arcpy.CalculateField_management(feature, fieldName, "!SHAPE.CENTROID.Y!","PYTHON_9.3")
arcpy.CalculateField_management(feature, fieldName, "!SHAPE.CENTROID@DECIMALDEGREES!.split()[0]", "PYTHON") 
arcpy.CalculateField_management(feature, fieldName, "!SHAPE.CENTROID@DECIMALDEGREES!.split()[1]", "PYTHON") 
asked Feb 14, 2017 at 12:04
2
  • Why ask and then answer your own question 1 min later Commented Feb 14, 2017 at 12:27
  • 1
    I just wasted a lot of time to find the answer (about 2 hours). This can save a lot of time to the other people. Besides 3 years ago i resolve this problem and forgot how i did that. Commented Feb 14, 2017 at 13:06

1 Answer 1

2

Use arcpy.CalculateField_managementwith following expressions:

For x coordinates:

expression = 'arcpy.PointGeometry(!Shape!.centroid,!Shape!.spatialReference).projectAs(arcpy.SpatialReference(4326)).centroid.X'
arcpy.CalculateField_management(feature, fieldName, expression,"PYTHON_9.3")

For y coordinates:

expression = 'arcpy.PointGeometry(!Shape!.centroid,!Shape!.spatialReference).projectAs(arcpy.SpatialReference(4326)).centroid.Y'
arcpy.CalculateField_management(feature, fieldName, expression, "PYTHON_9.3")
answered Feb 14, 2017 at 12:04
1

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.