populate x,y

4946
17
Jump to solution
07-29-2015 02:30 PM
PacoAlverez
New Contributor III

I am trying to populate ever point's x,y when a point is created by a mouse click or clicking. Some times i might only create one point but sometimes i may have to create more then one. I am having trouble populating the x,y of the new created points.

this is currently what i have. I know it's wrong. i would like to see how to do this correctly.

getting error at

Traceback (most recent call last):

  File "C:\GIS\Python\AddPoint\AddPoint_4.py", line 18, in <module>

    geom = prow.SHAP

AttributeError: 'tuple' object has no attribute 'SHAPE'

Failed to execute (Script).

#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]
        geom = prow.SHAPE
        prow.x = geom.X
        prow.y = geom.Y
del prow          

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          
0 Kudos
17 Replies
DarrenWiens2
MVP Honored Contributor

Okay, last reply, then you're going to have to piece some of this together on your own.

insCursor = arcpy.da.InsertCursor(pointFC, ['Minrights', 'FCVTotal','POINT_X','POINT_Y','SHAPE@XY']) # create insert cursor      
  
with arcpy.da.SearchCursor(point,['Minrights', 'FCVTotal','POINT_X','POINT_Y','SHAPE@XY']) as cursor: # loop through feature set      
    for row in cursor:   
        row[0] = row[0] # if the 'Minrights' value is coming from the search cursor, otherwise change this
        row[1] = row[1] # if the 'FCVTotal' value is coming from the search cursor, otherwise change this
        row[2] = row[4][0] # the X coordinate from the SHAPE@XY
        row[3] = row[4][1] # the Y coordinate from the SHAPE@XY
        row[4] = row[4] # the whole SHAPE@XY
        insCursor.insertRow(row)   
0 Kudos
PacoAlverez
New Contributor III

Darren. thank you for your time and responses. i apologize for my python skills are not so great.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Since Arcpy Data Access search cursors return tuples, this specific code will generate a TypeError since tuples don't support item assignment.

0 Kudos
PacoAlverez
New Contributor III

Hi Joshua. I was trying to understand how to create a point or multiple points and how those new points attributes populated from the parcel the new points are within. The x,y would be calculated at the time the new point or points are created.  I am rather new to python so my first posted code was based on information i found.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Unless you are willing/able to post a subset of the data and a description of what the final product would look like, I am out of ideas.  Best of luck.

0 Kudos
PacoAlverez
New Contributor III

Here is some data. thanks for your help.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

What is point, exactly?  Your code is  point = arcpy.GetParameterAsText(0)  # click , but I am unclear what is being returned.  Is point supposed to be an ArcPy Point object or a set of coordinates for a location or a name to a feature class containing points?

Regarding your original error message, just so you understand why you were getting that error, you were using the SHAPE@XY token.  The SHAPE@XY token returns a Python tuple of the x,y coordinates of the point, not an ArcPy Point object or PointGeometry object.  As such, there is no 'SHAPE' attribute so an AttributeError is generated.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Are POINT_X and POINT_Y populated in point or are they going to be new data in pointFC?  If they are NULL in point, why are you retrieving them with the search cursor?

In cases like this, posting some sample data and an explanation of what you are trying to accomplish is helpful.  It could be your entire approach is off, and people in GeoNet could offer a different way of doing it entirely.

0 Kudos