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 e9031a31a9..e9b0ae9473 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 @@ -53,7 +53,7 @@ export class PlanningUnitsService { * @param filters so far only bbox is accepted * @returns vector tile */ - public findPreviewTile( + public findPreviewTile( tileSpecification: tileSpecification, filters?: PlanningUnitsFilters, ): Promise { @@ -104,21 +104,19 @@ export class PlanningUnitsService { planningUnitAreakm2: number, ): string { const gridShape = this.regularFunctionGridSelector(planningUnitGridShape); - const gridSize = this.calculateGridSize( - planningUnitAreakm2, - ); + 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}, \ + let query = `( 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) { - Query = `( SELECT row_number() over() as id, st_centroid((${gridShape}(${gridSize}, \ + 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; + return query; } /** * @param filters including only bounding box of the area where the grids would be generated @@ -134,7 +132,6 @@ export class PlanningUnitsService { return whereQuery; } - /** * @param planningUnitGridShape the grid shape that would be use for generating the grid. This grid shape * can be square or hexagon. If any grid shape is provided, square would be the default. @@ -156,9 +153,7 @@ export class PlanningUnitsService { * @param planningUnitAreakm2 * @returns grid h size in m */ - private calculateGridSize( - planningUnitAreakm2: number, - ): number { + private calculateGridSize(planningUnitAreakm2: number): number { return Math.sqrt(planningUnitAreakm2) * 1000; } } diff --git a/api/apps/geoprocessing/src/modules/tile/tile.service.ts b/api/apps/geoprocessing/src/modules/tile/tile.service.ts index d4805bdf89..121e48374e 100644 --- a/api/apps/geoprocessing/src/modules/tile/tile.service.ts +++ b/api/apps/geoprocessing/src/modules/tile/tile.service.ts @@ -90,7 +90,13 @@ export class TileService { */ private readonly logger: Logger = new Logger(TileService.name); - simplification(z: number, geometry: string): string { + /** + * Simplification based in zoom level + * @param z + * @param geometry + * @returns + */ + geometrySimplification(z: number, geometry: string): string { return z > 7 ? `${geometry}` : `ST_RemoveRepeatedPoints(${geometry}, ${0.1 / (z * 2)})`; @@ -120,7 +126,7 @@ export class TileService { .select(`ST_AsMVT(tile, 'layer0', ${extent}, 'mvt_geom')`, 'mvt') .from((subQuery) => { subQuery.select( - `${attributes}, ST_AsMVTGeom(ST_Transform(${this.simplification( + `${attributes}, ST_AsMVTGeom(ST_Transform(${this.geometrySimplification( z, geometry, )}, 3857),