tmontaigu / dbase-rs

Rust library to read & write dBase files.
MIT License
29 stars 30 forks source link

Generated dbf-file not readable #26

Closed michelk closed 2 years ago

michelk commented 2 years ago

I wrote a function to export a triangular mesh to a shapefile.

All files are written (shp, shx, dbf) and the shp-file could be opened with QGIS.

This works, but the dbf-file couldn't be opened:

dbfdump msh.dbf 
DBFOpen(msh.dbf,"r") failed.

Any idea what the problem could be?

EDIT: There is a full example, see below.

Thanks.

michelk commented 2 years ago

I made a reproducible example:

https://github.com/michelk/shapefile-rs/blob/write-polygon-example/examples/write-polygon/src/main.rs

michelk commented 2 years ago

I tried serde_derive, which didn't help.

And it also happens with Polyline-records.

tmontaigu commented 2 years ago

A quick guess without testing but just looking at the code its that you use integer_field which is something for FoxPro2 files so your file .dbf is not purely a dBase file and I think that the shapefile spec implicitely says that the dbf file should be a dBase not FoxPro2 dBase.

Try replace the interger_field with numeric field

michelk commented 2 years ago

Unfortunately, with add_numeric_field I still get

dbfdump _build/testdata_polygon.dbf     
    DBFOpen(_build/testdata_polygon.dbf,"r") failed.
tmontaigu commented 2 years ago

Transfered because its a dbase issue.

I've had a deeper look at this, and the problem is that we did not count the deletion flag field size in the total record size written in the header.

Issue #18 described the same problem

michelk commented 2 years ago

Thanks, now it works :)

tmontaigu commented 2 years ago

Cool, i'll make a release this week as it's an important fix