2

I have polygon features and want to calculate coordinates of it's centroids in arcgis using python - all goes fine, but it gives me coordinates in meters and not in degrees as i want.

Here is the code:

arcpy.CalculateField_management(folder+"\\"+f+"_fakela_shp.shp", "X", "!SHAPE.CENTROID@DECIMALDEGREES!.split()[0]", "PYTHON") 
arcpy.CalculateField_management(folder+"\\"+f+"_fakela_shp.shp", "Y", "!SHAPE.CENTROID@DECIMALDEGREES!.split()[1]", "PYTHON") 

@DECIMALDEGREES should done the job, but it is broken somehow.

1

I have verify your python code for a test polygon shape. It worked correctly. It writes the coordinates of the defined XY Coordinate System into the attribute table.

Ensure that the XY Coordinate System of the shape file is defined correctly. If you use your code directly in ArcMap check the Coordinate System of the Data Frame. If your shape file is defined in a Cartesian coordinate system you have to project your shape file in a previous step:

http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000007m000000

Hope that helps!

  • My shape file have Projected Coordinate System: WGS_84_UTM_zone_42N, so projection is not needed. – Vasyska Sep 19 '13 at 9:22
  • 1
    @Vasyska Yes, you have to project it if you want to calculate the centroids in degrees and not in meters, because WGS_84_UTM_zone_42N has coordinates in meters. – KalleBlomquist Sep 19 '13 at 9:37
  • 1
    You was right after reprojecting it works fine. – Vasyska Sep 19 '13 at 10:42

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.