1

I have the code below that works, however I want the units to be in decimal degrees. How do I force this?

fields2 = ['cent_lat', 'cent_long', 'SHAPE@X', 'SHAPE@Y']

with arcpy.da.UpdateCursor(fc,fields2) as cursor:
    for row in cursor:
        row[0] = row[2]
        row[1] = row[3]

        cursor.updateRow(row)
5

You can just project the geometry of the point on the fly like the below example which will project a point to WGS 1984 (WKID 4326). Then you can just get the x and y values from that newly projected point geometry.

What your code might look like:

import arcpy

fields2 = ['cent_lat', 'cent_long', 'SHAPE@']

with arcpy.da.UpdateCursor(fc,fields2) as cursor:
    for row in cursor:
        pt = row[2].projectAs('4326').centroid
        row[0] = pt.Y
        row[1] = pt.X

        cursor.updateRow(row)

projectAs is a method of the "pointGeometry" arcpy class.

  • 1
    I forgot the quotes around the spatial reference number '4326' – PMK Apr 10 '18 at 19:33
0

Try that way:

fields2 = ['cent_lat', 'cent_long', 'SHAPE@X', 'SHAPE@Y']
sr = arcpy.SpatialReference(4326)

with arcpy.da.UpdateCursor(fc,fields2, "", sr) as cursor:
    for row in cursor:
        row[0] = row[2]
        row[1] = row[3]

        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.