Refactor aggregation resolution

This commit is contained in:
Javier Goizueta 2017-12-14 16:51:55 +01:00
parent e4407ece84
commit 9d8ce6bc44

View File

@ -78,9 +78,14 @@ const aggregateColumnDefs = ctx => {
}).join(', '); }).join(', ');
}; };
// SQL expression to compute the aggregation resolution (grid cell size).
// This is equivalent to `${256/ctx.res}*CDB_XYZ_Resolution(CDB_ZoomFromScale(!scale_denominator!))`
// This is defined by the ctx.res parameter, which is the number of grid cells per tile linear dimension
// (i.e. each tile is divided into ctx.res*ctx.res cells).
const gridResolution = ctx => `(${256*0.00028/ctx.res}*!scale_denominator!)::double precision`;
// Notes: // Notes:
// * ${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 // * We need to filter spatially using !bbox! to make the queries efficient because
// the filter added by Mapnik (wrapping the query) // the filter added by Mapnik (wrapping the query)
// is only applied after the aggregation. // is only applied after the aggregation.
@ -90,7 +95,7 @@ const aggregationQueryTemplates = {
'centroid': ctx => ` 'centroid': ctx => `
WITH _cdb_params AS ( WITH _cdb_params AS (
SELECT SELECT
(${256*0.00028/ctx.res}*!scale_denominator!)::double precision AS res, ${gridResolution(ctx)} AS res,
!bbox! AS bbox !bbox! AS bbox
) )
SELECT SELECT
@ -112,7 +117,7 @@ const aggregationQueryTemplates = {
'point-grid': ctx => ` 'point-grid': ctx => `
WITH _cdb_params AS ( WITH _cdb_params AS (
SELECT SELECT
(${256*0.00028/ctx.res}*!scale_denominator!)::double precision AS res, ${gridResolution(ctx)} AS res,
!bbox! AS bbox !bbox! AS bbox
), ),
_cdb_clusters AS ( _cdb_clusters AS (
@ -133,8 +138,7 @@ const aggregationQueryTemplates = {
'point-sample': ctx => ` 'point-sample': ctx => `
WITH _cdb_params AS ( WITH _cdb_params AS (
SELECT SELECT
${gridResolution(ctx)} AS res,
(${256*0.00028/ctx.res}*!scale_denominator!)::double precision AS res,
!bbox! AS bbox !bbox! AS bbox
), _cdb_clusters AS ( ), _cdb_clusters AS (
SELECT SELECT