I am attempting to learn python so please bare with me. I would like to create points with a mouse click. I have the following code from another post but it's not working i am getting the following error. at this point i would like to just create one point but after i get past this code i would like to be able to click anywhere and create multiple points. Can some one help me out with this code?
Traceback (most recent call last):
File "C:\GIS\AddPoint.py", line 17, in <module>
cursor.insertRow(row)
TypeError: sequence size must match size of the row
Failed to execute (Script).
#import modules
import arcpy
point = arcpy.GetParameterAsText(0) #click
An = "AnimalPoints" #target point feature class Animal Sightings
for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'):
x,y = prow[0]
del prow
point1 = arcpy.Point(x, y)
ptGeometry = arcpy.PointGeometry(point1)
with arcpy.da.InsertCursor(An,('SHAPE@XY')) as cursor:
cursor.insertRow(row)
Solved! Go to Solution.
Freddie Gibsonmakes a good point you may want to start your code with something like below just to make sure your in the same spatial reference.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
dfsr = df.spatialReference
fcsr = arcpy.Describe(An).spatialReference
if dfsr.name == fcsr.name:
"""Now do your work"""
Wes thank you i will incorporate that into the code. Also how would i create multiple points and actually have them created to the feature class?
I would like to populate the POINT_X AND POINT_Y when the point is created.
i have add to my code to try to get the x,y populated but i get an error, i am thinking it's a syntax error.
File "C:\GIS\Python\AddPoint\AddPoint.py", line 24, in <module>
cursor.insertRow(row_value)
TypeError: sequence size must match size of the row
#import modules
import arcpy
arcpy.env.qualifiedFieldNames = False
An = "AnimalPoints" #target point feature class Animal Sightings
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
dfsr = df.spatialReference
fcsr = arcpy.Describe(An).spatialReference
if dfsr.name == fcsr.name:
"""Now do your work"""
point = arcpy.GetParameterAsText(0) #click
for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'):
x,y = prow[0]
del prow
row_value = ([(x,y)])
with arcpy.da.InsertCursor(An,('POINT_X', 'POINT_Y','SHAPE@XY')) as cursor:
cursor.insertRow(row_value)
You need to make row_value = something before you can create the row. Insert Row will accept either a list or tuple. You'll need to set row_value in the order of your field list ['POINT_X', 'POINT_Y','SHAPE@XY']
i am do that here am i not?
row_value = (x,y)
That is the tuple for Shape@XY
it should be
row_value = [x,y,(x,y)] or something similar
Got it, thank you.