georust / geozero

Zero-Copy reading and writing of geospatial data.
Apache License 2.0
323 stars 30 forks source link

Multiple problems with Shapefile test data #85

Closed twpayne closed 1 year ago

twpayne commented 1 year ago

Thanks for this project. I'm not a Rust user, but I'm writing a Shapefile parser for Go and am testing my code with your testdata. I think some of your example Shapefiles are incorrect, which may in turn be concealing bugs in your code.

I'm using GDAL as a reference implementation. GDAL includes an ogrinfo command that can be used to query Shapefiles:

$ ogrinfo -al geozero-shp/tests/data/point.shp
INFO: Open of `geozero-shp/tests/data/point.shp'
      using driver `ESRI Shapefile' successful.

Layer name: point
Geometry: Point
Feature Count: 1
Extent: (122.000000, 37.000000) - (122.000000, 37.000000)
Layer SRS WKT:
(unknown)
OGRFeature(point):0
  POINT (122 37)

Note that GDAL requires a .shx index file. For many of your test Shapefiles, these do not exist. I've been using this tip to create a .shx file where they are missing.

I believe that the following errors in your test Shapefiles are present:

geozero-shp/tests/data/pointz.shp: bounds in header do not match bounds of data; first record should have record number 1, but has record number 0.

geozero-shp/tests/data/polygon.shp: the polygon is invalid because its rings are not closed.

geozero-shp/tests/data/poly.dbf (note that this in in the .dbf file): the dbf file is missing the \x1a terminator.

pka commented 1 year ago

Hi Tom, nice to meet you again in GeoRust land :-) I took these test files from https://github.com/tmontaigu/shapefile-rs, but GDAL would probably have better shapefiles for testing. In general, there would be a lot to improve in the shapefile driver, but since I use shapfiles so rarely these days, my personal priority is very low.