Opened 15 years ago

Closed 13 years ago

#2671 closed enhancement (fixed)

[PATCH] delete fields in .dbf

Reported by: wonder Owned by: warmerdam
Priority: normal Milestone: 1.9.0
Component: OGR_SF Version: svn-trunk
Severity: normal Keywords: shape
Cc: jef, msieczka, Markus Neteler, gislab

Description

I've developed a patch to allow deletion of fields in an existing DBF file. It's done by overwriting header and moving records in DBF file (without creating a new temporary file).

The patch adds new C++ function OGRLayer::DeleteField(int field) and C API equivalent OGR_L_DeleteField.

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.

Attachments (6)

dbf_delete_field.patch (9.0 KB ) - added by wonder 15 years ago.
patch for deletion of field in dbf
rfc35.patch (54.8 KB ) - added by Even Rouault 13 years ago.
Proposed implementation of RFC35
rfc35_v2.patch (63.8 KB ) - added by Even Rouault 13 years ago.
v2 of implementation of rfc35
rfc35_test.py (4.6 KB ) - added by Even Rouault 13 years ago.
Example of use of RFC35
rfc35_v3.patch (72.3 KB ) - added by Even Rouault 13 years ago.
v3 of implementation of rfc35
shapelib_rfc35.patch (18.9 KB ) - added by Even Rouault 13 years ago.
Shapelib part of RFC35 implementation

Download all attachments as: .zip

Change History (21)

by wonder, 15 years ago

Attachment: dbf_delete_field.patch added

patch for deletion of field in dbf

comment:1 by wonder, 15 years ago

Btw. if you like the patch I'm willing to create another one to support adding fields to existing DBF files in similar way as deletion is done.

Martin

comment:2 by warmerdam, 15 years ago

Component: defaultOGR_SF
Keywords: shape added
Status: newassigned

Martin,

Adding a DeleteField() method for OGRLayer's would require an RFC voted on by the GDAL PSC. I'm personally a bit leery about it, but if it were pursued I think it might be best approached as part of more general manipulation of the field list (reordering, modifying type).

Also, it is too late for such capabilities in GDAL/OGR 1.6, now in beta.

I would be very receiptive to an implementation of CreateField() on existing .dbf files which could be incorporated if available in time for 1.6.0 beta2.

comment:3 by warmerdam, 15 years ago

I have applied the portion of the patch that adds DBFDeleteField() upstream in shapelib. This can be valuable to some people even if OGR does not support deleting fields.

comment:4 by jef, 15 years ago

Cc: jef@… added

comment:5 by msieczka, 15 years ago

Cc: msieczka added

comment:6 by Markus Neteler, 15 years ago

Cc: Markus Neteler added

comment:7 by gislab, 15 years ago

Cc: gislab added

comment:8 by jef, 15 years ago

Cc: jef added; jef@… removed

comment:9 by lutra, 14 years ago

Any chance to see this applied in the next gdal/ogr release?

comment:10 by wonder, 14 years ago

Frank,

can we try to resolve this ticket to get this functionality into next release (1.8 I guess)? I'm willing to create an RFC, however I'd like to skip the general manipulation as you've proposed and I'd ask only for DeleteField method. Basically the reordering and modifying types of attributes aren't really much requested features and would increase the scope of work significantly.

Martin

comment:11 by Stemby, 13 years ago

Is there any news?

Carlo

comment:12 by warmerdam, 13 years ago

There has been no action.

comment:13 by enrico80, 13 years ago

this is a very useful function, when will it implement?

by Even Rouault, 13 years ago

Attachment: rfc35.patch added

Proposed implementation of RFC35

by Even Rouault, 13 years ago

Attachment: rfc35_v2.patch added

v2 of implementation of rfc35

by Even Rouault, 13 years ago

Attachment: rfc35_test.py added

Example of use of RFC35

by Even Rouault, 13 years ago

Attachment: rfc35_v3.patch added

v3 of implementation of rfc35

by Even Rouault, 13 years ago

Attachment: shapelib_rfc35.patch added

Shapelib part of RFC35 implementation

comment:14 by warmerdam, 13 years ago

Shapelib patched as suggested, and results brought back downstream into GDAL trunk (r22367).

comment:15 by Even Rouault, 13 years ago

Milestone: 1.9.0
Resolution: fixed
Status: assignedclosed

r22368 /trunk/gdal/ogr/ (9 files in 3 dirs): RFC35 : core of implementation (#2671)

r22369 /trunk/gdal/ogr/ogrsf_frmts/ (6 files in 3 dirs): RFC35 : implementation in Shapefile, Memory and PG drivers (#2671)

r22370 /trunk/gdal/swig/ (4 files in 4 dirs): RFC35: SWIG bindings (#2671)

r22371 /trunk/autotest/ogr/ (ogr_pg.py ogr_rfc35_mem.py ogr_rfc35_shape.py): RFC35: autotest for implementation in Shapefile, Memory and PG drivers (#2671)

Note: See TracTickets for help on using tickets.