use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class TestGeometrySerialization method testEnvelope.
@Test
public void testEnvelope() {
testEnvelopeSerialization(new Envelope());
testEnvelopeSerialization(new Envelope(0, 0, 1, 1));
testEnvelopeSerialization(new Envelope(1, 2, 3, 4));
testEnvelopeSerialization(new Envelope(10101, -2.05, -3e5, 0));
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class TestGeometrySerialization method testDeserializeType.
@Test
public void testDeserializeType() {
assertDeserializeType("POINT (1 2)", POINT);
assertDeserializeType("POINT EMPTY", POINT);
assertDeserializeType("MULTIPOINT (20 20, 25 25)", MULTI_POINT);
assertDeserializeType("MULTIPOINT EMPTY", MULTI_POINT);
assertDeserializeType("LINESTRING (1 1, 5 1, 6 2))", LINE_STRING);
assertDeserializeType("LINESTRING EMPTY", LINE_STRING);
assertDeserializeType("MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))", MULTI_LINE_STRING);
assertDeserializeType("MULTILINESTRING EMPTY", MULTI_LINE_STRING);
assertDeserializeType("POLYGON ((0 0, 0 4, 4 0))", POLYGON);
assertDeserializeType("POLYGON EMPTY", POLYGON);
assertDeserializeType("MULTIPOLYGON (((0 0 , 0 2, 2 2, 2 0)), ((2 2, 2 4, 4 4, 4 2)))", MULTI_POLYGON);
assertDeserializeType("MULTIPOLYGON EMPTY", MULTI_POLYGON);
assertDeserializeType("GEOMETRYCOLLECTION (POINT (3 7), LINESTRING (4 6, 7 10))", GEOMETRY_COLLECTION);
assertDeserializeType("GEOMETRYCOLLECTION EMPTY", GEOMETRY_COLLECTION);
assertEquals(deserializeType(serialize(new Envelope(1, 2, 3, 4))), ENVELOPE);
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class SpatialPartitioningInternalAggregateFunction method input.
@InputFunction
public static void input(SpatialPartitioningState state, @SqlType(GEOMETRY_TYPE_NAME) Slice slice, @SqlType(INTEGER) long partitionCount) {
Envelope envelope = deserializeEnvelope(slice);
if (envelope.isEmpty()) {
return;
}
if (state.getCount() == 0) {
state.setPartitionCount(toIntExact(partitionCount));
state.setSamples(new ArrayList<>());
}
// use reservoir sampling
Rectangle extent = new Rectangle(envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax());
List<Rectangle> samples = state.getSamples();
if (samples.size() <= MAX_SAMPLE_COUNT) {
samples.add(extent);
} else {
long sampleIndex = ThreadLocalRandom.current().nextLong(state.getCount());
if (sampleIndex < MAX_SAMPLE_COUNT) {
samples.set(toIntExact(sampleIndex), extent);
}
}
state.setCount(state.getCount() + 1);
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class BingTileFunctions method appendIntersectingSubtiles.
/**
* Identifies a minimum set of tiles at specified zoom level that cover intersection of the
* specified geometry and a specified tile of the same or lower level. Adds tiles to provided
* BlockBuilder.
*/
private static void appendIntersectingSubtiles(OGCGeometry ogcGeometry, int zoomLevel, BingTile tile, BlockBuilder blockBuilder) {
int tileZoomLevel = tile.getZoomLevel();
checkArgument(tileZoomLevel <= zoomLevel);
Envelope tileEnvelope = tileToEnvelope(tile);
if (tileZoomLevel == zoomLevel) {
if (!disjoint(tileEnvelope, ogcGeometry)) {
BIGINT.writeLong(blockBuilder, tile.encode());
}
return;
}
if (contains(ogcGeometry, tileEnvelope)) {
int subTileCount = 1 << (zoomLevel - tileZoomLevel);
int minX = subTileCount * tile.getX();
int minY = subTileCount * tile.getY();
for (int x = minX; x < minX + subTileCount; x++) {
for (int y = minY; y < minY + subTileCount; y++) {
BIGINT.writeLong(blockBuilder, BingTile.fromCoordinates(x, y, zoomLevel).encode());
}
}
return;
}
if (disjoint(tileEnvelope, ogcGeometry)) {
return;
}
int minX = 2 * tile.getX();
int minY = 2 * tile.getY();
int nextZoomLevel = tileZoomLevel + 1;
verify(nextZoomLevel <= MAX_ZOOM_LEVEL);
for (int x = minX; x < minX + 2; x++) {
for (int y = minY; y < minY + 2; y++) {
appendIntersectingSubtiles(ogcGeometry, zoomLevel, BingTile.fromCoordinates(x, y, nextZoomLevel), blockBuilder);
}
}
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class BingTileFunctions method geometryToBingTiles.
@Description("Given a geometry and a zoom level, returns the minimum set of Bing tiles of that zoom level that fully covers that geometry")
@ScalarFunction("geometry_to_bing_tiles")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block geometryToBingTiles(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(StandardTypes.INTEGER) long zoomLevelInput) {
Envelope envelope = deserializeEnvelope(input);
if (envelope.isEmpty()) {
return EMPTY_TILE_ARRAY;
}
int zoomLevel = toIntExact(zoomLevelInput);
GeometrySerializationType type = deserializeType(input);
List<BingTile> covering;
if (type == GeometrySerializationType.POINT || type == GeometrySerializationType.ENVELOPE) {
covering = findMinimalTileCovering(envelope, zoomLevel);
} else {
OGCGeometry ogcGeometry = deserialize(input);
if (isPointOrRectangle(ogcGeometry, envelope)) {
covering = findMinimalTileCovering(envelope, zoomLevel);
} else {
covering = findMinimalTileCovering(ogcGeometry, zoomLevel);
}
}
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, covering.size());
for (BingTile tile : covering) {
BIGINT.writeLong(blockBuilder, tile.encode());
}
return blockBuilder.build();
}
Aggregations