1

Displaying points from a table is easy - you just right click the table and choose "Display XY Data".

But what is the comparable method for shapefiles? When you right click a shapefile the "Display XY Data" option is nowhere to be found. The "Add XY Coordinates" tool is not appropriate because it just adds two new columns "POINT_X" and "POINT_Y" to the table, not to the map.

My shapefile's attributes table is as follows.

enter image description here

The first 4 points were pre-existing... then I ran a script that added the last two from an excel table. So now they're in my shapefile's attributes table, but not showing on the map.

Relevant portion of My script:

#Insert NEW points into Target Shapefile
x = 0
with arcpy.da.InsertCursor(Target_Shapefile, ['CSSP_ID', 'Lat', 'Lon']) as curs:
    while x < total_new:
        curID = new[x]
        newcoord = latLonDi[curID]
        newlat = newcoord[0]
        newlon = newcoord[1]
        curs.insertRow((curID, newlat, newlon))
        x+=1

How do I display these last two points so that I have all six showing on the map? This seems like it should be a straightforward task for Arc. Surely there's a relatively simple process akin to "Display XY Data" for tables.

5
  • You've pretty much missed the entire point of spatial data types. The points in a shapefile are a property of the "shape" column, which you don't seem to have populated (you can't render that which is NULL). The time to fix this was when you ran the script inserting features in the shapefile. If you edit the question to be "How do I alter this script to insert a Geometry into a shapefile" you won't need a second script to update the rows without geometry.
    – Vince
    Jan 9, 2018 at 1:20
  • @Vince - Not so although I can understand why you assumed that my shapefile lacked a "shape" column based on the portion of my table I originally showed. I've added a new screen shot of my entire table to show that it does have a "shape" column.
    – Waterman
    Jan 9, 2018 at 1:39
  • Yes, all shapefiles have a shape column, but if you don't populate it, then it doesn't render. The attributes of Lon and Lat must be encoded with a Point or PointGeometry (with the values in X,Y order -- Longitude,Latitude), and that point inserted, or the column value will be null. Unfortunately, the Table doesn't show "null" when the geometry is Null, which is why I suggested you provide the script (which should have a "Shape@" in the DA InsertCursor column list and a point in the row array). If you Zoom To and the extent doesn't change, it's a null.
    – Vince
    Jan 9, 2018 at 3:25
  • @Vince - That's it. Thanks, this is my first time doing this and I hadn't read far enough down ESRI's page on Insert Cursors to get to the section on using tokens like "@ShapeXY". Must say I find the whole 'adding geometry that's never acknowledged in the table' thing a bit mysterious but it the bottom line is my script works like a charm now - new points automatically show up (caveat - once you 'adjust' the map project slightly - for example, by using the Pan tool). To help others I've reworded my question and added my original code above. Would you like to add your solution?
    – Waterman
    Jan 9, 2018 at 23:05
  • You did the work. You should get the rep.
    – Vince
    Jan 10, 2018 at 0:55

2 Answers 2

1

Problem: My original code should have used the "Shape@XY" token to add 'geometry' to all NEW points.

Solution: New code below (notice 4th argument 'SHAPE@XY' in the Insert Cursor, and 4th argument 'newcoord' in the curs.insertRow).

#Insert NEW points into Target Shapefile
x = 0
with arcpy.da.InsertCursor(Target_Shapefile, ['CSSP_ID', 'Lat', 'Lon','SHAPE@XY']) as curs:
    while x < total_new:
        curID = new[x]
        newcoord = latLonDi[curID]
        newlat = newcoord[1]
        newlon = newcoord[0]
        curs.insertRow((curID, newlat, newlon, newcoord))
        x+=1

If anyone wants to see the full code just let me know but it should suffice to understand that...

'new' = list of IDs of all NEW points

'latLonDi' is just a dictionary that collected each NEW point's ID, Lat, and Lon

@Vince pointed me in the right direction.

0

The simplest solution is to export your shapefile table to DBF and then run "Add XY Data" to generate a new shapefile.

The preferred way to add points to an existing shapefile from x,y coordinates is using Absolute x,y while editing in ArcMap. More info here:

Creating a point or vertex at an exact x,y location (absolute x,y)

If you want to add multiple points by copying and pasting x,y coordinate pairs, better to leave the data as a table and run "Add XY Data" each time you want to generate a shapefile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.