Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static Envelope getEnvelope(OGCGeometry ogcGeometry)
}
}

public static boolean disjoint(Envelope envelope, OGCGeometry ogcGeometry)
public static boolean disjoint(Geometry polygon, OGCGeometry ogcGeometry)
{
GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
while (true) {
Expand All @@ -111,13 +111,13 @@ public static boolean disjoint(Envelope envelope, OGCGeometry ogcGeometry)
return true;
}

if (!GeometryEngine.disjoint(geometry, envelope, null)) {
if (!GeometryEngine.disjoint(geometry, polygon, null)) {
return false;
}
}
}

public static boolean contains(OGCGeometry ogcGeometry, Envelope envelope)
public static boolean contains(OGCGeometry ogcGeometry, Geometry polygon)
{
GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
while (true) {
Expand All @@ -126,7 +126,7 @@ public static boolean contains(OGCGeometry ogcGeometry, Envelope envelope)
return false;
}

if (GeometryEngine.contains(geometry, envelope, null)) {
if (GeometryEngine.contains(geometry, polygon, null)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.plugin.geospatial;

import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.ogc.OGCGeometry;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -377,7 +378,7 @@ public static Block geometryToBingTiles(@SqlType(StandardTypes.GEOMETRY) Slice i
for (int x = leftUpperTile.getX(); x <= rightLowerTile.getX(); x++) {
for (int y = leftUpperTile.getY(); y <= rightLowerTile.getY(); y++) {
BingTile tile = BingTile.fromCoordinates(x, y, zoomLevel);
if (pointOrRectangle || !disjoint(tileToEnvelope(tile), ogcGeometry)) {
if (pointOrRectangle || !disjoint(tileToGeometry(tile), ogcGeometry)) {
BIGINT.writeLong(blockBuilder, tile.encode());
}
}
Expand Down Expand Up @@ -533,15 +534,15 @@ private static void appendIntersectingSubtiles(
int tileZoomLevel = tile.getZoomLevel();
checkArgument(tileZoomLevel <= zoomLevel);

Envelope tileEnvelope = tileToEnvelope(tile);
Geometry tileGeometry = tileToGeometry(tile);
if (tileZoomLevel == zoomLevel) {
if (!disjoint(tileEnvelope, ogcGeometry)) {
if (!disjoint(tileGeometry, ogcGeometry)) {
BIGINT.writeLong(blockBuilder, tile.encode());
}
return;
}

if (contains(ogcGeometry, tileEnvelope)) {
if (contains(ogcGeometry, tileGeometry)) {
int subTileCount = 1 << (zoomLevel - tileZoomLevel);
int minX = subTileCount * tile.getX();
int minY = subTileCount * tile.getY();
Expand All @@ -553,7 +554,7 @@ private static void appendIntersectingSubtiles(
return;
}

if (disjoint(tileEnvelope, ogcGeometry)) {
if (disjoint(tileGeometry, ogcGeometry)) {
return;
}

Expand Down Expand Up @@ -637,6 +638,13 @@ private static Envelope tileToEnvelope(BingTile tile)
return new Envelope(upperLeftCorner.getX(), lowerRightCorner.getY(), lowerRightCorner.getX(), upperLeftCorner.getY());
}

private static Geometry tileToGeometry(BingTile tile)
{
Point upperLeftCorner = tileXYToLatitudeLongitude(tile.getX(), tile.getY(), tile.getZoomLevel());
Point lowerRightCorner = tileXYToLatitudeLongitude(tile.getX() + 1, tile.getY() + 1, tile.getZoomLevel());
return OGCGeometry.createFromEsriGeometry(new Envelope(upperLeftCorner.getX(), lowerRightCorner.getY(), lowerRightCorner.getX(), upperLeftCorner.getY()), null).getEsriGeometry();
}

private static void checkZoomLevel(long zoomLevel)
{
checkCondition(zoomLevel > 0, ZOOM_LEVEL_TOO_SMALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ public void testLargeGeometryToBingTiles()
.binding("geometry", "ST_GeometryFromText('%s')".formatted(wkt))
.binding("zoom", Integer.toString(zoomLevel)))
.isEqualTo(tileCount);
assertThat(assertions.expression("ST_Within(geometry, geometry_union(transform(geometry_to_bing_tiles(geometry, zoom), bing_tile -> bing_tile_polygon(bing_tile))))")
.binding("geometry", "ST_GeometryFromText('%s')".formatted(wkt))
.binding("zoom", Integer.toString(zoomLevel)))
.isEqualTo(true);
}
}

Expand Down
2 changes: 2 additions & 0 deletions plugin/trino-geospatial/src/test/resources/large_polygon.txt

Large diffs are not rendered by default.