I would like to be able to click multiple locations and create points where i click and populate each points x, y. i have the current code but only creates one point, so i needs help.
current code.
#import modules import arcpy arcpy.env.qualifiedFieldNames = False An = "AnimalSightings" #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,(x,y)] with arcpy.da.InsertCursor(An,('POINT_X', 'POINT_Y','SHAPE@XY')) as cursor: cursor.insertRow(row_value)
Solved! Go to Solution.
Darren i am still confused on how to incorporate what you suggested into my code.
this is what i currently have.
#import modules import arcpy arcpy.env.qualifiedFieldNames = False pointFC = "Animal Sightings" #target point feature class Animal Sightings mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] dfsr = df.spatialReference fcsr = arcpy.Describe(pointFC).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 point1 = arcpy.Point(x, y) ptGeometry = arcpy.PointGeometry(point1) insCursor = arcpy.da.InsertCursor(pointFC,('POINT_X','POINT_Y','SHAPE@XY')) # create insert cursor with arcpy.da.SearchCursor(point,('POINT_X','POINT_Y','SHAPE@XY')) as cursor: # loop through feature set for row in cursor: POINT_X = row[0] POINT_Y = row[1] insCursor.insertRow(row) # insert row del insCursor # delete insert cursor
It's tough to help without knowing how it doesn't work - is there an error?
Your current example assigns values to variables POINT_X and POINT_Y which are never used. However, since your InsertCursor and SearchCursor happen to use the exact same fields, you should be able to use the entire row from the SearchCursor to insert into the InsertCursor.
insCursor = arcpy.da.InsertCursor(pointFC,('POINT_X','POINT_Y','SHAPE@XY')) # create insert cursor with arcpy.da.SearchCursor(point,('POINT_X','POINT_Y','SHAPE@XY')) as cursor: # loop through feature set for row in cursor: insCursor.insertRow(row) # insert row
Try this. If it doesn't work, reply with error message or explanation how it fails to work.
currently the code runs fine with no error, but the POINT_X & POINT_Y doesn't get populate in the attribute table of the point or points that get created. I would like to create points by using the mouse click and update the x,y of those points that i used the mouse click to create.
I am using the last code i attached.
thanks Darren.
- for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'):
- x,y = prow[0]
- del prow
^ this reads all your rows, one at a time, overwriting the values of x and y each time. So, in the end, you are left with one single pair of coordinates. A SearchCursor is like a for loop that cycles through all records and then stops. If you want to do something for each record in "point", you need to do it within the SearchCursor.