问题
My application uses Node.js (v9.3.0), PostgreSQL (v9.5.1.0) as database with PostGIS (v2.2.1) installed as an extension and Sequelize (v4.37.6) as ORM. I'm trying to insert a 4D data - with longitude, latitude, altitude and a unix timestamp - in a LineStringZM column but I'm getting the following error:
DatabaseError: Column has M dimension but geometry does not
After some research, I've found out that Sequelize uses the function ST_GeomFromGeoJSON to insert spatial data. However, this function seems to ignore the 4th dimension in my GeoJSON data, which causes the error above.
I suppose that a raw query using ST_MakeLine
(with the appropriated input) instead of ST_GeomFromGeoJSON
would solve my problem. However, is there an easier way or a more elegant solution to insert a 4D spatial data using Sequelize?
Aditional info:
Model sample:
const GEOGRAPHY = require('sequelize').GEOGRAPHY
module.exports = function (sequelize, DataTypes) {
let Course = sequelize.define('Course', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true
},
gps: {
type: GEOGRAPHY('LinestringZM', 4326)
}
}, {
tableName: 'courses',
timestamps: false,
paranoid: false
})
return Course
}
Insertion code generated by Sequelize:
INSERT INTO "courses" ("gps")
VALUES (St_geomfromgeojson(
'{"type":"LineString","crs":{"type":"name","properties"{"name":"EPSG:4326"}},"coordinates":[[-44.058367,-19.964709,0,1521552190]]}'
));
The SQL above returns the following exception: DatabaseError: Column has M dimension but geometry does not
.
Successful insertion using ST_MakeLine
:
INSERT INTO "courses" ("gps")
VALUES (ST_MakeLine(ST_MakePoint(1,2, 10, 1), ST_MakePoint(3,4, 10, 1)));
来源:https://stackoverflow.com/questions/49800163/insert-data-in-a-4d-spatial-column-using-sequelize