1

I am trying to use the geometry method to calculate the convex hull around two polygons (polyA, polyB) with the following code:

# Union both polygons to one (multipart) polygon:
polyAB = polyA.union(polyB)
# Calculating the convex hull around polyAB:
convexhullAB = polyAB.convexHull()

To check if it is working I am writing the combined polygon (polyAB) and the convex hull (convexhullAB) to a shapefile:

cur_poly = arcpy.da.InsertCursor("polyAB.shp", ["SHAPE@"])
cur_poly.insertRow((polyAB,))
cur_convex = arcpy.da.InsertCursor("convex.shp", ["SHAPE@"])
cur_convex.insertRow((convexhullAB,))

The shapefile polyAB.shp contains the (correct) polygon, but convex.shp is empty. Has anyone an idea what went wrong?

4
  • 2
    At the moment the code that you have presented seems insufficient to qualify as a code snippet. I suggest you bolster it by using code to build your polyA and polyB (two rectangles is all you need) at the start of it, and then to include pictures of inputs and expected/observed outputs.
    – PolyGeo
    Commented Oct 11, 2016 at 21:29
  • 1
    Your code with proper geometries is working just fine. I suspect you may have empty geometries. There are a couple of diagnostics that I can offer. Just after convexhullAB = polyAB.convexHull(), try convexhullAB.getPart(). If it gives you array of coordinates (expecting to see more than 3 coordinates), that means you have your convex hull. Lastly, try arcpy.CopyFeatures_management(convexhullAB, "convex_text.shp"), if it creates a shapefile, then it means your geometry has no issues.
    – fatih_dur
    Commented Oct 12, 2016 at 0:20
  • If you don't include polygon vertex arrays which exhibit the behavior, you can't clear the reproducibility hurdle necessary to make this answerable.
    – Vince
    Commented Oct 12, 2016 at 3:45
  • Please edit your question to include a reproducible code snippet as requested by PolyGeo and Vince.
    – Midavalo
    Commented Oct 12, 2016 at 5:08

0

Browse other questions tagged or ask your own question.