Changes between Version 1 and Version 2 of rfc29_desired_fields
- Timestamp:
- Jul 29, 2010, 1:22:18 AM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
rfc29_desired_fields
v1 v2 1 = RFC 29: OGR Set Desired Fields =1 = RFC 29: OGR Set Ignored Fields = 2 2 3 3 Author: Martin Dobias[[BR]] … … 7 7 == Summary == 8 8 9 To improve performance when fetching features, this RFC proposes a way how to tell OGR which fields are going to be required in subsequent GetFeature() / GetNextFeature() calls. Knowing the necessary fields, the OGR driver can decide to leave the rest of the fields null. 9 To improve performance when fetching features, this RFC proposes a way how to tell OGR which fields are going to be required in subsequent GetFeature() / GetNextFeature() calls. Knowing the necessary fields, the OGR driver can decide to leave the rest of the fields null. 10 10 11 11 == Details == 12 12 13 A new (non-virtual) function should be added to OGRLayer class to allow the client to set which fields willbe fetched:13 A new function will be added to OGRLayer class to allow the client to set which fields will *not* be fetched: 14 14 15 15 {{{ 16 v oid SetDesiredFields(int nNumFields, int* pabFields);16 virtual OGRErr OGRLayer::SetIgnoredFields( const char **papszFields ); 17 17 }}} 18 18 … … 20 20 21 21 {{{ 22 void CPL_DLL OGR_L_SetDesiredFields( OGRLayerH, int, int*);22 OGRErr CPL_DLL OGR_L_SetIgnoredFields( OGRLayerH, const char **papszFields ); 23 23 }}} 24 24 25 The parameter "pabFields" is an array of booleans, each item specifies whether the field with the same index should be fetched. The length of the array is specified in "nNumFields" parameter and typically it should be the same as the actual number of fields. The SetDesiredFields() function makes a copy of both nNumFields and pabFields (these have to be stored as class member variables of OGRLayer: nDesiredNumFields, pabDesiredFields).26 25 27 The parameter "nNumFields" is a bit redundant, but it keeps things safe in case some fields are later added so that there is not access beyond the allocated memory of the array. 26 The argument is a list of fields to be ignored, by name, and the special field names "OGR_GEOMETRY" and "OGR_STYLE" will 27 be interpreted to refer to the geometry and style values of a feature. 28 28 29 The semantics is as follows: if nNumFields < 0, all fields will be fetched. Otherwise the pabFields array will be copied to an internal one within OGRLayer and only the fields having non-zero value in that array will be fetched. 29 Passing by field name has been chosen so that we could handle OGR_GEOMETRY, OGR_STYLE and possibly some other special 30 fields in the future. Instead of specifying "desired" fields, it has been decided to specify "ignored" fields 31 so that we wouldn't accidentally drop things like geometry and style just because they weren't explicitly 32 listed in a desired list. 30 33 31 The implementation of fetching in drivers will usually require only small adjustment, e.g.: 34 Passing NULL for papszFields will clear the ignored list. 35 36 The method will return OGRERR_NONE as long as all the field names are able to be resolved, even if the method does not 37 support selection of fields. 38 39 The method will be implemented at the level of OGRLayer class: it will resolve indexes of the fields and set the following new member variables which indicate what should be ignored: 40 {{{m_pabIgnoredFields}}}, {{{m_bIgnoreGeometry}}}, {{{m_bIgnoreStyle}}}. 41 42 Optionally the method can be overridden in driver implementation if the driver has some special needs. 43 44 == Implementation in drivers == 45 46 The implementation of drivers will require small adjustments in order to support this RFC. Drivers not making use of this addition will simply continue to fetch also fields/geometry/style that are not requested by the caller. 47 48 The adjustments in driver implementation will look as follows: 32 49 33 50 {{{ 51 if (!m_bIgnoreGeometry) 52 { 53 // fetch geometry 54 } 55 if (!m_bIgnoreStyle) 56 { 57 // fetch style 58 } 59 34 60 for( int iField = 0; iField < poDefn->GetFieldCount(); iField++ ) 35 61 { 36 if ( nDesiredNumFields >= 0 && iField < nDesiredNumFields && !pabDesiredFields[iField])62 if (m_pabIgnoredFields && iField < m_nIgnoredFieldCount && m_pabIgnoredFields[iField]) 37 63 continue; 38 64 … … 41 67 }}} 42 68 69 43 70 == Compatibility == 44 71 45 This change is fully backwards compatible: OGR will continue to fetch all fields by default. Only applications using the proposed new API will experience new behavior.72 This change is fully backwards compatible: OGR will continue to fetch geometry, style and all fields by default. Only applications using the proposed API will experience the new behavior. 46 73 47 There is no need to modify all existing drivers. Drivers that do not consider the desired fields will stillfetch all attributes as before.74 Initially, only some drivers (Shapefile and few others) will implement this RFC. There is no need to modify all existing drivers when adopting the RFC - drivers that do not consider the ignored fields will simply fetch all attributes as before. 48 75 76 ogr2ogr command line tool will make use of this RFC in cases it receives -select argument with a list of required fields. Other than the specified fields will be ignored.