相关疑难解决方法(0)

使用Sequelize ORM插入/更新PostGis几何体

我用sequelize-auto提取了一些PostGis图层的模型,给出:

module.exports = function(sequelize, DataTypes) {
return sequelize.define('table', {
  id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    autoIncrement: true
  },
  geom: {
    type: DataTypes.GEOMETRY('POINT', 4326),
    allowNull: true,
  },
...
Run Code Online (Sandbox Code Playgroud)

在GET上,sequelize将geom作为GeoJSON发送给客户端:

{
  "type":"Point",
  "coordinates":[11.92164103734465,57.67219297300486]
}
Run Code Online (Sandbox Code Playgroud)

当我尝试将此Posgis错误保存为:

ERROR:  Geometry SRID (0) does not match column SRID (4326)
Run Code Online (Sandbox Code Playgroud)

这个答案给出了如何添加SRID的神的指示(如何在Sequelize ORM中插入PostGIS几何点?),

var point = { 
  type: 'Point', 
  coordinates: [39.807222,-76.984722],
  crs: { type: 'name', properties: { name: 'EPSG:4326'} }
};

User.create({username: 'username', geometry: point }).then(function(newUser) {
...
});
Run Code Online (Sandbox Code Playgroud)

我知道SRID曾经是从sequelize中删除的功能(https://github.com/sequelize/sequelize/issues/4054).

有没有人知道一种方法来挂钩Sequelize,以便将srid添加到发送给PostGis的GeoJson?在哪里放?在模型的设定者?

postgis geojson sequelize.js

6
推荐指数
1
解决办法
1123
查看次数

标签 统计

geojson ×1

postgis ×1

sequelize.js ×1