Select to view content in your preferred language

Trouble with writing feature to shapefile

965
2
03-31-2014 04:12 PM
MarionConstante
Deactivated User
I created a new shapefile and using the cursor I'm trying to add data to the new shapefile using an array.  When I run the python script this always shows:


feat.shape = pointArray
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\_base.py", line 35, in __setattr__
    return setattr(self._arc_object, attr, ao)
RuntimeError: ERROR 999999: Error executing function.

The code snippet for the cursor is (in bold is what seems to be the problem):

    output = "Points.shp"
    arcpy.CreateFeatureclass_management("C:/workspace", output, "POINT")
    cur = arcpy.InsertCursor(output)
    pointArray = arcpy.Array()

    # start point
    start = arcpy.Point()
    (start.ID, start.X, start.Y) = (1, origin_x, origin_y)
    pointArray.add(start)

    # end point
    end = arcpy.Point()
    (end.ID, end.X, end.Y) = (2, end_x, end_y)
    pointArray.add(end)


    feat = cur.newRow()
    feat.shape = pointArray
    cur.insertRow(feat)


Any thoughts, I am still new to python.

Thanks
Tags (2)
0 Kudos
2 Replies
ShaunWalbridge
Esri Regular Contributor
Marion,

The problem is that you're initially creating a shapefile with type "POINT", but then trying to write Polylines to it. Change the create feature class layer to:

arcpy.CreateFeatureclass_management("C:/workspace", output, "POLYLINE")


cheers,
Shaun
0 Kudos
MarionConstante
Deactivated User
Thanks it worked
0 Kudos