I'm calculating 4 double fields for a polygon feature class (exploded, single-part features): SquareFeet, Acreage, Lat, and Long

I found the correct python expressions to calculate SquareFeet & Acreage using the Calculate Field (Data Management) tool.

For the Lat and Long fields, I've tried using !SHAPE.CENTROID.Y! which calculates in either feet or meters depending on which unit is set on the data, but since I need the calculation in decimal degrees this isn't acceptable. And I've tried !SHAPE.CENTROID.Y@DECIMALDEGREES! to get the calculation in decimal degrees, but this expression just flat out doesn't return anything. I've tried setting the parser to PYTHON and PYTHON_9.3.

Does anyone know if there's a python expression to calculate latitude and longitude in decimal degrees?

(!SHAPE.CENTROID.X@DECIMALDEGREES! of course was used to try and calculate Long)

Calculate Field tool

  • Change the expression type to 'Python'. I'm not sure that capability was available in v9.3.
    – Bjorn
    Mar 6 '17 at 18:49
  • @Bjorn "PYTHON" is pre-9.3, "PYTHON_9.3" is 9.3 onwards. Are you saying it was present before 9.3 but then removed?
    – Midavalo
    Mar 6 '17 at 18:54
  • I've tried both ways, and neither parser works, so it must be the expression that't not right
    – geominded
    Mar 6 '17 at 18:56
  • @geominded What version of ArcGIS Desktop?
    – Midavalo
    Mar 6 '17 at 19:06
  • @Midavalo 10.3 using a professional or standard license
    – geominded
    Mar 6 '17 at 20:15

Found out that for some reason, the data has to be in a geographic coordinate system without a projection, and you can on-the-fly project into WGS84 (in the case in the code below) or NAD83 when calculating.

The code below ended up being a solution to calculating Lat/Long for polygons in decimal degrees:

arcpy.CalculateField_management(inputData, "LAT", "arcpy.PointGeometry(!Shape.centroid!,!Shape.spatialReference!).projectAs(arcpy.SpatialReference(4326)).firstPoint.Y","PYTHON_9.3","#")

arcpy.CalculateField_management(inputData, "LONG", "arcpy.PointGeometry(!Shape.centroid!,!Shape.spatialReference!).projectAs(arcpy.SpatialReference(4326)).firstPoint.X","PYTHON_9.3","#")

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.