Arcpy Updatecursor not using normal LAT LONG units

308
4
Jump to solution
02-19-2024 10:49 AM
JJGFMO
by
New Contributor II

I am trying to update a points lat long. Instead of placing the point at LAT 50, LONG 50, it's updating the point to just barely off from 0,0 (0.0004492, 0.0004492). This works as expected on another machine. I suspect there is some spatial reference that needs to be set. How do I do that?

 

import arpy

inFeatures = <points layer location>

with arcpy.da.UpdateCursor(inFeatures, ["SHAPE@X","SHAPE@Y", "bhid"]) as cursor:
for row in cursor:
if row[2] == "1175":
print(row[0])
print(row[1])
row[0] = 50
row[1] = 50

cursor.updateRow(row)

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

WGS 1984 Web Mercator (auxiliary sphere) is a projected coordinate system that uses metres as the units, not longitude/latitude.

Try setting an output spatial reference.

with arcpy.da.UpdateCursor(inFeatures, ["SHAPE@X","SHAPE@Y", "bhid"], spatial_reference=arcpy.SpatialReference(4326)) as cursor:
    for row in cursor:
        etc...

View solution in original post

4 Replies
JoshuaBixby
MVP Esteemed Contributor

We need a bit more information.  For example, the feature class the cursor is updating already has a spatial reference, or it should, so what is it?  Also, the logic of the code snippet doesn't make sense because if you are working with latitude and longitude, how will you ever get a latitude of "1175"?  (See line:  if row[1] == "1175").

0 Kudos
JJGFMO
by
New Contributor II

That's supposed to be 2, not 1. A spelling error due to trying to get the post to show the code with proper indentation. It's been corrected.

The code finds the row with a "bhid" of 1175. It then updates the SHAPE@X and Y, but the numbers are being interpreted as non-DD. It's some weird coordinate system.

The spatial reference of the layer in a file gdb is "WGS 1984 Web Mercator (auxiliary sphere)", geographic coordinate system "WGS 1984".

0 Kudos
Luke_Pinner
MVP Regular Contributor

WGS 1984 Web Mercator (auxiliary sphere) is a projected coordinate system that uses metres as the units, not longitude/latitude.

Try setting an output spatial reference.

with arcpy.da.UpdateCursor(inFeatures, ["SHAPE@X","SHAPE@Y", "bhid"], spatial_reference=arcpy.SpatialReference(4326)) as cursor:
    for row in cursor:
        etc...
JJGFMO
by
New Contributor II

Thanks, Luke_Pinner. This is exactly what I was looking for. My mistake was thinking that WGS 1984 (WKID 4326) was the same as WGS 1984 Web Mercator.

0 Kudos