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

Polygon insertion issue (due to SRID) on Postgres

我在将多边形插入我的 table 结构时遇到问题。我对 PostGIS 比较陌生,所以我可能在这方面犯了一个非常业余的错误。

我的 table 设置为 "Regions",我正在为我的几何添加一列:

"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 类型无关。

感谢您的帮助。

两件事:

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