Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
"taskBatchSize": {
"__name": "TILES_MERGING_TASK_BATCH_SIZE",
"__format": "number"
},
"radiusBufferCM": {
"__name": "TILES_MERGING_RADIUS_BUFFER_CM",
CL-SHLOMIKONCHA marked this conversation as resolved.
Show resolved Hide resolved
"__format": "number"
}
},
"tilesSeeding": {
Expand Down
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"tilesMerging": {
"type": "tiles-merging",
"tileBatchSize": 10000,
"taskBatchSize": 5
"taskBatchSize": 5,
"radiusBufferCM": 30
},
"tilesSeeding": {
"type": "tiles-seeding",
Expand Down
1 change: 1 addition & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ 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_TASK_BATCH_SIZE: {{ $jobDefinitions.tasks.merge.radiusBufferCM | quote }}
CL-SHLOMIKONCHA marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ jobDefinitions:
type: ""
tileBatchSize: 10000
taskBatchSize: 5
radiusBufferCM: 30
seed:
type: ""
grid: "WorldCRS84"
Expand Down
37 changes: 33 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 } from '@turf/turf';
import { inject, injectable } from 'tsyringe';
import { SERVICES, TilesStorageProvider } from '../../common/constants';
import {
Expand All @@ -29,6 +30,7 @@ export class TileMergeTaskManager {
private readonly tileBatchSize: number;
private readonly taskBatchSize: number;
private readonly taskType: string;
private readonly radiusBufferCM: number;
public constructor(
@inject(SERVICES.LOGGER) private readonly logger: Logger,
@inject(SERVICES.CONFIG) private readonly config: IConfig,
Expand All @@ -40,6 +42,7 @@ 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');
}

public buildTasks(taskBuildParams: MergeTilesTaskParams): AsyncGenerator<MergeTaskParameters, void, void> {
Expand Down Expand Up @@ -215,18 +218,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, radiusBufferCM: this.radiusBufferCM });

const bufferOutFeature = buffer(feature.geometry, this.radiusBufferCM, { units: 'centimeters' });

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' });

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
Loading