Add Row to Existing Point Feature Class

226
1
Jump to solution
04-23-2020 12:11 PM
AletaMarch
New Contributor
Hello,
I am having difficulty adding a new row to an existing point feature class using the arcpy.da InsertCursor.
All the fields are populated, except for the ‘Lon’ and ‘Lat’ fields which are given NULL values (‘None’ type).
The existing point feature class was created using arcpy.management.XYTableToPoint. The fc fields are: ['Shape',
'USGS_ID', 'Date', 'Event_Time', 'Magnitude', 'Place', ‘Lon', ‘Lat', 'Depth', 'Update_Time']. 'Lon' and 'Lat' are type Float.
In the call to the InsertCursor, the 'Lon' field was replaced with 'SHAPE@X' and the 'Lat' field with 'SHAPE@Y'.
The 'Shape' field was not included. Input consisted of a tuple of values corresponding to the listed fc fields.
Sample input:
new_event_rows = [('ci39400304', '2020-04-22', '07:03:47.740000', 3.690000057220459,'1km S of View Park-Windsor Hills, CA', -118.34950256347656, 33.98899841308594, 11.600000381469727, 1587616153600.0)].
My code is as follows:
total_new_events = len(new_event_rows)
if total_new_events > 0: # If there are new events to add to the feature class
    with arcpy.da.InsertCursor(base_fc, ['USGS_ID', 'Date','Event_Time', 'Magnitude', 'Place', 'SHAPE@X', 'SHAPE@Y',                                                                                                                                              'Depth','Update_Time']) as irows:
        index = total_new_events - 1
        while index >= 0:
            # Populate new row of base_fc with element (tuple) of new_event_rows
            irows.insertRow(new_event_rows[index])
            index = index - 1
    del irows

I would appreciate your helping me to understand how to use the geometry tokens.
Thank you,
Aleta March
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AletaMarch
New Contributor

Hello All,

My problem has been resolved. I was trying to use the geometry tokens ('SHAPE@X' and 'SHAPE@Y') to replace the fields containing the floating point X and Y values for 'Lon' and 'Lat'.  Wrong tokens and wrong fields!

By 1) using the 'SHAPE@XY' token instead of the 'Shape' field name in the arcpy.da.InsertCursor field list and 2) populating that field with  a tuple containing the (Lon, Lat) values, the Point geometry is added.

It seems so simple now, but as a newcomer to ArcPy, it wasn't clear to me that the 'Shape' field that, to my eye,  contained values in the feature class table that looked like the string 'Point', needed to be filled with a tuple of floating point numbers. Lesson learned.

Aleta March

View solution in original post

1 Reply
AletaMarch
New Contributor

Hello All,

My problem has been resolved. I was trying to use the geometry tokens ('SHAPE@X' and 'SHAPE@Y') to replace the fields containing the floating point X and Y values for 'Lon' and 'Lat'.  Wrong tokens and wrong fields!

By 1) using the 'SHAPE@XY' token instead of the 'Shape' field name in the arcpy.da.InsertCursor field list and 2) populating that field with  a tuple containing the (Lon, Lat) values, the Point geometry is added.

It seems so simple now, but as a newcomer to ArcPy, it wasn't clear to me that the 'Shape' field that, to my eye,  contained values in the feature class table that looked like the string 'Point', needed to be filled with a tuple of floating point numbers. Lesson learned.

Aleta March