Skip to content

Commit

Permalink
addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aagm committed Jun 10, 2021
1 parent c4fbf92 commit d112472
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Buffer> {
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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;
}
}
10 changes: 8 additions & 2 deletions api/apps/geoprocessing/src/modules/tile/tile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)})`;
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d112472

Please sign in to comment.