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: error out on valid .sbn file #9430

Closed
pathmapper opened this issue Mar 9, 2024 · 3 comments
Closed

Shapefile: error out on valid .sbn file #9430

pathmapper opened this issue Mar 9, 2024 · 3 comments
Assignees
Labels

Comments

@pathmapper
Copy link
Contributor

pathmapper commented Mar 9, 2024

Feature description

Here's a dataset (Shapefile with spatial index .sbn / .sbx) for which ogrinfo with spatial filter returns:

ERROR 1: Inconsistent shape count for bin
SHAPE: Used spatial index, got 0 matches.
Feature Count: 13

Looks like shapelib detects an error regarding the spatial index and in consequence the spatial index is not used but the matching features could still be found (the normal way without spatial index).

Suggestion is here to improve the ogrinfo output to make it more clear what's going on.

ogrinfo -ro -so -spat 5 5 6 6 glwd_2.shp --debug on
Shape: DBF Codepage = LDID/87 for glwd_2.shp
Shape: Treating as encoding 'ISO-8859-1'.
GDAL: GDALOpen(glwd_2.shp, this=0x55765f5e0090) succeeds as ESRI Shapefile.
INFO: Open of `glwd_2.shp'
      using driver `ESRI Shapefile' successful.
OGR: GetLayerCount() = 1


Layer name: glwd_2
Metadata:
  DBF_DATE_LAST_UPDATE=2003-05-20
Geometry: Polygon
ERROR 1: Inconsistent shape count for bin
SHAPE: Used spatial index, got 0 matches.
Feature Count: 13
Extent: (-180.000000, -55.587208) - (180.000000, 83.575951)
Layer SRS WKT:
(unknown)
GLWD_ID: Integer64 (10.0)
TYPE: String (12.0)
POLY_SRC: String (12.0)
AREA_SKM: Real (12.1)
PERIM_KM: Real (12.1)
LONG_DEG: Real (10.2)
LAT_DEG: Real (10.2)
GDAL: GDALClose(glwd_2.shp, this=0x55765f5e0090)

Additional context

It's kind of surprising that for this well established dataset such an error is detected -> OSGeo/shapelib#106

@pathmapper pathmapper changed the title gdalinfo / shapefile - make it more clear what happens if the spatial index is corrupt ogrinfo / shapefile - make it more clear what happens if the spatial index is corrupt Mar 9, 2024
@rouault rouault added bug and removed enhancement labels Mar 10, 2024
@rouault rouault self-assigned this Mar 10, 2024
rouault added a commit to rouault/shapelib that referenced this issue Mar 10, 2024
rouault added a commit to rouault/gdal that referenced this issue Mar 10, 2024
@rouault rouault changed the title ogrinfo / shapefile - make it more clear what happens if the spatial index is corrupt Shapefile: error out on valid .sbn file Mar 10, 2024
@rouault
Copy link
Member

rouault commented Mar 10, 2024

It's kind of surprising that for this well established dataset such an error is detected

That was actually a fundamental algorithmic bug that has existed forever based on a wrong assumption about the ordering of some elements in the .sbn. I guess most .sbn in the wild met our wrong assumption, but for larger datasets like the one of this ticket, it could be defeated

rouault added a commit to rouault/gdal that referenced this issue Mar 10, 2024
rouault added a commit to rouault/shapelib that referenced this issue Mar 10, 2024
@pathmapper
Copy link
Contributor Author

Thank you @rouault, this thing really tested my patience. You can't imagine how happy I am with the outcome.

rouault added a commit to rouault/shapelib that referenced this issue Mar 10, 2024
rouault added a commit to rouault/shapelib that referenced this issue Mar 10, 2024
rouault added a commit to rouault/gdal that referenced this issue Mar 10, 2024
rouault added a commit to rouault/gdal that referenced this issue Mar 10, 2024
rouault added a commit to rouault/shapelib that referenced this issue Mar 15, 2024
@pathmapper
Copy link
Contributor Author

fixed by @rouault in #9439

rouault added a commit to rouault/gdal that referenced this issue Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants