diff --git a/api/apps/geoprocessing/src/modules/planning-units/planning-units.service.ts b/api/apps/geoprocessing/src/modules/planning-units/planning-units.service.ts index 966f8939c8..278201f6ee 100644 --- a/api/apps/geoprocessing/src/modules/planning-units/planning-units.service.ts +++ b/api/apps/geoprocessing/src/modules/planning-units/planning-units.service.ts @@ -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; }