[GIS] Arcpy: List to point feature class

arcgis-10.0arcgis-desktoparcpylistpython

I have a list of lists that contains:

[vala, valb, valc, vald, (pntx, pnty)]
[vala, valb, valc, vald, (pntx, pnty)]
[vala, valb, valc, vald, (pntx, pnty)]

I also have a list of the field names that correspond to vala, valb, etc.

I am trying to use arcpy to create a feature class with all the information from the list, with the proper field names from the list of field names.

As I want the FC to be a point layer, I thought about using add XY event layer, however there seems to be no option for adding a field list and my x,y coordinates are in a tuple instead of individual list positions for indexing. I could probably create an empty feature class and use an insert cursor, but then how do I deal with the geometry?

I am using ArcMap 10.0.

Best Answer

with 10.1, you'll need to use arcpy.da.insertcursor with the SHAPE@XY token

c = arcpy.da.InsertCursor(emptyshapefil, 
                          ("NAMEa", "NAMEb", "NAMEc", "NAMEd", "SHAPE@XY"))

for row in yourlist:
    c.insertRow(row)

with 10.0 it is more complicated. you'll need arcpy.insertCursor and point geometry

c = arcpy.InsertCursor(emptyshapefile)

for row in yourlist:
    feat = c.newRow()   
#attributes
    feat.NAMEa = row[0]
    feat.NAMEb = row[1]
    feat.NAMEc = row[2]
    feat.NAMEd = row[3]
#geometry 
    pnt = arcpy.Point()
    pnt.X = row[4][0]
    pnt.Y = row[4][1]
    feat.shape = pnt
    c.insertRow(feat)
del feat, c
Related Question