Aggregation: Extract the query to get the grid data
This commit is contained in:
parent
892479d9b9
commit
8454eef6e9
@ -300,7 +300,7 @@ const havingClause = ctx => {
|
||||
// We limit the the minimum resolution to avoid division by zero problems. The limit used is
|
||||
// the pixel size of zoom level 30 (i.e. 1/2*(30+8) of the full earth web-mercator extent), which is about 0.15 mm.
|
||||
//
|
||||
// NOTE: We'd rather use !pixel_height!, but in Mapnik this value is extent / 256 for raster
|
||||
// NOTE: We'd rather use !scale_denominator!, but in Mapnik this value is extent / 256 for raster
|
||||
// and extent / tile_extent {4096 default} for MVT, so since aggregations are always based
|
||||
// on 256 we can't have the same query in both cases
|
||||
// As this scale change doesn't happen in !scale_denominator! we use that instead
|
||||
@ -309,6 +309,26 @@ const gridResolution = ctx => {
|
||||
return `${256/ctx.res} * GREATEST(!scale_denominator! * 0.00028, ${minimumResolution})::double precision`;
|
||||
};
|
||||
|
||||
// SQL query to extra the boundaries of the area to be aggregated and the grid resolution
|
||||
const gridInfoQuery = ctx => {
|
||||
return `
|
||||
SELECT
|
||||
res,
|
||||
CEIL (ST_XMIN(cdb_full_bbox) / res) * res AS cdb_xmin,
|
||||
FLOOR(ST_XMAX(cdb_full_bbox) / res) * res AS cdb_xmax,
|
||||
CEIL (ST_YMIN(cdb_full_bbox) / res) * res AS cdb_ymin,
|
||||
FLOOR(ST_YMAX(cdb_full_bbox) / res) * res AS cdb_ymax
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
${gridResolution(ctx)} AS res,
|
||||
!bbox! cdb_full_bbox
|
||||
OFFSET 0
|
||||
) _cdb_input_resources
|
||||
`;
|
||||
};
|
||||
|
||||
|
||||
// Function to generate the resulting point for a cell from the aggregated
|
||||
const aggregatedPoint = (ctx, aggregated) => {
|
||||
const placement = ctx.placement || DEFAULT_PLACEMENT;
|
||||
@ -387,19 +407,7 @@ SELECT * FROM
|
||||
((cdb_ymax - cdb_ymin) / res)::int as cdb_limit_y
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
res,
|
||||
CEIL (ST_XMIN(cdb_full_bbox) / res) * res AS cdb_xmin,
|
||||
FLOOR(ST_XMAX(cdb_full_bbox) / res) * res AS cdb_xmax,
|
||||
CEIL (ST_YMIN(cdb_full_bbox) / res) * res AS cdb_ymin,
|
||||
FLOOR(ST_YMAX(cdb_full_bbox) / res) * res AS cdb_ymax
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
${gridResolution(ctx)} AS res,
|
||||
!bbox! cdb_full_bbox
|
||||
OFFSET 0
|
||||
) _cdb_input_resources
|
||||
${gridInfoQuery(ctx)}
|
||||
) _cdb_grid_bbox_margins OFFSET 0
|
||||
) __cdb_src_params
|
||||
WHERE the_geom_webmercator && cdb_point_bbox OFFSET 0
|
||||
|
Loading…
Reference in New Issue
Block a user