Skip to content

Commit

Permalink
reworked as a ternary based on A. Rota request
Browse files Browse the repository at this point in the history
  • Loading branch information
aagm committed Jun 21, 2021
1 parent 283863b commit 2e3673d
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,17 @@ export class PlanningUnitsService {
const gridSize = this.calculateGridSize(planningUnitAreakm2);
// 156412 references to m per pixel at z level 0 at the equator in EPSG:3857
const ratioPixelExtent = gridSize / (156412 / 2 ** z);
let query = `( SELECT row_number() over() as id, (${gridShape}(${gridSize}, \
/**
* We are checking that the pixel ration is < 8 px and bbox is not present
* Because we want to reduce the overhead for the db if an uncontroled area requests
* a large area.
* If so the shape we are getting is down the optimal to visualize it as points
*/
const query = (ratioPixelExtent < 8 && !filters?.bbox) ?
`( SELECT row_number() over() as id, st_centroid((${gridShape}(${gridSize}, \
ST_Transform(ST_TileEnvelope(${z}, ${x}, ${y}), 3857))).geom ) as the_geom )` :
`( SELECT row_number() over() as id, (${gridShape}(${gridSize}, \
ST_Transform(ST_TileEnvelope(${z}, ${x}, ${y}), 3857))).geom as the_geom)`;
// (so we are checking that the pixel ration is < 8 px)
// If so the shape we are getting is down the optimal to visualize it
if (ratioPixelExtent < 8 && !filters?.bbox) {
query = `( SELECT row_number() over() as id, st_centroid((${gridShape}(${gridSize}, \
ST_Transform(ST_TileEnvelope(${z}, ${x}, ${y}), 3857))).geom ) as the_geom )`;
}

return query;
}
Expand Down

0 comments on commit 2e3673d

Please sign in to comment.