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

Spurious warnings when reading shapefiles #8767

Closed
dopplershift opened this issue Nov 21, 2023 · 0 comments
Closed

Spurious warnings when reading shapefiles #8767

dopplershift opened this issue Nov 21, 2023 · 0 comments
Assignees

Comments

@dopplershift
Copy link

With GDAL >=3.7.3, I'm seeing the following when loading any of the US Census Bureau county borders files, for instance the 1:20m file:

Warning 1: us_counties_20m.shp contains polygon(s) with rings with invalid winding order. Autocorrecting them, but that shapefile should be corrected using ogr2ogr for example.

This warning came in with #8483, but for all I can tell, there's nothing wrong with the geometry in that file (ids 1524 and 1973 in the 1:20m file at least). Looking at the relevant code:

for (int iRing = 1; iRing < psShape->nParts; iRing++)
{
tabPolygons[iRing]->getEnvelope(&sCurEnvelope);
if (!sFirstEnvelope.Intersects(sCurEnvelope))
{
// If the envelopes of the rings don't intersect,
// then it is clearly a multi-part polygon
bUseSlowMethod = true;
break;
}
else
{
// Otherwise take 4 points at each extremity of
// the inner rings and check if there are in the
// outer ring. If none are within it, then it is
// very likely a outer ring (or an invalid ring
// which is neither a outer nor a inner ring)
auto poRing = tabPolygons[iRing]->getExteriorRing();
const auto nNumPoints = poRing->getNumPoints();
OGRPoint p;
OGRPoint leftPoint(
std::numeric_limits<double>::infinity(), 0);
OGRPoint rightPoint(
-std::numeric_limits<double>::infinity(), 0);
OGRPoint bottomPoint(
0, std::numeric_limits<double>::infinity());
OGRPoint topPoint(
0, -std::numeric_limits<double>::infinity());
for (int iPoint = 0; iPoint < nNumPoints - 1;
++iPoint)
{
poRing->getPoint(iPoint, &p);
if (p.getX() < leftPoint.getX() ||
(p.getX() == leftPoint.getX() &&
p.getY() < leftPoint.getY()))
{
leftPoint = p;
}
if (p.getX() > rightPoint.getX() ||
(p.getX() == rightPoint.getX() &&
p.getY() > rightPoint.getY()))
{
rightPoint = p;
}
if (p.getY() < bottomPoint.getY() ||
(p.getY() == bottomPoint.getY() &&
p.getX() > bottomPoint.getX()))
{
bottomPoint = p;
}
if (p.getY() > topPoint.getY() ||
(p.getY() == topPoint.getY() &&
p.getX() < topPoint.getX()))
{
topPoint = p;
}
}
if (!poRing->isPointInRing(&leftPoint) &&
!poRing->isPointInRing(&rightPoint) &&
!poRing->isPointInRing(&bottomPoint) &&
!poRing->isPointInRing(&topPoint))
{
bUseSlowMethod = true;
break;
}
}
}

it says it's checking that points are in the "exterior ring", but near as I can tell the polygons in tabPolygons are all individual rings, so the exterior ring of any of those is polygons is itself. Is perhaps the correct line instead:

auto poRing = tabPolygons[0]->getExteriorRing();

? Otherwise, am I missing something here as to why the warning is actually correct?

@rouault rouault self-assigned this Nov 21, 2023
rouault added a commit that referenced this issue Nov 21, 2023
Shapefile reader: fix spurious warning when reading polygons (ammends fix of #8483, fixes #8767)
rouault added a commit that referenced this issue Nov 22, 2023
[Backport release/3.8] Shapefile reader: fix spurious warning when reading polygons (ammends fix of #8483, fixes #8767)
ralphraul pushed a commit to 1SpatialGroupLtd/gdal that referenced this issue Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants