[GIS] How to create points in a Feature Class from a database table

arcgis-10.1arcpy

I have a destination (Feature Class):

C:/Users/XXX/Documents/ArcGIS/ABC.gdb/SamplePoints

I have a database table in the same file geodatabase that contains my source point data. I have columns with attributes in addition to the requisite coordinate data.

Using Arcpy, how do I retrieve the points from the source database table and create points in the destination Feature Class?

I tried creating a single point using this code:

import arcpy
cur = arcpy.InsertCursor(fc, ["SHAPE@XY"])
pnt = arcpy.Point()
pnt.x = 20000
pnt.y = 10000
feat = cur.newRow()
feat.shape = pnt
cur.insertRow(feat)
del cur

but, although a row is created, the coordinates are 0,0.

Current thoughts – I'll probably use a cursor to step through the records retrieved and for each row in the source, build a point and insert it into the destination. The logic seems to make sense.

Best Answer

I am not sure whether nested cursors (e.g. a SearchCursor for the source table and an InsertCursor for the destination feature class) will work, but it's worth a shot.

Specific to your problem of how to get geometry data into a feature class using an InsertCursor:

  1. Use a da.InsertCursor (since you have access to 10.1+)

  2. Take a look at the Help page for arcpy.da.InsertCursor, particularly the examples. I think that you are making it more complex than necessary.

This is their example. No geometry objects needed, just the numeric values.

import arcpy

# A list of values that will be used to construct new rows
row_values = [('Anderson', (1409934.4442000017, 1076766.8192000017)),
              ('Andrews', (752000.2489000037, 1128929.8114))]

# Open an InsertCursor
cursor = arcpy.da.InsertCursor("C:/data/texas.gdb/counties", ("NAME", "SHAPE@XY"))

# Insert new rows that include the county name and a x,y coordinate
#  pair that represents the county center
for row in row_values:
    cursor.insertRow(row)
Related Question