WIP
This commit is contained in:
parent
5f9f77ded1
commit
50008ea149
@ -57,7 +57,7 @@ BEGIN
|
|||||||
-- asked-for measures in the Observatory.
|
-- asked-for measures in the Observatory.
|
||||||
_procgeom_clauses AS (
|
_procgeom_clauses AS (
|
||||||
SELECT
|
SELECT
|
||||||
'_procgeoms_' || Coalesce(geom_tablename || '_' || geom_geomref_colname, api_method) || ' AS (' ||
|
'_procgeoms_' || Coalesce(left(geom_tablename,10) || '_' || geom_geomref_colname, api_method) || ' AS (' ||
|
||||||
'SELECT ' ||
|
'SELECT ' ||
|
||||||
'ST_AsMVTGeom(st_intersection(' || geom_tablename || '.' || geom_colname || ', _geoms.geom), ST_MakeBox2D(ST_Point(0, 0), ST_Point($2, $2)), $2, $3, $4) AS mvtgeom, ' ||
|
'ST_AsMVTGeom(st_intersection(' || geom_tablename || '.' || geom_colname || ', _geoms.geom), ST_MakeBox2D(ST_Point(0, 0), ST_Point($2, $2)), $2, $3, $4) AS mvtgeom, ' ||
|
||||||
geom_tablename || '.' || geom_geomref_colname || ' AS geomref, ' ||
|
geom_tablename || '.' || geom_geomref_colname || ' AS geomref, ' ||
|
||||||
@ -80,7 +80,7 @@ BEGIN
|
|||||||
-- provide values according to users geometries.
|
-- provide values according to users geometries.
|
||||||
_val_clauses AS (
|
_val_clauses AS (
|
||||||
SELECT
|
SELECT
|
||||||
'_vals_' || Coalesce(geom_tablename || '_' || geom_geomref_colname, api_method) || ' AS (
|
'_vals_' || Coalesce(left(geom_tablename,10) || '_' || geom_geomref_colname, api_method) || ' AS (
|
||||||
SELECT _procgeoms.geomref, _procgeoms.mvtgeom, ' ||
|
SELECT _procgeoms.geomref, _procgeoms.mvtgeom, ' ||
|
||||||
String_Agg('json_build_object(' || CASE
|
String_Agg('json_build_object(' || CASE
|
||||||
-- api-delivered values
|
-- api-delivered values
|
||||||
@ -105,7 +105,7 @@ BEGIN
|
|||||||
END
|
END
|
||||||
-- areaNormalized
|
-- areaNormalized
|
||||||
WHEN LOWER(normalization) LIKE 'area%'
|
WHEN LOWER(normalization) LIKE 'area%'
|
||||||
THEN
|
THEN
|
||||||
-- areaNormalized polygon interpolation
|
-- areaNormalized polygon interpolation
|
||||||
-- SUM (numer * (% OBS geom in user geom)) / area of big geom
|
-- SUM (numer * (% OBS geom in user geom)) / area of big geom
|
||||||
' ROUND(CAST(SUM(' || numer_tablename || '.' || numer_colname || ' ' ||
|
' ROUND(CAST(SUM(' || numer_tablename || '.' || numer_colname || ' ' ||
|
||||||
@ -152,7 +152,7 @@ BEGIN
|
|||||||
END
|
END
|
||||||
|| ') val_' || colid, ', ')
|
|| ') val_' || colid, ', ')
|
||||||
|| '
|
|| '
|
||||||
FROM _procgeoms_' || Coalesce(geom_tablename || '_' || geom_geomref_colname, api_method) || ' _procgeoms ' ||
|
FROM _procgeoms_' || Coalesce(left(geom_tablename,10) || '_' || geom_geomref_colname, api_method) || ' _procgeoms ' ||
|
||||||
Coalesce(String_Agg(DISTINCT
|
Coalesce(String_Agg(DISTINCT
|
||||||
Coalesce('LEFT JOIN observatory.' || numer_tablename || ' ON _procgeoms.geomref = observatory.' || numer_tablename || '.' || numer_geomref_colname,
|
Coalesce('LEFT JOIN observatory.' || numer_tablename || ' ON _procgeoms.geomref = observatory.' || numer_tablename || '.' || numer_geomref_colname,
|
||||||
', LATERAL (SELECT * FROM cdb_observatory.' || api_method || '(_procgeoms.mvtgeom' || Coalesce(', ' ||
|
', LATERAL (SELECT * FROM cdb_observatory.' || api_method || '(_procgeoms.mvtgeom' || Coalesce(', ' ||
|
||||||
@ -164,7 +164,7 @@ BEGIN
|
|||||||
ORDER BY _procgeoms.geomref'
|
ORDER BY _procgeoms.geomref'
|
||||||
|| ')'
|
|| ')'
|
||||||
AS val_clause,
|
AS val_clause,
|
||||||
'_vals_' || Coalesce(geom_tablename || '_' || geom_geomref_colname, api_method) AS cte_name
|
'_vals_' || Coalesce(left(geom_tablename, 10) || '_' || geom_geomref_colname, api_method) AS cte_name
|
||||||
FROM _meta
|
FROM _meta
|
||||||
GROUP BY geom_tablename, geom_geomref_colname, geom_colname, api_method
|
GROUP BY geom_tablename, geom_geomref_colname, geom_colname, api_method
|
||||||
),
|
),
|
||||||
@ -180,9 +180,8 @@ BEGIN
|
|||||||
-- Generate JSON clause. This puts together vals from val_clauses
|
-- Generate JSON clause. This puts together vals from val_clauses
|
||||||
_json_clause AS (SELECT
|
_json_clause AS (SELECT
|
||||||
'SELECT ST_AsMVT(q, ''data'', $2) FROM (' ||
|
'SELECT ST_AsMVT(q, ''data'', $2) FROM (' ||
|
||||||
'SELECT ' || cdb_observatory.FIRST(cte_name) || '.geomref::TEXT id, '
|
'SELECT ' || cdb_observatory.FIRST(cte_name) || '.geomref::TEXT id, ' || (SELECT String_Agg('val_' || colid || '->>''value'' as val_' || colid, ', ') FROM _meta) || ', '
|
||||||
|| cdb_observatory.FIRST(cte_name) || '.mvtgeom geom,
|
|| cdb_observatory.FIRST(cte_name) || '.mvtgeom geom
|
||||||
to_JSONB(ARRAY[' || (SELECT String_Agg('val_' || colid, ', ') FROM _meta) || '])
|
|
||||||
FROM ' || String_Agg(cte_name, ', ') ||
|
FROM ' || String_Agg(cte_name, ', ') ||
|
||||||
Coalesce(' WHERE ' || val_joins, ') q')
|
Coalesce(' WHERE ' || val_joins, ') q')
|
||||||
AS json_clause
|
AS json_clause
|
||||||
|
Loading…
Reference in New Issue
Block a user