1

I am writing polygon geometries and I have points holding the geometries that represent vertices of the polygon.

When I run the code below I get:

TypeError: sequence size must match size of the row

cur = arcpy.da.InsertCursor(fc_path, ["SHAPE@"])

# Stuff
    X_Min = DF_extent.XMin
    X_Max = DF_extent.XMax
    Y_Min = DF_extent.YMin
    Y_Max = DF_extent.YMax

    point_0 = arcpy.Point(X_Min, Y_Min)
    point_1 = arcpy.Point(X_Min, Y_Max)
    point_2 = arcpy.Point(X_Max, Y_Max)
    point_3 = arcpy.Point(X_Max, Y_Min)

   # this is the part that is causing errors:
    cur.insertRow((point_0, point_1, point_2, point_3, point_1))

When I have the vertices that make up a polygon, what is the correct way to pass that information to the insert cursor so it knows that all of those points are, in fact, one argument to be taken at once?

  • 2
    You have this tagged with 10.0, but are using DA cursors, which were released at 10.1. Please Edit the question to specify the exact ArcGIS release. Note that there's an entire documentation topic on writing geometries (and to avoid coordinate value corruption, the SpatialReference should always applied to Geometry constructors) – Vince Dec 4 '19 at 20:07
0

Try passing a polygon object, instead of a list of point objects. You can create a polygon object from your point objects, and then pass that to your insert cursor.

See: Polygon class documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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