Spatialite

  • Post author:
  • Post category:其他


使用spatialite接口创建空间数据时,几何字段要使用函数AddGeometryColumn进行创建,具体用法如下:

SELECT AddGeometryColumn(‘tableName’, ‘geomFieldName’, EPSG_Code, ‘GeometryType’, dimension)

tableName:表名;

geomFieldName:几何字段名;

EPSG_Code:空间坐标系统编码,如WGS84编码为4326;

GeometryType:几何类型,’POINT’,’LINESTRING’,’POLYGON’等;

dimension:维度,2:二维;3:三维。如果维度与数据坐标维度不同,数据插入失败

使用CreateSpatialIndex进行空间索引构建,具体用法如下:

SELECT CreateSpatialIndex(‘tableName’, ‘geomFieldName’)。

遇到的失败经历:

1、错误代码19:Geometry violates Geometry constraint [geom-type or SRID not allowed]

从错误信息可以看到是几何类型或空间参考不正确导致,但其实维度dimension与插入的几何数据不正确也会出现这样的问题。

另外在使用sqlite进行空间数据操作时,需要初始化Spatialite的一些环境:

sqlite3* mSqlite=NULL;

void* mCache=NULL;

使用前:

mCache = spatialite_alloc_connection();

spatialite_init_ex(mSqlite, mCache, 0);

使用后:

spatialite_cleanup_ex(mCache);

spatialite_shutdown();



版权声明:本文为LY_lxq123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。