【发布时间】:2018-05-27 11:11:24
【问题描述】:
我用 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,
},
...
在 GET 上,sequelize 将 geom 作为 GeoJSON 发送到客户端:
{
"type":"Point",
"coordinates":[11.92164103734465,57.67219297300486]
}
当我尝试通过以下方式保存这个 PosGis 错误时:
ERROR: Geometry SRID (0) does not match column SRID (4326)
这个答案很好地说明了如何添加 SRID (How to insert a PostGIS GEOMETRY Point in Sequelize ORM?),
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) {
...
});
我了解 SRID 曾经是从 sequelize (https://github.com/sequelize/sequelize/issues/4054) 中删除的功能。
有谁知道挂钩到 Sequelize 以便将 srid 添加到发送到 PostGis 的 GeoJson 的方法?放在哪里?在模型的二传手中?
【问题讨论】:
标签: sequelize.js postgis geojson