Skip to content

Commit

Permalink
Merge pull request #154 from TileDB-Inc/xan/sc-40029/geo-polygon-fix
Browse files Browse the repository at this point in the history
Fix polygons with different coordinate systems
  • Loading branch information
XanthosXanthopoulos authored Jan 26, 2024
2 parents bcdd070 + 188b0ae commit 70eb7e0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
9 changes: 6 additions & 3 deletions packages/core/src/tile/model/geometry/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,12 @@ export class GeometryTile extends Tile<GeometryResponse> {
this.mesh.material!.disableColorWrite = !(

Check warning on line 201 in packages/core/src/tile/model/geometry/geometry.ts

View workflow job for this annotation

GitHub Actions / Test and lint

Forbidden non-null assertion

Check warning on line 201 in packages/core/src/tile/model/geometry/geometry.ts

View workflow job for this annotation

GitHub Actions / Test and lint

Forbidden non-null assertion
updateOptions.style & GeometryStyle.FILLED
);
this.mesh.edgesRenderer!.isEnabled = Boolean(
updateOptions.style & GeometryStyle.OUTLINED
);

if (this.mesh.edgesRenderer) {
this.mesh.edgesRenderer.isEnabled = Boolean(
updateOptions.style & GeometryStyle.OUTLINED
);
}
}

this.mesh.visibility = updateOptions.fillOpacity ?? this.mesh.visibility;
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/tile/model/geometry/geometryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export class GeometryManager extends Manager<GeometryTile> {
continue;
}

this.tileStatus.delete(key);

if (status.state !== TileState.VISIBLE) {
this.workerPool.cancelRequest({
type: RequestType.CANCEL,
Expand All @@ -181,8 +183,6 @@ export class GeometryManager extends Manager<GeometryTile> {
} else if (status.state === TileState.VISIBLE) {
status.tile?.dispose();
}

this.tileStatus.delete(key);
}
}

Expand Down Expand Up @@ -503,6 +503,7 @@ export class GeometryManager extends Manager<GeometryTile> {
geometryCRS: this.metadata.crs,
geotransformCoefficients: this.transformationCoefficients,
metersPerUnit: this.metersPerUnit,
features: this.metadata.features,
nonce: response.nonce
} as GeometryMessage
} as DataRequest);
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/tile/tileImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ export class TileDBTileImageVisualization extends TileDBVisualization {
)
);

await initializeCacheDB([
`${geometryArrayID}_${this.tileSize / 2 ** nativeZoom}`
]);
await initializeCacheDB([`${id}_${this.tileSize / 2 ** nativeZoom}`]);
}
}

Expand Down
20 changes: 16 additions & 4 deletions packages/core/src/tile/worker/loaders/geometryLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export async function geometryRequest(
request.index,
tileSize,
affineMatrix,
request.pad,
request.imageCRS,
request.geometryCRS
);
Expand Down Expand Up @@ -135,6 +136,11 @@ export async function geometryRequest(
vertexMap: new Map<bigint, number[]>()
};

const converter =
request.imageCRS && request.geometryCRS
? proj4(request.geometryCRS, request.imageCRS)
: null;

try {
for await (const result of generator) {
switch (request.geometryAttribute.type) {
Expand All @@ -145,6 +151,7 @@ export async function geometryRequest(
request.features,
request.type,
inv(affineMatrix),
converter,
geometryOutput
);
break;
Expand All @@ -155,6 +162,7 @@ export async function geometryRequest(
request.features,
request.type,
inv(affineMatrix),
converter,
geometryOutput
);
break;
Expand Down Expand Up @@ -242,8 +250,8 @@ function calculateQueryRanges(
let minPoint = matrix([x * tilesize, y * tilesize, 1]);
let maxPoint = matrix([(x + 1) * tilesize, (y + 1) * tilesize, 1]);

minPoint = multiply(minPoint, affineMatrix);
maxPoint = multiply(maxPoint, affineMatrix);
minPoint = multiply(affineMatrix, minPoint);
maxPoint = multiply(affineMatrix, maxPoint);

if (baseCRS && sourceCRS) {
const converter = proj4(baseCRS, sourceCRS);
Expand Down Expand Up @@ -289,6 +297,7 @@ function loadBinaryGeometry(
features: Feature[],
geometryType: string,
affineTransform: Matrix,
converter: any | undefined,
outputGeometry: OutputGeometry
) {
const offsets = data['__offsets'][attributes.geometry.name] as BigUint64Array;
Expand Down Expand Up @@ -353,7 +362,8 @@ function loadBinaryGeometry(
id,
outputGeometry,
featureData,
affineTransform
affineTransform,
converter
);
break;
default:
Expand All @@ -367,6 +377,7 @@ function loadStringGeometry(
features: Feature[],
geometryType: string,
affineTransform: Matrix,
converter: any | undefined,
outputGeometry: OutputGeometry
) {
const wkt = data[attributes.geometry.name] as string[];
Expand Down Expand Up @@ -425,7 +436,8 @@ function loadStringGeometry(
id,
outputGeometry,
featureData,
affineTransform
affineTransform,
converter
);
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/tile/worker/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export function parsePolygon(
}

shape.push(
multiply([point.x, point.y, 1], affineTransform)
multiply(affineTransform, [point.x!, point.y!, 1])
.subset(index([true, true, false]))
.toArray()
.toArray() as number[]
);
}
data.push(shape);
Expand All @@ -85,7 +85,7 @@ export function parsePolygon(
}

hole.push(
multiply([point.x, point.y, 1], affineTransform)
multiply(affineTransform, [point.x, point.y, 1])
.subset(index([true, true, false]))
.toArray()
);
Expand Down

0 comments on commit 70eb7e0

Please sign in to comment.