Fix point-grid aggregation query

This commit is contained in:
Javier Goizueta
2017-12-12 17:38:39 +01:00
parent 4405d61845
commit 4193f96c03
@@ -80,31 +80,24 @@ const aggregationQueryTemplates = {
`,
'point-grid': ctx => `
WITH _cdb_params AS (
SELECT
(${ctx.res*0.00028/256}*!scale_denominator!)::double precision AS res,
!bbox! AS bbox
),
_cdb_clusters AS (
SELECT
ST_SetSRID(
ST_MakePoint(
AVG(ST_X(_cdb_query.the_geom_webmercator)),
AVG(ST_Y(_cdb_query.the_geom_webmercator))
),
3857
) AS the_geom_webmercator,
Floor(ST_X(_cdb_query.the_geom_webmercator)/_cdb_params.res)::int AS _cdb_gx,
Floor(ST_Y(_cdb_query.the_geom_webmercator)/_cdb_params.res)::int AS _cdb_gy,
${aggregateColumns(ctx)}
FROM (${ctx.sourceQuery}) _cdb_query, _cdb_params
WHERE the_geom_webmercator && _cdb_params.bbox
GROUP BY _cdb_gx, _cdb_gy
)
WITH _cdb_params AS (
SELECT
ST_SetSRID(ST_MakePoint(_cdb_gx*(res+0.5), _cdb_gy*(res*0.5)), 3857) AS the_geom_webmercator,
_cdb_feature_count
FROM _cdb_clusters, _cdb_params
(${ctx.res*0.00028/256}*!scale_denominator!)::double precision AS res,
!bbox! AS bbox
),
_cdb_clusters AS (
SELECT
Floor(ST_X(_cdb_query.the_geom_webmercator)/_cdb_params.res)::int AS _cdb_gx,
Floor(ST_Y(_cdb_query.the_geom_webmercator)/_cdb_params.res)::int AS _cdb_gy,
${aggregateColumns(ctx)}
FROM (${ctx.sourceQuery}) _cdb_query, _cdb_params
WHERE the_geom_webmercator && _cdb_params.bbox
GROUP BY _cdb_gx, _cdb_gy
)
SELECT
ST_SetSRID(ST_MakePoint(_cdb_gx*(res+0.5), _cdb_gy*(res*0.5)), 3857) AS the_geom_webmercator,
_cdb_feature_count
FROM _cdb_clusters, _cdb_params
`,
'point-sample': ctx => `