I have a layer of parcels where some "parcel-itos" are inside larger "container" polygons, but these parcelitos are inside holes of the containers (e.g. they do not overlap, but they do touch). Both parcelitos and containers are in the same feature class. I would like to be able to relate the parcelitos' IDs to their containers' IDs. This is what I've tried:

inside = <Polygon object of Parcelito>
outside = <Polygon object of Container>

outside.contains(inside, 'BOUNDARY') #returns false
inside.within(outside, 'BOUNDARY') #returns false

From what I could glean on ESRI's info for Polygon Objects and Methods, it seems like specifying 'BOUNDARY' should have made both of the tests above return True. I don't want to use inside.touches(outside) because the iterative process that contains this test would also pick up the parcels surrounding the container polygon, and I don't care about those relationships.

Any idea of what's going on with these polygon object methods?

  • 1
    No, this is not a trivial operator problem. Holes (interior rings) are part of the topological relationship, and therefore are not part of polygon, so you cannot simply test for contains/within. Instead you need to tear apart the geometry, either capturing only interior or only exterior rings, and fashion a new geometry for comparison.
    – Vince
    Commented Feb 10, 2018 at 0:47
  • @Vince I took your suggestion to heart and tried to compare the exterior ring of the container to the parcelito, but still to no avail. I did this by defining poly = arcpy.Polygon(outside.boundary().getPart(0)) and then testing poly.contains(inside), which returned False. Any suggestions about how to approach this differently?
    – jesnes
    Commented Feb 12, 2018 at 15:34
  • 1
    Sorry, I meant to get back to this, but 12 hour days can put a crimp in a schedule. For the record, always use a SpatialReference in Geometry constructors. The default X/Y precision is 0.001, which will mangle WGS84 data.
    – Vince
    Commented Feb 13, 2018 at 3:37
  • 1
    Also, topology operators always fail when comparing objects which do not share an identical spatial reference.
    – Vince
    Commented Feb 13, 2018 at 4:03

1 Answer 1


Below are two polygons, one with an island and one cookie cutter in the island. You can get the contains true by using the extent object of the bigger island, or use the boundary/part option to create a new polygon to get the exact outside boundary. To get the second option to work, you need to specify the spatial reference.

poly1 = arcpy.AsShape('{"rings":[[[379273.37069999985,3192707.9048999995],[385211.39169999957,3176048.4570000004],[368964.30640000012,3166234.2278000005],[355108.92389999982,3179264.8850999996],[361954.1425999999,3190646.0921],[379273.37069999985,3192707.9048999995]],[[363356.17540000007,3184708.0710000005],[364428.3180999998,3180501.9727999996],[369789.03149999958,3182893.6756999996],[368304.5262000002,3186769.8838999998],[363356.17540000007,3184708.0710000005]]],"spatialReference":{"wkid":26917,"latestWkid":26917}}',True)
poly2 = arcpy.AsShape('{"rings":[[[363356.17540000007,3184708.0710000005],[368304.5262000002,3186769.8838999998],[369789.03149999958,3182893.6756999996],[364428.3180999998,3180501.9727999996],[363356.17540000007,3184708.0710000005]]],"spatialReference":{"wkid":26917,"latestWkid":26917}}',True)
poly1.contains(poly2) #False
poly1.extent.contains(poly2) #True
poly3 = arcpy.Polygon(poly1.boundary().getPart(0),poly1.spatialReference)
poly3.contains(poly2) #True

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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