Opened 11 years ago
Closed 5 years ago
#5146 closed defect (wontfix)
[Shapelib patch] EOF-weirdness when deleting columns in .dbf
Reported by: | berendsen | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | closed_because_of_github_migration |
Component: | default | Version: | 1.9.2 |
Severity: | normal | Keywords: | dbf, columns, delete |
Cc: |
Description
Symptom: When deleting a column in a shapefiles dbf table, it leads to strangeness at the end of the dbf-file. Strangeness is always visible when looking at the file in Excel, but only sometimes in Libreoffice / OOo Calc (seems to be only when having deleted a LOT of columns).
(noticed this when a colleague had problems loading such a file into an propietary ArcGIS 9.x extension)
Steps to reproduce:
- Create shapefile
- Create some random points, lines or polygons
- Create and fill some random columns in the table
- Delete a column
- Check .dbf in Excel
(The attached .zip contains two shapefiles. 'dbf-test' is before the deletion of table column, 'dbf-test-afterdelete' afterwards)
Happens: Always
Observed in version: GDAL/OGR 1.9.2 \ QGIS 1.9.0-326 / Windows (OSGeo4W-installer) GDAL/OGR 1.9.1 \ QGIS 1.8.0-5 / Windows (OSGeo4W-installer) Other systems not tested
Might be related to: RFC35 http://trac.osgeo.org/gdal/ticket/2671, especially the statement: "One downside is that after deletion of a field, the .dbf file is not truncated as there's no hook for truncation. However this doesn't affect overall functionality. "
Workarounds: Use the 'Save layer as' feature in QGIS or ArcGIS 10.
Attachments (3)
Change History (6)
by , 11 years ago
Attachment: | dbf-deletecolumn.zip added |
---|
comment:1 by , 11 years ago
Summary: | EOF-weirdness when deleting columns in .dbf → [Shapelib patch] EOF-weirdness when deleting columns in .dbf |
---|
This issue has been fixed in GDAL 1.10. I've just done a backport in branch/1.9 in case a 1.9.3 is release some day...
branch/1.9 r26134 "Shape: truncate DBF file when removing a column (partial backport of r23972, #5146)"
Frank, I'm attaching a patch to shapelib to implement the truncation in shapelib itself, which is the proper solution (instead of doing it in OGR as currently). Note that I've only implemented the new FTruncate() SAHooks callback in the context of shp_vsi.c. I've not looked at the SASetupDefaultHooks() implementation of shapelib, but it should be extended to implement FTruncate() (inspiration can certainly be taken from GDAL port POSIX and Windows implementations) and to define the ABI version so that SAHooks can be extended someday. After that, the ogrshape_remove_truncatedbf.patch can be applied to remove the OGR hack.
by , 11 years ago
Attachment: | ogrshape_remove_truncatedbf.patch added |
---|
Add a FTruncate callback to SAHooks and use it in DBFDeleteField() and DBFAlterFieldDefn()
by , 11 years ago
Attachment: | ogrshape_remove_truncatedbf.2.patch added |
---|
Remove hack (to be applied after shapelib_truncate.patch)
comment:2 by , 11 years ago
Thanks very much for the quick fix. I don't know whether I'll have time to create a build at work today, so I might have to wait until OSGeo4W/QGIS carries the patch.
comment:3 by , 5 years ago
Milestone: | → closed_because_of_github_migration |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.
Two shapes, 'dbf-test-afterdelete.dbf' shows the problem. Can be created from 'dbf-test' by deleting a column in the table via GDAL/OGR.