TransWikia.com

InsertCursor in ArcGIS Pro doesn't understand my coordinates

Geographic Information Systems Asked by veen on June 5, 2021

I am trying to use the arcpy.da.InsertCursor to add simple points to a feature class, but it doesn’t work for me as every single point I add ends up somewhere near Paris. Here’s the simplest code block that doesn’t work for me:

arcpy.CreateFeatureclass_management(' (my path here) ...Map.gdb','Hotspots2', 'POINT')
a = arcpy.Point(7, 7)
cursor = arcpy.da.InsertCursor("Hotspots2",["SHAPE@XY"])
cursor.insertRow([a])
del cursor

It ends up here:

Paris, ugh

at coordinate ~ (3.3, 48). Whatever coordinates I enter into a don’t matter for the outcome. If I change a to a point geometry it doesn’t work. If I use SHAPE@ and a point geometry it also doesn’t work. Every darn point ends up there. What am I doing wrong and can someone test to see if they get the same result??

4 Answers

Try using arcpy.PointGeometry object instead of point.
Suggestion 2: you didn't define the spatial reference of your feature class. This means it is inheriting it from whatever your dataframe is. Most likely it's going in as web mercator, but I am guessing you want WGS-1984.

From the help: CreateFeatureclass_management (out_path, out_name, {geometry_type}, {template}, {has_m}, {has_z}, {spatial_reference}, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})

To create the spatial reference object and perform the insert do the following:

 sr = arcpy.SpatialReference(4326)
 coords = [(3.3, 48) ]
 fc = arcpy.CreateFeatureclass_management(r'<path>', '<name>', 'POINT', spatial_reference=sr)[0] 
 cursor = arcpy.da.InsertCursor(fc,['SHAPE@XY'])
 for coord in coords:
     cursor.insertRow([coord])
     del coord
 del cursor

Correct answer by code base 5000 on June 5, 2021

I think that when you create a point through arcpy.Point({x},{y}) one should use SHAPE@, not SHAPE@XY in your cursor:

InsertCursor - help:

SHAPE@XY —A tuple of the feature's centroid x,y coordinates.

SHAPE@ —A geometry object for the feature.

Try adjusting that field in your cursor, that's how I'm inserting points in my script.

If that doesn't work, try setting your X and Y as a string, that's how I'm using them inside arcpy.Point({x},{y}).

Answered by JiyuuSensei on June 5, 2021

When using SHAPE@ token the cursor is expecting a geometry. You are creating this with arcpy.Point:

import arcpy
pointfc = r'C:TEST.gdbpoint'

a = [arcpy.Point(5,7)]

cursor = arcpy.da.InsertCursor(pointfc, ['SHAPE@'])
cursor.insertRow(a)
del cursor

If you want to use the SHAPE@XY token the cursor is expecting a tuple, for example (5,7) :

import arcpy
pointfc = r'C:TEST.gdbpoint'

a = (5,7)

cursor = arcpy.da.InsertCursor(pointfc, ['SHAPE@XY'])
cursor.insertRow((a,))
del cursor

Answered by BERA on June 5, 2021

I don't really work in ArcGIS, but from a general GIS perspective it looks as if you may be entering coordinates in a different coordinate system to that used by the map window. Have you checked that your input coordinates use the same system as that of the map window?

Those coordinates (3.3, 48) are mapped correctly using WGS84, where are you expecting them to map to?

Answered by T_Bacon on June 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP