4

创建空间表并使用 RecoverGeometryColumn 函数恢复几何时,如果您未将几何列指定为小写,您最终会收到“违反几何约束 [不允许使用几何类型或 SRID]”错误。

我做错了什么还是我在某处错过了一些文档?

4

1 回答 1

5

举个例子:

  1. 创建具有空间列的表

    CREATE TABLE "test1" (
    "PK_UID" INTEGER PRIMARY KEY AUTOINCREMENT,
    "Geometry" MULTIPOLYGON)
    
  2. 恢复几何

    SELECT RecoverGeometryColumn('test1', 'Geometry', 2, 'MULTIPOLYGON',2);
    
  3. 查看已创建的触发器

    select * from sqlite_master where type='trigger' and lower(tbl_name)='test1'
    

结果:

    CREATE TRIGGER "ggi_test1_Geometry" BEFORE INSERT ON "test1"
    FOR EACH ROW BEGIN
    SELECT RAISE(ROLLBACK, 'test1.Geometry violates Geometry constraint [geom-type or SRID not allowed]')
    WHERE (SELECT type FROM geometry_columns
    WHERE f_table_name = 'test1' AND f_geometry_column = 'Geometry'
    AND GeometryConstraints(NEW."Geometry", type, srid, 'XY') = 1) IS NULL;
    END

    CREATE TRIGGER "ggu_test1_Geometry" BEFORE UPDATE ON "test1"
    FOR EACH ROW BEGIN
    SELECT RAISE(ROLLBACK, 'test1.Geometry violates Geometry constraint [geom-type or SRID not allowed]')
    WHERE (SELECT type FROM geometry_columns
    WHERE f_table_name = 'test1' AND f_geometry_column = 'Geometry'
    AND GeometryConstraints(NEW."Geometry", type, srid, 'XY') = 1) IS NULL;
    END

与 geometry_columns 表中的内容进行比较

    select * from geometry_columns

结果:

f_table_name f_geometry_column 类型 coord_dimension srid spaitial_index_enabled

test1 几何 MULTIPOLYGON XY 2 0

结论:请注意,geometry_columns 表 f_geometry_column 被指定为“几何”,但触发器正在寻找“几何”。这会导致“几何约束 [不允许使用几何类型或 SRID]”问题。所以解决方法是让你的空间列名小写。

于 2013-03-04T14:06:48.650 回答