From 8bd6513db74e23d33a0b2af3d5a1c2445dce0867 Mon Sep 17 00:00:00 2001 From: almog8k Date: Tue, 24 Dec 2024 18:39:22 +0200 Subject: [PATCH] feat: suuport radiusBufferUnits in configuration --- config/custom-environment-variables.json | 5 +++-- config/default.json | 3 ++- helm/templates/configmap.yaml | 3 ++- helm/values.yaml | 3 ++- src/task/models/tileMergeTaskManager.ts | 14 ++++++++------ 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index df249a7..584248b 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -110,10 +110,11 @@ "__name": "TILES_MERGING_TASK_BATCH_SIZE", "__format": "number" }, - "radiusBufferCM": { + "radiusBuffer": { "__name": "TILES_MERGING_RADIUS_BUFFER_CM", "__format": "number" - } + }, + "radiusBufferUnits": "TILES_MERGING_RADIUS_BUFFER_UNITS" }, "tilesSeeding": { "type": "TILES_SEEDING_TASK_TYPE", diff --git a/config/default.json b/config/default.json index 1d95be3..bfbf16f 100644 --- a/config/default.json +++ b/config/default.json @@ -86,7 +86,8 @@ "type": "tiles-merging", "tileBatchSize": 10000, "taskBatchSize": 5, - "radiusBufferCM": 30 + "radiusBuffer": 0.000006, + "radiusBufferUnits": "degrees" }, "tilesSeeding": { "type": "tiles-seeding", diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml index fc26d63..742bfb1 100644 --- a/helm/templates/configmap.yaml +++ b/helm/templates/configmap.yaml @@ -46,7 +46,8 @@ data: TILES_MERGING_TASK_TYPE: {{ $jobDefinitions.tasks.merge.type | quote }} TILES_MERGING_TILE_BATCH_SIZE: {{ $jobDefinitions.tasks.merge.tileBatchSize | quote }} TILES_MERGING_TASK_BATCH_SIZE: {{ $jobDefinitions.tasks.merge.taskBatchSize | quote }} - TILES_MERGING_RADIUS_BUFFER_CM: {{ $jobDefinitions.tasks.merge.radiusBufferCM | quote }} + TILES_MERGING_RADIUS_BUFFER_CM: {{ $jobDefinitions.tasks.merge.radiusBuffer | quote }} + TILES_MERGING_RADIUS_BUFFER_UNITS: {{ $jobDefinitions.tasks.merge.radiusBufferUnits | quote }} TILES_SEEDING_TASK_TYPE: {{ $jobDefinitions.tasks.seed.type | quote }} TILES_SEEDING_GRID : {{ $jobDefinitions.tasks.seed.grid | quote }} TILES_SEEDING_MAX_ZOOM : {{ $jobDefinitions.tasks.seed.maxZoom | quote }} diff --git a/helm/values.yaml b/helm/values.yaml index 22d1aee..94ac77e 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -123,7 +123,8 @@ jobDefinitions: type: "" tileBatchSize: 10000 taskBatchSize: 5 - radiusBufferCM: 30 + radiusBuffer: 0.000006 + radiusBufferUnits: "degrees" # supported values are: "degrees" | "centimeters" | "meters" | "millimeters" | "kilometers" | "miles" | "inches" | "yards" | "feet" | "radians" seed: type: "" grid: "WorldCRS84" diff --git a/src/task/models/tileMergeTaskManager.ts b/src/task/models/tileMergeTaskManager.ts index e8ab0ab..fb1099a 100644 --- a/src/task/models/tileMergeTaskManager.ts +++ b/src/task/models/tileMergeTaskManager.ts @@ -4,7 +4,7 @@ import { Feature, MultiPolygon, Polygon } from 'geojson'; import { InputFiles, PolygonPart } from '@map-colonies/mc-model-types'; import { ICreateTaskBody, TaskHandler as QueueClient } from '@map-colonies/mc-priority-queue'; import { degreesPerPixelToZoomLevel, tileBatchGenerator, TileRanger } from '@map-colonies/mc-utils'; -import { bbox, buffer, featureCollection, polygon, union } from '@turf/turf'; +import { bbox, buffer, featureCollection, polygon, union, Units } from '@turf/turf'; import { inject, injectable } from 'tsyringe'; import { SERVICES, TilesStorageProvider } from '../../common/constants'; import { @@ -30,7 +30,8 @@ export class TileMergeTaskManager { private readonly tileBatchSize: number; private readonly taskBatchSize: number; private readonly taskType: string; - private readonly radiusBufferCM: number; + private readonly radiusBuffer: number; + private readonly radiusBufferUnits: Units; public constructor( @inject(SERVICES.LOGGER) private readonly logger: Logger, @inject(SERVICES.CONFIG) private readonly config: IConfig, @@ -42,7 +43,8 @@ export class TileMergeTaskManager { this.tileBatchSize = this.config.get('jobManagement.ingestion.tasks.tilesMerging.tileBatchSize'); this.taskBatchSize = this.config.get('jobManagement.ingestion.tasks.tilesMerging.taskBatchSize'); this.taskType = this.config.get('jobManagement.ingestion.tasks.tilesMerging.type'); - this.radiusBufferCM = this.config.get('jobManagement.ingestion.tasks.tilesMerging.radiusBufferCM'); + this.radiusBuffer = this.config.get('jobManagement.ingestion.tasks.tilesMerging.radiusBuffer'); + this.radiusBufferUnits = this.config.get('jobManagement.ingestion.tasks.tilesMerging.radiusBufferUnits'); } public buildTasks(taskBuildParams: MergeTilesTaskParams): AsyncGenerator { @@ -234,9 +236,9 @@ export class TileMergeTaskManager { //strip out all gaps and holes in the polygon which simplifies the polygon(solved the issue with tileRanger intersect error) private createBufferedFeature(feature: Feature): Feature { - const logger = this.logger.child({ featureType: feature.type, radiusBufferCM: this.radiusBufferCM }); + const logger = this.logger.child({ featureType: feature.type, radiusBuffer: this.radiusBuffer }); - const bufferOutFeature = buffer(feature.geometry, this.radiusBufferCM, { units: 'centimeters' }); + const bufferOutFeature = buffer(feature.geometry, this.radiusBuffer, { units: this.radiusBufferUnits }); if (bufferOutFeature === undefined) { const errorMsg = 'Failed to buffer Out feature because the result is undefined'; @@ -244,7 +246,7 @@ export class TileMergeTaskManager { throw new Error(errorMsg); } - const bufferInFeature = buffer(bufferOutFeature.geometry, -this.radiusBufferCM, { units: 'centimeters' }); + const bufferInFeature = buffer(bufferOutFeature.geometry, -this.radiusBuffer, { units: this.radiusBufferUnits }); if (bufferInFeature === undefined) { const errorMsg = 'Failed to buffer In feature because the result is undefined';