2013-03-04 46 views
4

如果您不指定幾何列爲小寫字母,則最終會獲得使用RecoverGeometryColumn函數創建空間表和恢復幾何圖形a'違反了幾何約束[geom-type或SRID not allowed]錯誤。SpatiaLite v4.0.0 RecoverGeometryColumn違反了幾何約束[geom-type或SRID not allowed]'

我做錯了什麼或者我錯過了某些地方的文檔?

+0

我有同樣的問題。我的問題是,我設置,我期待點通過AddGeometryColumn類型,然後試圖把多邊形。 – grasshopper 2015-01-08 21:09:57

回答

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

結論: 注意,f_geometry_column被指定爲「幾何」,但觸發GEOMETRY_COLUMNS表尋找「幾何學」。這會導致'幾何約束[geom-type或SRID not allowed]'問題。所以修復是讓你的空間列名小寫。

+0

我試過這個,但我仍然得到相同的錯誤 「CREATE TABLE Sessions([SessionId] TEXT NOT NULL PRIMARY KEY,[SessionCompletedDate] TEXT NOT NULL,[shape] POINT NULL)」, 「SELECT RecoverGeometryColumn('Sessions','shape',-1,'POINT',2)「, 」SELECT CreateSpatialIndex('Sessions','shape')「, – Chucky 2015-10-26 10:48:10