Adapt GIS endpoint to new preplots tables structure

This commit is contained in:
D. Berge
2025-08-07 22:02:04 +02:00
parent 5070be5ff3
commit 95d6d0054b

View File

@@ -12,27 +12,53 @@ async function lines (projectId, options = {}) {
["V", "S"].includes(options.class) && options.class || "S"
];
const text = `
SELECT json_build_object(
'type', 'FeatureCollection',
'features', json_agg(geojson::json)) geojson
FROM (
SELECT ST_AsGeoJSON(t.*) geojson
const text = values[6] == 'V'
? `
SELECT json_build_object(
'type', 'FeatureCollection',
'features', json_agg(geojson::json)) geojson
FROM (
SELECT line, incr, remarks, ntba, ST_Transform(geometry, 4326) geometry
FROM preplot_lines
WHERE
class = $7
AND (
($1 IS true
AND ST_Transform(geometry, 4326) && ST_MakeEnvelope($2, $3, $4, $5, 4326)
SELECT ST_AsGeoJSON(t.*) geojson
FROM (
SELECT pl.line, psl.incr, psl.remarks, psl.ntba, ST_Transform(pl.geometry, 4326) geometry
FROM preplot_lines pl
INNER JOIN preplot_saillines psl
ON pl.line = psl.sailline
WHERE
class = $7
AND (
($1 IS true
AND ST_Transform(pl.geometry, 4326) && ST_MakeEnvelope($2, $3, $4, $5, 4326)
)
OR ($1 IS false AND true)
)
OR ($1 IS false AND true)
)
LIMIT $6
) t
) f;
`;
LIMIT $6
) t
) f;
`
: `
SELECT json_build_object(
'type', 'FeatureCollection',
'features', json_agg(geojson::json)) geojson
FROM (
SELECT ST_AsGeoJSON(t.*) geojson
FROM (
SELECT pl.line, psl.incr, psl.remarks, psl.ntba, ST_Transform(pl.geometry, 4326) geometry
FROM preplot_lines pl
INNER JOIN preplot_saillines psl
ON pl.line = psl.line
WHERE
class = $7
AND (
($1 IS true
AND ST_Transform(pl.geometry, 4326) && ST_MakeEnvelope($2, $3, $4, $5, 4326)
)
OR ($1 IS false AND true)
)
LIMIT $6
) t
) f;
`
const res = await client.query(text, values);
client.release();