lundi 20 avril 2015

Inserting geometry (JSON) into loopbackjs model

I am adding and editing geometry in loopback with the angular SDK into PostGIS, and I have the following working fine:

ProjectGeoms.upsert({"id":"129","projectGeom":   {"type":"Polygon","coordinates":[[arrays of x/y co-ordinates]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}}, successCallback, errorCallback)

The SQL query being run is:

loopback:connector:postgresql SQL: UPDATE "public"."project_geom" SET  "ref"=$1,"project_geom"=$2
Parameters: 129,{"type":"Polygon","coordinates":[[arrays of x/y co-ordinates]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}} +2ms

This is for a geometry that already exists. However, when I add it for a geometry which doesn't exist (the same JSON structure, but with an id 124), then it does not work.

The SQL query being run is:

loopback:connector:postgresql SQL: INSERT INTO "public"."project_geom" ("ref","project_geom") SELECT $1,$2 RETURNING 
Parameters: 124,{"type":"Polygon","coordinates":[[arrays of x/y co-ordinates]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}} +2ms

The full error message is below:

loopback:connector:postgresql error: syntax error at end of input
at Connection.parseE (C:\Bitnami\wappstack-5.4.30-   0\apache2\htdocs\project\api\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:534:11)
at Connection.parseMessage (C:\Bitnami\wappstack-5.4.30-0\apache2\htdocs\project\api\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:361:17)
at Socket.<anonymous> (C:\Bitnami\wappstack-5.4.30-0\apache2\htdocs\project\api\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:105:22)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10) +15ms

If I run the following query in Postgres directly:

INSERT INTO project_geom (ref,project_geom) VALUES (124,'{"type":"Polygon","coordinates":[[arrays of x/y co-ordinates]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'::json);

I am able to insert the value without issue.

The view schema is (ref::integer, project_geom::json)

Aucun commentaire:

Enregistrer un commentaire