GIS final: return multiple features.

Rather than a single massive FeatureCollection.
This commit is contained in:
D. Berge
2020-08-11 17:10:05 +02:00
parent ca508980f9
commit ba253eae8d

View File

@@ -35,29 +35,24 @@ async function points (projectId, options = {}) {
];
const text = `
SELECT json_build_object(
'type', 'FeatureCollection',
'features', json_agg(geojson::json)) geojson
SELECT ST_AsGeoJSON(t.*) geojson
FROM (
SELECT ST_AsGeoJSON(t.*) geojson
FROM (
SELECT fl.line sailline, fs.line, point, sequence, objref, tstamp, ST_Transform(geometry, 4326) geometry
FROM final_lines fl
INNER JOIN final_shots fs USING (sequence)
WHERE
($1 IS true
AND ST_Transform(geometry, 4326) && ST_MakeEnvelope($2, $3, $4, $5, 4326)
)
OR ($1 IS false AND true)
LIMIT $6
) t
) f;
SELECT fl.line sailline, fs.line, point, sequence, objref, tstamp, ST_Transform(geometry, 4326) geometry
FROM final_lines fl
INNER JOIN final_shots fs USING (sequence)
WHERE
($1 IS true
AND ST_Transform(geometry, 4326) && ST_MakeEnvelope($2, $3, $4, $5, 4326)
)
OR ($1 IS false AND true)
LIMIT $6
) t
`;
const res = await pool.query(text, values);
if (res.rows && res.rows.length) {
return res.rows[0].geojson;
return res.rows.map(r => JSON.parse(r.geojson));
} else {
throw {status: 404};
}