Creating a Convex Hull with Points

Using a point featureclass as the input and a target polygon featureclass as the output to put the convex hull into, just use the following code:

def CreateConvex(inputfc, outputfc):
    pointArray = arcpy.Array()
    totalrows = arcpy.GetCount_management(inputfc)
    print "Points total is {0}".format(int(totalrows.getOutput(0)))

    #Loop through points in FC (points)
    desc = arcpy.Describe(inputfc)
    shapefieldname = desc.ShapeFieldName
    fields = ["SHAPE@"]
    with arcpy.da.SearchCursor(inputfc, fields) as cursor:
        for row in cursor:
        pnt = row[0].getPart()

    pointMultipoint = arcpy.Multipoint(pointArray)
    pointArray.removeAll() #frees up memory
    convexPolygon = pointMultipoint.convexHull()

    #Insert into output featureclass
    insertCursor = arcpy.da.InsertCursor(outputfc, ("SHAPE@"))
    del insertCursor #This actually inserts the row - very important!
    print "Inserted convex polygon"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s