Skip to content

Commit

Permalink
feat(tileMergeTaskManager): create buffered version of the unified pa…
Browse files Browse the repository at this point in the history
…rts (#36)

* feat(tileMergeTaskManager): create buffered version of the unified parts

* chore: pr comments

* feat: suuport radiusBufferUnits in configuration

* fix: changed TILES_MERGING_RADIUS_BUFFER_CM to TILES_MERGING_RADIUS_BUFFER
  • Loading branch information
almog8k authored Dec 25, 2024
1 parent 989a61b commit 763d95d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
7 changes: 6 additions & 1 deletion config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@
"taskBatchSize": {
"__name": "TILES_MERGING_TASK_BATCH_SIZE",
"__format": "number"
}
},
"radiusBuffer": {
"__name": "TILES_MERGING_RADIUS_BUFFER",
"__format": "number"
},
"radiusBufferUnits": "TILES_MERGING_RADIUS_BUFFER_UNITS"
},
"tilesSeeding": {
"type": "TILES_SEEDING_TASK_TYPE",
Expand Down
4 changes: 3 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
"tilesMerging": {
"type": "tiles-merging",
"tileBatchSize": 10000,
"taskBatchSize": 5
"taskBatchSize": 5,
"radiusBuffer": 0.000006,
"radiusBufferUnits": "degrees"
},
"tilesSeeding": {
"type": "tiles-seeding",
Expand Down
2 changes: 2 additions & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +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: {{ $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
2 changes: 2 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ jobDefinitions:
type: ""
tileBatchSize: 10000
taskBatchSize: 5
radiusBuffer: 0.000006
radiusBufferUnits: "degrees" # supported values are: "degrees" | "centimeters" | "meters" | "millimeters" | "kilometers" | "miles" | "inches" | "yards" | "feet" | "radians"
seed:
type: ""
grid: "WorldCRS84"
Expand Down
39 changes: 35 additions & 4 deletions src/task/models/tileMergeTaskManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { join } from 'path';
import { Logger } from '@map-colonies/js-logger';
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, 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 @@ -29,6 +30,8 @@ export class TileMergeTaskManager {
private readonly tileBatchSize: number;
private readonly taskBatchSize: number;
private readonly taskType: string;
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 @@ -40,6 +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.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 @@ -215,18 +220,44 @@ export class TileMergeTaskManager {
}

const mergedFootprint = union(featureCollection);

if (mergedFootprint === null) {
throw new Error('Failed to merge footprints because the union result is null');
throw new Error('Failed to merge parts because the union result is null');
}
const bufferedFeature = this.createBufferedFeature(mergedFootprint);

return {
fileName: fileName,
tilesPath: tilesPath,
footprint: mergedFootprint,
extent: bbox(mergedFootprint),
footprint: bufferedFeature,
extent: bbox(bufferedFeature),
};
}

//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, radiusBuffer: this.radiusBuffer });

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.radiusBuffer, { units: this.radiusBufferUnits });

if (bufferInFeature === undefined) {
const errorMsg = 'Failed to buffer In feature because the result is undefined';
logger.error({ errorMsg });
throw new Error(errorMsg);
}

logger.debug({ msg: 'Successfully created buffered feature' });
return bufferInFeature;
}

private async *createTasksForPart(
part: UnifiedPart,
zoom: number,
Expand Down
2 changes: 1 addition & 1 deletion tests/configurations/unit/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
branches: 80,
functions: 80,
lines: 80,
statements: -10,
statements: -12,
},
},
};

0 comments on commit 763d95d

Please sign in to comment.