diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 7bb133d9..f85a2bc6 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -131,7 +131,12 @@ const dimensionDefs = ctx => { // 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`; +const gridResolution = ctx => { + const factor = 256*0.00028/ctx.res; + const minimum_resolution = 2*Math.PI*6378137/Math.pow(2,38); + let minimum_scale_denominator = minimum_resolution/factor; + return `(${factor}*GREATEST(!scale_denominator!,${minimum_scale_denominator}))::double precision`; +}; // Notes: // * We need to filter spatially using !bbox! to make the queries efficient because