Skip to content

Commit

Permalink
Shapefile reader: fix spurious warning when reading polygons (ammends…
Browse files Browse the repository at this point in the history
… fix of OSGeo#8483, fixes OSGeo#8767)
  • Loading branch information
rouault authored and ralphraul committed Mar 11, 2024
1 parent b9e78cb commit dec5183
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions autotest/ogr/data/shp/cb_2022_us_county_20m_extract.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions autotest/ogr/ogr_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,16 @@ def test_ogr_shape_read_multipolygon_as_invalid_polygon():
)


def test_ogr_shape_read_multipolygon_as_invalid_polygon_no_warning():

ds = ogr.Open("data/shp/cb_2022_us_county_20m_extract.shp")
lyr = ds.GetLayer(0)
gdal.ErrorReset()
with gdal.quiet_errors():
lyr.GetNextFeature()
assert gdal.GetLastErrorMsg() == ""


###############################################################################
# Test alternate date formatting (#2746)

Expand Down
9 changes: 5 additions & 4 deletions ogr/ogrsf_frmts/shape/shape2ogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ OGRGeometry *SHPReadOGRObject(SHPHandle hSHP, int iShape, SHPObject *psShape,
// Only inner rings
OGREnvelope sFirstEnvelope;
OGREnvelope sCurEnvelope;
auto poExteriorRing = tabPolygons[0]->getExteriorRing();
tabPolygons[0]->getEnvelope(&sFirstEnvelope);
for (int iRing = 1; iRing < psShape->nParts; iRing++)
{
Expand Down Expand Up @@ -406,10 +407,10 @@ OGRGeometry *SHPReadOGRObject(SHPHandle hSHP, int iShape, SHPObject *psShape,
topPoint = p;
}
}
if (!poRing->isPointInRing(&leftPoint) &&
!poRing->isPointInRing(&rightPoint) &&
!poRing->isPointInRing(&bottomPoint) &&
!poRing->isPointInRing(&topPoint))
if (!poExteriorRing->isPointInRing(&leftPoint) &&
!poExteriorRing->isPointInRing(&rightPoint) &&
!poExteriorRing->isPointInRing(&bottomPoint) &&
!poExteriorRing->isPointInRing(&topPoint))
{
bUseSlowMethod = true;
break;
Expand Down

0 comments on commit dec5183

Please sign in to comment.