Changes between Initial Version and Version 1 of rfc35_deletereorderalterfielddefn


Ignore:
Timestamp:
May 7, 2011, 10:02:41 AM (13 years ago)
Author:
Even Rouault
Comment:

Add RFC35

Legend:

Unmodified
Added
Removed
Modified
  • rfc35_deletereorderalterfielddefn

    v1 v1  
     1= RFC 35: Delete, reorder and alter field definitions of OGR layers =
     2
     3Authors: Even Rouault[[BR]]
     4Contact: even dot rouault at mines dash paris dot org[[BR]]
     5Status: Developement
     6
     7== Summary ==
     8
     9This document proposes changes in OGR to add the capability to delete fields, reorder fields
     10and alter field definitions, in OGR layer definitions.
     11
     12== Rationale ==
     13
     14Currently, an OGR layer definition can only be altered to add a new field definition with OGRLayer::CreateField().
     15
     16It is desirable to extend those capabilities to be able to delete, reorder and alter field
     17definitions of existing layers. Such wish has been expressed in ticket #2671 and comes back regularly
     18on QGIS mailing list (e.g. http://lists.osgeo.org/pipermail/qgis-user/2011-May/011935.html).
     19QGIS currently has a "Table Manager" to work around the lack of DeleteField(), so a proper solution is
     20clearly needed.
     21
     22== Planned Changes ==
     23
     24The OGRLayer class will be extended with the following methods :
     25{{{
     26    virtual OGRErr      DeleteField( int iField );
     27    virtual OGRErr      ReorderField( int iOldFieldPos, int iNewFieldPos );
     28    virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
     29}}}
     30
     31The documentation of those new methods is :
     32{{{
     33
     34/**
     35\fn OGRErr OGRLayer::DeleteField( int iField );
     36
     37\brief Delete an existing field on a layer.
     38
     39You must use this to delete existing fields
     40on a real layer. Internally the OGRFeatureDefn for the layer will be updated
     41to reflect the deleted field.  Applications should never modify the OGRFeatureDefn
     42used by a layer directly.
     43
     44This function should not be called while there are feature objects in existance that
     45were obtained or created with the previous layer definition.
     46
     47Not all drivers support this method. You can query a layer to check if it supports it
     48with the OLCDeleteField capability. Some drivers may only support this method while
     49there are still no features in the layer. When it is supported, the existings features of the
     50backing file/database should be updated accordingly.
     51
     52This function is the same as the C function OGR_L_DeleteField().
     53
     54@param iField index of the field to delete.
     55
     56@return OGRERR_NONE on success.
     57
     58@since OGR 1.9.0
     59*/
     60
     61/**
     62\fn OGRErr OGRLayer::ReorderField( int iOldFieldPos, int iNewFieldPos );
     63
     64\brief Reorder an existing field on a layer.
     65
     66You must use this to reorder existing fields
     67on a real layer. Internally the OGRFeatureDefn for the layer will be updated
     68to reflect the reordering of the fields.  Applications should never modify the OGRFeatureDefn
     69used by a layer directly.
     70
     71This function should not be called while there are feature objects in existance that
     72were obtained or created with the previous layer definition.
     73
     74Not all drivers support this method. You can query a layer to check if it supports it
     75with the OLCReorderField capability. Some drivers may only support this method while
     76there are still no features in the layer. When it is supported, the existings features of the
     77backing file/database should be updated accordingly.
     78
     79This function is the same as the C function OGR_L_ReorderField().
     80
     81@param iOldFieldPos previous position of the field to move.
     82@param iNewFieldPos new position of the field to move.
     83
     84@return OGRERR_NONE on success.
     85
     86@since OGR 1.9.0
     87*/
     88
     89/**
     90\fn OGRErr OGRLayer::AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
     91
     92\brief Alter the definition of an existing field on a layer.
     93
     94You must use this to alter the definition of an existing field of a real layer.
     95Internally the OGRFeatureDefn for the layer will be updated
     96to reflect the altered field.  Applications should never modify the OGRFeatureDefn
     97used by a layer directly.
     98
     99This function should not be called while there are feature objects in existance that
     100were obtained or created with the previous layer definition.
     101
     102Not all drivers support this method. You can query a layer to check if it supports it
     103with the OLCAlterFieldDefn capability. Some drivers may only support this method while
     104there are still no features in the layer. When it is supported, the existings features of the
     105backing file/database should be updated accordingly. Some drivers might also not support
     106all update flags.
     107
     108This function is the same as the C function OGR_L_AlterFieldDefn().
     109
     110@param iField index of the field whose definition must be altered.
     111@param poNewFieldDefn new field definition
     112@param nFlags combination of ALTER_NAME_FLAG, ALTER_TYPE_FLAG and ALTER_WIDTH_PRECISION_FLAG
     113to indicate which of the name and/or type and/or width and precision fields from the new field
     114definition must be taken into account.
     115
     116@return OGRERR_NONE on success.
     117
     118@since OGR 1.9.0
     119*/
     120}}}
     121
     122Three new layer capabilities are added :
     123{{{
     124OLCDeleteField / "DeleteField": TRUE if this layer can delete
     125existing fields on the current layer using DeleteField(), otherwise FALSE.
     126
     127OLCReorderField / "ReorderField": TRUE if this layer can reorder
     128existing fields on the current layer using ReorderField(), otherwise FALSE.
     129
     130OLCAlterFieldDefn / "AlterFieldDefn": TRUE if this layer can alter
     131the definition of an existing field on the current layer using AlterFieldDefn(), otherwise FALSE.
     132}}}
     133
     134
     135The new methods are mapped to the C API :
     136{{{
     137OGRErr CPL_DLL OGR_L_DeleteField( OGRLayerH, int iField );
     138OGRErr CPL_DLL OGR_L_ReorderField( OGRLayerH, int iOldFieldPos, int iNewFieldPos );
     139OGRErr CPL_DLL OGR_L_AlterFieldDefn( OGRLayerH, int iField, OGRFieldDefnH hNewFieldDefn, int nFlags );
     140}}}
     141
     142For the purpose of the implementation, new methods are also added to the OGRFeatureDefn class :
     143{{{
     144    OGRErr      DeleteFieldDefn( int iField );
     145    OGRErr      ReorderFieldDefn( int iOldFieldPos, int iNewFieldPos );
     146}}}
     147
     148== Compatibility Issues ==
     149
     150None
     151
     152== Changed drivers ==
     153
     154The shapefile driver will implement DeleteField(), ReorderField() and AlterFieldDefn(). Shapelib will be
     155extended with DBFReorderField() and DBFAlterFieldDefn().
     156
     157Note: The implementation of AlterFieldDefn() in the Shapefile driver does not currently support altering
     158the field type, and will not reformat numeric values of existing features if width or precision are changed.
     159However, appropriate field truncation or expansion will occur if the width is altered.
     160
     161Other drivers, mainly database drivers (PG, MySQL, SQLite), could be easily extented to implement the new API
     162by issuing the appropriate SQL command (DROP COLUMN, ALTER TABLE foo ALTER COLUMN bar, ...).
     163The implementation of DeleteField() and AlterFieldDefn() in the PG driver is indeed planned,
     164provided this RFC is adopted.
     165
     166== SWIG bindings ==
     167
     168DeleteField(), ReorderField() and AlterFieldDefn() will be mapped to SWIG.
     169
     170== Test Suite ==
     171
     172The autotest suite will be extended to test the implementation of the new API for the Shapefile driver. An example
     173of the use of the new API is attached to ticket #2671 (rfc35_test.py) and will be turned into unit tests.
     174
     175== Implementation ==
     176
     177Implementation will be done by Even Rouault in GDAL/OGR trunk. Changes in Shapelib will need to be
     178pushed into upstream CVS by a Shapelib committer. The proposed implementation is attached as
     179a patch in ticket #2671 (rfc35.patch).