Opened 8 years ago

Closed 6 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, 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 8 years ago.
patch for deletion of field in dbf
rfc35.patch (54.8 KB) - added by Even Rouault 6 years ago.
Proposed implementation of RFC35
rfc35_v2.patch (63.8 KB) - added by Even Rouault 6 years ago.
v2 of implementation of rfc35
rfc35_test.py (4.6 KB) - added by Even Rouault 6 years ago.
Example of use of RFC35
rfc35_v3.patch (72.3 KB) - added by Even Rouault 6 years ago.
v3 of implementation of rfc35
shapelib_rfc35.patch (18.9 KB) - added by Even Rouault 6 years ago.
Shapelib part of RFC35 implementation

Download all attachments as: .zip

Change History (21)

Changed 8 years ago by wonder

Attachment: dbf_delete_field.patch added

patch for deletion of field in dbf

comment:1 Changed 8 years ago by wonder

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 Changed 8 years ago by warmerdam

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 Changed 8 years ago by warmerdam

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 Changed 8 years ago by jef

Cc: jef@… added

comment:5 Changed 8 years ago by msieczka

Cc: msieczka added

comment:6 Changed 8 years ago by neteler

Cc: neteler added

comment:7 Changed 8 years ago by gislab

Cc: gislab added

comment:8 Changed 8 years ago by jef

Cc: jef added; jef@… removed

comment:9 Changed 7 years ago by lutra

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

comment:10 Changed 7 years ago by wonder

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 Changed 6 years ago by Stemby

Is there any news?

Carlo

comment:12 Changed 6 years ago by warmerdam

There has been no action.

comment:13 Changed 6 years ago by enrico80

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

Changed 6 years ago by Even Rouault

Attachment: rfc35.patch added

Proposed implementation of RFC35

Changed 6 years ago by Even Rouault

Attachment: rfc35_v2.patch added

v2 of implementation of rfc35

Changed 6 years ago by Even Rouault

Attachment: rfc35_test.py added

Example of use of RFC35

Changed 6 years ago by Even Rouault

Attachment: rfc35_v3.patch added

v3 of implementation of rfc35

Changed 6 years ago by Even Rouault

Attachment: shapelib_rfc35.patch added

Shapelib part of RFC35 implementation

comment:14 Changed 6 years ago by warmerdam

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

comment:15 Changed 6 years ago by Even Rouault

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.