admin管理员组

文章数量:1189186

The end goal is to update an ongoing shapefile with missing well data. As field agents find missing wells, they can update a spreadsheet with GPS coords (Decimal Degrees). Once a month or so I can run the Python code in ArcMAP and update the shapefile with new points. I am trying to insert the GPS coordinates as points into a shapefile in ArcMAP 10.7 using Python 2.7.

Everything appears to be working correctly, the data table and attributes are correct, the newly added points appear to be correct relative to one another. The issue is when I try to update an existing file. The newly added points are way off somewhere else. In the example here, I tried to add the exact same GPS coords (in decimal degrees) as an existing point. You can see the first entry, the Y_Coord and X_Coord for Well_1 is the same as 1. However the new point is way below the other points.

Immediately, I am thinking this is a coordinate issue of some sort, and searches on the problem indicate a coordinate issue as well but I have a million-times checked to make sure the shapefile, a boundary layer (visual check only), and dataframe are all in the correct geographic and projection coordinate systems. GCS being used is GCS_WGS_1984 (WKID: 4326) and PCS is WGS_1984_UTM_Zone_16N (WKID: 32616).

I have doble-checked, triple, a million times checked to make sure the coordinates systems are correct. I have tried to specifically assign it in Python (although I am not sure I am calling it correctly.

Questions: Am I defining the spatial reference in Python correctly? I feel like I am just calling the object but not actually initiating it. If not, is there a way to specifically tell Python to apply this in the correct GCS/PCS?

import arcpy

#one coordinate only for testing
coords = [(1, (43.20779, -89.78513))]

# link to shapefile
shapefile = r'M:\ARC\gis_users\Missing_Wells\Missing_Wells.shp'

# Define the spatial reference (GCS_WGS_1984 = 4326, PCS_WGS_1984_UTM16N = 32616)
arcpy.SpatialReference(32616)

#use SHAPE@XY syntax to add point features to a point feature class
with arcpy.da.InsertCursor(shapefile, ['Well_ID', 'Y_Coord', 'X_Coord', 'SHAPE@XY']) as cursor:
#Insert new rows that include the well ID and a x,y coordinate pair
    for Well_ID, (lat, lon) in coords:
        cursor.insertRow((Well_ID, lat, lon, (lat, lon)))
        print('added')
...

sys.exit()

p.s. yes, I know there are tools in ArcGIS Online that can accomplish this goal much easier and in a more timely manner. Our Org will be moving over to ArcGIS Pro next year. We just don't have the budget for it at the moment.

The end goal is to update an ongoing shapefile with missing well data. As field agents find missing wells, they can update a spreadsheet with GPS coords (Decimal Degrees). Once a month or so I can run the Python code in ArcMAP and update the shapefile with new points. I am trying to insert the GPS coordinates as points into a shapefile in ArcMAP 10.7 using Python 2.7.

Everything appears to be working correctly, the data table and attributes are correct, the newly added points appear to be correct relative to one another. The issue is when I try to update an existing file. The newly added points are way off somewhere else. In the example here, I tried to add the exact same GPS coords (in decimal degrees) as an existing point. You can see the first entry, the Y_Coord and X_Coord for Well_1 is the same as 1. However the new point is way below the other points.

Immediately, I am thinking this is a coordinate issue of some sort, and searches on the problem indicate a coordinate issue as well but I have a million-times checked to make sure the shapefile, a boundary layer (visual check only), and dataframe are all in the correct geographic and projection coordinate systems. GCS being used is GCS_WGS_1984 (WKID: 4326) and PCS is WGS_1984_UTM_Zone_16N (WKID: 32616).

I have doble-checked, triple, a million times checked to make sure the coordinates systems are correct. I have tried to specifically assign it in Python (although I am not sure I am calling it correctly.

Questions: Am I defining the spatial reference in Python correctly? I feel like I am just calling the object but not actually initiating it. If not, is there a way to specifically tell Python to apply this in the correct GCS/PCS?

import arcpy

#one coordinate only for testing
coords = [(1, (43.20779, -89.78513))]

# link to shapefile
shapefile = r'M:\ARC\gis_users\Missing_Wells\Missing_Wells.shp'

# Define the spatial reference (GCS_WGS_1984 = 4326, PCS_WGS_1984_UTM16N = 32616)
arcpy.SpatialReference(32616)

#use SHAPE@XY syntax to add point features to a point feature class
with arcpy.da.InsertCursor(shapefile, ['Well_ID', 'Y_Coord', 'X_Coord', 'SHAPE@XY']) as cursor:
#Insert new rows that include the well ID and a x,y coordinate pair
    for Well_ID, (lat, lon) in coords:
        cursor.insertRow((Well_ID, lat, lon, (lat, lon)))
        print('added')
...

sys.exit()

p.s. yes, I know there are tools in ArcGIS Online that can accomplish this goal much easier and in a more timely manner. Our Org will be moving over to ArcGIS Pro next year. We just don't have the budget for it at the moment.

Share Improve this question edited Jan 27 at 6:12 Publicchee asked Jan 24 at 16:12 PubliccheePublicchee 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Solution is credited to username DavidPike from the Esri community.

TlDr: Set GCS to WGS84. That's it. No PCS. Then you can enter the data as decimal degrees.

Long version: I was over-specifying when I specified a PCS. As DavidPike pointed out, ArcMAP then interpreted the inputs as cartesian coordinates. My SHAPE@XY was then overwriting the coordinates with what I specified it to be so it LOOKED like the coordinates were correct in the attribute table. However, if the point was examined the decimal degree coordinates were actually close to zero. Solution was to just specify the GCS.

If a PCS must be specified, than an alternative solution would be to convert the decimal degrees into the appropriate cartesian coordinates of whatever PCS you choose. This should be done in Python prior to inputting into ArcMAP so that you are inputting cartesian coordinates.

Much appreciated again DavidPike!!

本文标签: PythonArcMAP ArcPy InsertCursor points not showing up correctlyStack Overflow