bixb0012

Check Geometry Fails in Shared-Origin Edge Case

Discussion created by bixb0012 Champion on Dec 1, 2019
Latest reply on Dec 23, 2019 by bixb0012

In the Hole lies outside shell and arcpy thread, the OP had geometries that were invalid but Esri tools were failing to detect them as such.  After some investigation, I discovered a shared-origin edge case where the Check Geometry will fail to detect an invalid geometry.

 

The following is a simplified example of the OP's geometries from the Hole lies outside shell and arcpy  thread.

 

In the example above, polygon a is valid while polygon b is invalid because of "hole" lies outside of the bounding geometry.  When run through Check Geometry, it will identify polygon b as invalid.  When the two parts are combined into a two-part multi-polygon, the Check Geometry tools fails to identify the polygon as invalid even though one of the two parts is invalid.

 

The following code creates a feature class containing three polygons (a, b, and ab), and then checks the geometry of all three:

import arcpy

SR = arcpy.SpatialReference(4326)
polys = {
    "a":("MULTIPOLYGON(((10 5, 10 10, 0 10, 0 0, 10 0, 10 5)))"),
    "b":("MULTIPOLYGON(((10 5, 15 0, 20 5, 15 10, 10 5),(10 5, 7.5 2.5, 5 5, 7.5 7.5, 10 5)))"),
    "ab":("MULTIPOLYGON(((10 5, 10 10, 0 10, 0 0, 10 0, 10 5)),"
                        "((10 5, 15 0, 20 5, 15 10, 10 5),(10 5, 7.5 2.5, 5 5, 7.5 7.5, 10 5)))")
}

fc = arcpy.CopyFeatures_management(
    [arcpy.FromWKT(polys[p], SR) for p in polys],
    arcpy.CreateScratchName(workspace="memory")
)
chkGeom = arcpy.CheckGeometry_management(fc, arcpy.CreateScratchName(workspace="memory"))
print(*arcpy.da.SearchCursor(chkGeom, ["FEATURE_ID","PROBLEM"]), sep="\n")

 

The result is that just one of the three polygons is identified as invalid:

>>> print(*arcpy.da.SearchCursor(chkGeom, ["FEATURE_ID","PROBLEM"]), sep="\n")
(2, 'incorrect ring ordering')
>>>

Since the third polygon is a combined polygon, it should also be identified as invalid.

Outcomes