Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a polygon from polylines. I've created this script but it gives errors of Arrays. Thanks.

import arcpy
polygonArray = arcpy.Array()
cursor = arcpy.InsertCursor(Output_polygon)
row = cursor.newRow()
polygon = arcpy.Polygon(polygonArray, "")
row.SHAPE = polygon
del row
del cursor
share|improve this question
up vote 5 down vote accepted

You need to break it down to points if they're good points and reconstruct. Polylines are made from paths, polygons are made from rings. Although they are created in a similar way they are not compatable, hence your error.

Go through each point on the line adding a point to your output array and then insert.

here's a post that might help Get all the points of a polyline

This should work, though it's only a fragment... you have to set your own FeatureClass and make an insert cursor to accept the polygon:

rows = arcpy.da.SearchCursor(FeatureClass)
desc = arcpy.Describe(FeatureClass)
shapefieldname = desc.ShapeFieldName

for row in rows:
    feat = row.getValue(shapefieldname) # input line
    PArray = arcpy.Array() # new polygon
    partnum = 0
    for part in feat:
        for pnt in feat.getPart(partnum):
        # you will need to check that the first and last point are the same
        partnum += 1
    OutPoly = arcpy.Polygon(PArray) # now it's a polygon

Have a read of these:

Reading Geometries

Writing Geometries

share|improve this answer
Thanks Michael. I tested the code and it gave this error: feat = row.getValue(InFc) # input line NameError: name 'row' is not defined – Matt May 15 '14 at 6:54
row is a cursor object (arcpy.da.searchcursor) see edits. – Michael Miles-Stimson May 15 '14 at 21:33
Thanks a lot, Michael. I've got it working with some tweaks. – Matt May 19 '14 at 9:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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