Postgres上的多边形插入问题(由于SRID)

时间:2015-02-27 19:13:38

标签: postgresql geolocation geospatial postgis sequelize.js

我在将多边形插入表格结构时遇到问题。我对PostGIS来说比较新,所以我可能会犯这个非常业余的错误。

我的表格设置为"区域"我为我的几何图形添加了一列:

"SELECT AddGeometryColumn(" +
"'public', 'Regions', 'geom', 4326, 'POLYGON', 2" +
");"

根据我的阅读,这将列几何图形设置为接受WGS-83作为我的投影标准。我使用GeoJSON插入我的多边形,因为它对我来说是最简单的选择。这是我的更新声明的一个例子:

UPDATE "Regions"
    SET geom = ST_GeomFromGeoJSON(
        '{"type":"Polygon","coordinates":[[[-114.017347,51.048005],[-114.014433,51.047927],[-114.005899,51.045381],[-114.001598,51.04509],[-114.001631,51.055109],[-114.01618,51.055062],[-114.016949,51.056508],[-114.016181,51.056511],[-114.01659,51.057251],[-114.017318,51.057237],[-114.018672,51.059928],[-114.020528,51.0593],[-114.023615,51.059311],[-114.021148,51.055829],[-114.018807,51.052583],[-114.017347,51.048005]]]}'
    )
    WHERE id = 'ab8326c0-beb3-11e4-89eb-b3372c283c42'

我从查询中得到的回复是:

{ [SequelizeDatabaseError: Geometry SRID (0) does not match column SRID (4326)]
  name: 'SequelizeDatabaseError',
  message: 'Geometry SRID (0) does not match column SRID (4326)',
  parent: 
   { [error: Geometry SRID (0) does not match column SRID (4326)]
     name: 'error',
     length: 121,
     severity: 'ERROR',
     code: '22023',
     detail: undefined,
     hint: undefined,
     position: undefined,
     internalPosition: undefined,
     internalQuery: undefined,
     where: undefined,
     schema: undefined,
     table: undefined,
     column: undefined,
     dataType: undefined,
     constraint: undefined,
     file: 'gserialized_typmod.c',
     line: '128',
     routine: 'postgis_valid_typmod',

我已将坐标验证为WGS84,但现在我认为该问题与我使用的SRID类型无关。

感谢您的帮助。

1 个答案:

答案 0 :(得分:10)

两件事:

  • 只需使用ALTER TABLE命令,即可直接在PostGIS 2.0+中添加几何列。 ALTER TABLE foo ADD COLUMN geom Geometry(Polygon,4326)
  • 如错误所示,您从JSON创建的几何图形缺少列的SRID。所以你需要确保设置好。最简单的方法是使用ST_SetSrid,所以(缩写)UPDATE foo SET geom = ST_SetSRID(ST_GeomFromGeoJSON(...),4326)