| 1 | = RFC 50: OGR field subtypes = |
| 2 | |
| 3 | Author: Even Rouault[[BR]] |
| 4 | Contact: even dot rouault at spatialys dot com[[BR]] |
| 5 | Status: In development |
| 6 | |
| 7 | == Summary == |
| 8 | |
| 9 | This RFC aims at adding the capability of specifying sub-types to OGR fields, |
| 10 | like boolean, 16 bit integers or 32 bit floating point values. |
| 11 | The sub-type of a field definition is an additional |
| 12 | attribute that specifies a hint or a restriction to the main type. The subtype |
| 13 | can be used by applications and drivers that know how to handle it, and |
| 14 | can generally be safely ignored by applications and drivers that do not. |
| 15 | |
| 16 | == Core changes == |
| 17 | |
| 18 | === Field subtypes === |
| 19 | |
| 20 | The OGRFieldSubType enumeration is added : |
| 21 | |
| 22 | {{{ |
| 23 | /** |
| 24 | * List of field subtypes. A subtype represents a hint, a restriction of the |
| 25 | * main type, that is not strictly necessary to consult. |
| 26 | * This list is likely to be extended in the |
| 27 | * future ... avoid coding applications based on the assumption that all |
| 28 | * field types can be known. |
| 29 | * Most subtypes only make sense for a restricted set of main types. |
| 30 | * @since GDAL 2.0 |
| 31 | */ |
| 32 | typedef enum |
| 33 | { |
| 34 | /** No subtype. This is the default value */ OFSTNone = 0, |
| 35 | /** Boolean integer. Only valid for OFTInteger and OFTIntegerList.*/ |
| 36 | OFSTBoolean = 1, |
| 37 | /** Signed 16-bit integer. Only valid for OFTInteger and OFTIntegerList. */ |
| 38 | OFSTInt16 = 2, |
| 39 | /** Single precision (32 bit) floatint point. Only valid for OFTReal and OFTRealList. */ |
| 40 | OFSTFloat32 = 3, |
| 41 | OFSTMaxSubType = 3 |
| 42 | } OGRFieldSubType; |
| 43 | }}} |
| 44 | |
| 45 | |
| 46 | === New attributes and methods === |
| 47 | |
| 48 | * In OGRFieldDefn class : |
| 49 | {{{ |
| 50 | OGRFieldSubType eSubType; |
| 51 | |
| 52 | OGRFieldSubType GetSubType() { return eSubType; } |
| 53 | void SetSubType( OGRFieldSubType eSubTypeIn ); |
| 54 | static const char *GetFieldSubTypeName( OGRFieldSubType ); |
| 55 | }}} |
| 56 | |
| 57 | OGRFeature::SetField() will check that the passed value is in the accepted |
| 58 | range for boolean and int16 subtypes. If not, it will emit a warning and |
| 59 | correct/clamp the value to fit the subtype. |
| 60 | |
| 61 | === C API changes === |
| 62 | |
| 63 | Only additions : |
| 64 | {{{ |
| 65 | OGRFieldSubType CPL_DLL OGR_Fld_GetSubType( OGRFieldDefnH ); |
| 66 | void CPL_DLL OGR_Fld_SetSubType( OGRFieldDefnH, OGRFieldSubType ); |
| 67 | const char CPL_DLL *OGR_GetFieldSubTypeName( OGRFieldSubType ); |
| 68 | int CPL_DLL OGR_AreTypeSubTypeCompatible( OGRFieldType eType, |
| 69 | OGRFieldSubType eSubType ); |
| 70 | }}} |
| 71 | |
| 72 | == Changes in OGR SQL == |
| 73 | |
| 74 | * Subtypes are preserved when a field name (or *) is specified in the list |
| 75 | of fields of a SELECT |
| 76 | * CAST(xxx AS BOOLEAN) and CAST(xxx AS SMALLINT) are now supported. |
| 77 | * The field list of a SELECT can now accept boolean expressions, such as |
| 78 | "SELECT x IS NULL, x >= 5 FROM foo" |
| 79 | * The WHERE clause of a SELECT can now accept boolean fields, such as |
| 80 | "SELECT * FROM foo WHERE a_boolean_field" |
| 81 | |
| 82 | == Changes in drivers == |
| 83 | |
| 84 | * GeoJSON: can read/write OFSTBoolean |
| 85 | * GML: can read/write OFSTBoolean, OFSTInt16 and OFSTFloat32 |
| 86 | * CSV: can read/write OFSTBoolean (explicitely with CSVT or with autodetection), OFSTInt16 and OFSTFloat32 (explicitely with CSVT) |
| 87 | * PG: can read/write OFSTBoolean, OFSTInt16 and OFSTFloat32 |
| 88 | * PGDump: can write OFSTBoolean, OFSTInt16 and OFSTFloat32 |
| 89 | * GeoPackage: can read/write OFSTBoolean, OFSTInt16 and OFSTFloat32 |
| 90 | * SQLite: can read/write OFSTBoolean and OFSTInt16 |
| 91 | * SQLite dialect: can read/write OFSTBoolean, OFSTInt16 and OFSTFloat32 |
| 92 | * FileGDB: can read/write OFSTInt16 and OFSTFloat32 |
| 93 | * OpenFileGDB: can read OFSTInt16 and OFSTFloat32 |
| 94 | * VRT: 'subtype' property added to be able to handle any subtype. |
| 95 | |
| 96 | == Changes in utilities == |
| 97 | |
| 98 | * ogrinfo: the output of ogrinfo is slightly modified in presence of a subtype. |
| 99 | A field with a non-default subtype will be described as "field_type(field_subtype)". |
| 100 | For example |
| 101 | {{{ |
| 102 | Had to open data source read-only. |
| 103 | INFO: Open of `out.gml' |
| 104 | using driver `GML' successful. |
| 105 | |
| 106 | Layer name: test |
| 107 | Geometry: None |
| 108 | Feature Count: 2 |
| 109 | Layer SRS WKT: |
| 110 | (unknown) |
| 111 | short: Integer(Int16) (0.0) |
| 112 | b: Integer(Boolean) (0.0) |
| 113 | OGRFeature(test):0 |
| 114 | short (Integer(Int16)) = -32768 |
| 115 | b (Integer(Boolean)) = 1 |
| 116 | }}} |
| 117 | |
| 118 | == Changes in SWIG bindings == |
| 119 | |
| 120 | Addition of : |
| 121 | * ogr.OFSTNone, ogr.OFSTBoolean, ogr.OFSTInt16 and ogr.OFSTFloat32 |
| 122 | * ogr.GetFieldSubTypeName() |
| 123 | * FieldDefn.GetSubType() |
| 124 | * FieldDefn.SetSubType() |
| 125 | |
| 126 | == Compatibility == |
| 127 | |
| 128 | This should have no impact on read-only operations done by applications. |
| 129 | Update operations could be impacted if an out-of-range value for the subtype |
| 130 | is written (but such a behaviour probably already caused issues, either ignored or |
| 131 | notified by the backend) |
| 132 | |
| 133 | == Documentation == |
| 134 | |
| 135 | All new methods are documented. Driver documentationis updated when necessary. |
| 136 | |
| 137 | == Testing == |
| 138 | |
| 139 | The various aspects of this RFC are tested: |
| 140 | * core changes |
| 141 | * OGR SQL changes |
| 142 | * driver changes |
| 143 | |
| 144 | == Implementation == |
| 145 | |
| 146 | Implementation will be done by Even Rouault ([http://spatialys.com Spatialys]), |
| 147 | and sponsored by [https://cartodb.com CartoDB]. |
| 148 | |
| 149 | The proposed implementation lies in the "ogr_field_subtype" branch of the |
| 150 | https://github.com/rouault/gdal2/tree/ogr_field_subtype repository. |
| 151 | |
| 152 | The list of changes : https://github.com/rouault/gdal2/compare/ogr_field_subtype |
| 153 | |
| 154 | == Voting history == |
| 155 | |
| 156 | TBD |