RFC 50:OGR字段子类型
作者:连鲁奥
联系人:spatialys.com上的偶数点rouault
状态:采用,在GDAL 2.0中实现
总结
此RFC旨在添加向OGR字段指定子类型的功能,如布尔值、16位整数或32位浮点值。字段定义的子类型是一个附加属性,用于指定对主类型的提示或限制。子类型可以被知道如何处理它的应用程序和驱动程序使用,并且通常可以被不知道如何处理它的应用程序和驱动程序安全地忽略。
核心变化
字段子类型
添加了OGRFieldSubType枚举:
/**
* List of field subtypes. A subtype represents a hint, a restriction of the
* main type, that is not strictly necessary to consult.
* This list is likely to be extended in the
* future ... avoid coding applications based on the assumption that all
* field types can be known.
* Most subtypes only make sense for a restricted set of main types.
* @since GDAL 2.0
*/
typedef enum
{
/** No subtype. This is the default value */ OFSTNone = 0,
/** Boolean integer. Only valid for OFTInteger and OFTIntegerList.*/
OFSTBoolean = 1,
/** Signed 16-bit integer. Only valid for OFTInteger and OFTIntegerList. */
OFSTInt16 = 2,
/** Single precision (32 bit) floatint point. Only valid for OFTReal and OFTRealList. */
OFSTFloat32 = 3,
OFSTMaxSubType = 3
} OGRFieldSubType;
新的属性和方法
在OGRFieldDefn类中:
OGRFieldSubType eSubType;
OGRFieldSubType GetSubType() { return eSubType; }
void SetSubType( OGRFieldSubType eSubTypeIn );
static const char *GetFieldSubTypeName( OGRFieldSubType );
OGRFeature::SetField()将检查传递的值是否在布尔和int16子类型的可接受范围内。否则,它将发出警告并更正/钳制该值以适合子类型。
C API更改
仅添加:
OGRFieldSubType CPL_DLL OGR_Fld_GetSubType( OGRFieldDefnH );
void CPL_DLL OGR_Fld_SetSubType( OGRFieldDefnH, OGRFieldSubType );
const char CPL_DLL *OGR_GetFieldSubTypeName( OGRFieldSubType );
int CPL_DLL OGR_AreTypeSubTypeCompatible( OGRFieldType eType,
OGRFieldSubType eSubType );
OGR SQL中的更改
当字段名(或 * )在选定的字段列表中指定
现在支持强制转换(xxx作为布尔值)和强制转换(xxx作为SMALLINT)。
SELECT的字段列表现在可以接受布尔表达式,例如“SELECT x IS NULL,x>=5 FROM foo”
SELECT的WHERE子句现在可以接受布尔字段,例如“SELECT * 从foo,其中一个“布尔”字段“
驱动因素的变化
GeoJSON:可以读/写ofsboolean
GML:可以读/写OfsBoolean、OfsInt16和OfsFloat32
CSV:可以读/写OFSTBoolean(显式使用CSVT或自动检测)、OFSTInt16和OFSTFloat32(显式使用CSVT)
PG:可以读/写OFSTBoolean、OFSTInt16和OFSTFloat32
PGDump:可以写入OFSTBoolean、OFSTInt16和OFSTFloat32
GeoPackage:可以读/写OfsBoolean、OfsInt16和OfsFloat32
SQLite:可以读/写ofsboolean和ofstit16
SQLite方言:可以读/写OfsBoolean、OfsInt16和OfsFloat32
FileGDB:可以读/写ofstin16和OFSTFloat32
OpenFileGDB:可以读取ofstin16和OFSTFloat32
VRT:添加了“subtype”属性,以便能够处理任何子类型。
公用设施的变化
ogrinfo:在存在子类型的情况下,ogrinfo的输出稍有修改。具有非默认子类型的字段将被描述为“字段类型(字段子类型)”。例如
Had to open data source read-only.
INFO: Open of `out.gml'
using driver `GML' successful.
Layer name: test
Geometry: None
Feature Count: 2
Layer SRS WKT:
(unknown)
short: Integer(Int16) (0.0)
b: Integer(Boolean) (0.0)
OGRFeature(test):0
short (Integer(Int16)) = -32768
b (Integer(Boolean)) = 1
SWIG绑定的更改
增加:
ogr.Ofstone、ogr.OfsBoolean、ogr.OfsInt16和ogr.OfsFloat32
ogr.GetFieldSubTypeName()
FieldDefn.GetSubType()
FieldDefn.SetSubType()
兼容性
这应该不会影响应用程序执行的只读操作。如果写入子类型的超出范围的值,则更新操作可能会受到影响(但这样的行为可能已经导致问题,或者被忽略,或者被后端通知)
文档
所有新方法都记录在案。必要时更新驱动程序文档。
测试
对本RFC的各个方面进行了测试:
核心变化
OGR SQL更改
驱动程序更改
实施
实施将由甚至鲁奥完成 (Spatialys _),并由 CartoDB .
建议的实现位于 https://github.com/rouault/gdal2/tree/ogr_field_subtype 储存库。
更改列表: https://github.com/rouault/gdal2/compare/ogr_field_subtype
投票历史
+1 JukkaR,TamasS,FrankW和Ever