Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shapefile reader: fix spurious warning when reading polygons (ammends fix of #8483, fixes #8767) #8769

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 0 additions & 1 deletion port/cpl_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ char **CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols,
int nLines = 0;
int nAllocatedLines = 0;

CPLErrorReset();
while (!VSIFEofL(fp) && (nMaxLines == -1 || nLines < nMaxLines))
{
const char *pszLine = CPLReadLine2L(fp, nMaxCols, papszOptions);
Expand Down
Loading