From daa3fdca119b5702ea4eb7452104361d93be8c4f Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Thu, 14 Dec 2017 12:12:43 +0100 Subject: [PATCH 1/2] Fix bug in point-grid aggregation --- lib/cartodb/models/aggregation/aggregation-query.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 7dd55b3c..55ee53ea 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -50,6 +50,7 @@ const SUPPORTED_AGGREGATE_FUNCTIONS = { }; const aggregateColumns = ctx => { + // TODO: always add count let columns = ctx.columns || {}; if (Object.keys(columns).length === 0) { // default aggregation @@ -117,7 +118,7 @@ const aggregationQueryTemplates = { 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, + 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 `, From b0e47ecc6201643cc0821317bc6963a935af12f2 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Thu, 14 Dec 2017 12:23:02 +0100 Subject: [PATCH 2/2] Fix aggregation resolution parameter It was implemented as the inverse of the intended value --- lib/cartodb/models/aggregation/aggregation-query.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 55ee53ea..bf995c82 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -72,8 +72,8 @@ const aggregateColumns = ctx => { }; // Notes: -// * ${ctx.res*0.00028/256}*!scale_denominator! is equivalent to -// ${ctx.res/256}*CDB_XYZ_Resolution(CDB_ZoomFromScale(!scale_denominator!)) +// * ${256*0.00028/ctx.res}*!scale_denominator! is equivalent to +// ${256/ctx.res}*CDB_XYZ_Resolution(CDB_ZoomFromScale(!scale_denominator!)) // * We need to filter spatially using !bbox! to make the queries efficient because // the filter added by Mapnik (wrapping the query) // is only applied after the aggregation. @@ -83,7 +83,7 @@ const aggregationQueryTemplates = { 'centroid': ctx => ` WITH _cdb_params AS ( SELECT - (${ctx.res*0.00028/256}*!scale_denominator!)::double precision AS res, + (${256*0.00028/ctx.res}*!scale_denominator!)::double precision AS res, !bbox! AS bbox ) SELECT @@ -105,7 +105,7 @@ const aggregationQueryTemplates = { 'point-grid': ctx => ` WITH _cdb_params AS ( SELECT - (${ctx.res*0.00028/256}*!scale_denominator!)::double precision AS res, + (${256*0.00028/ctx.res}*!scale_denominator!)::double precision AS res, !bbox! AS bbox ), _cdb_clusters AS ( @@ -127,7 +127,7 @@ const aggregationQueryTemplates = { WITH _cdb_params AS ( SELECT - (${ctx.res*0.00028/256}*!scale_denominator!)::double precision AS res, + (${256*0.00028/ctx.res}*!scale_denominator!)::double precision AS res, !bbox! AS bbox ), _cdb_clusters AS ( SELECT