Skip to content

Commit

Permalink
feat: suuport radiusBufferUnits in configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
almog8k committed Dec 24, 2024
1 parent 93359e1 commit 8bd6513
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"type": "tiles-merging",
"tileBatchSize": 10000,
"taskBatchSize": 5,
"radiusBufferCM": 30
"radiusBuffer": 0.000006,
"radiusBufferUnits": "degrees"
},
"tilesSeeding": {
"type": "tiles-seeding",
Expand Down
3 changes: 2 additions & 1 deletion helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 8 additions & 6 deletions src/task/models/tileMergeTaskManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -42,7 +43,8 @@ export class TileMergeTaskManager {
this.tileBatchSize = this.config.get<number>('jobManagement.ingestion.tasks.tilesMerging.tileBatchSize');
this.taskBatchSize = this.config.get<number>('jobManagement.ingestion.tasks.tilesMerging.taskBatchSize');
this.taskType = this.config.get<string>('jobManagement.ingestion.tasks.tilesMerging.type');
this.radiusBufferCM = this.config.get<number>('jobManagement.ingestion.tasks.tilesMerging.radiusBufferCM');
this.radiusBuffer = this.config.get<number>('jobManagement.ingestion.tasks.tilesMerging.radiusBuffer');
this.radiusBufferUnits = this.config.get<Units>('jobManagement.ingestion.tasks.tilesMerging.radiusBufferUnits');
}

public buildTasks(taskBuildParams: MergeTilesTaskParams): AsyncGenerator<MergeTaskParameters, void, void> {
Expand Down Expand Up @@ -234,17 +236,17 @@ 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<Polygon | MultiPolygon>): Feature<Polygon | MultiPolygon> {
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';
logger.error({ errorMsg });
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';
Expand Down

0 comments on commit 8bd6513

Please sign in to comment.