use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class BingTileUtils method findRawTileCovering.
private static List<BingTile> findRawTileCovering(OGCGeometry ogcGeometry, int maxZoom) {
Envelope envelope = getEnvelope(ogcGeometry);
Optional<List<BingTile>> trivialResult = handleTrivialCases(envelope, maxZoom);
if (trivialResult.isPresent()) {
return trivialResult.get();
}
accelerateGeometry(ogcGeometry, OperatorIntersects.local(), Geometry.GeometryAccelerationDegree.enumMedium);
Deque<TilingEntry> stack = new ArrayDeque<>();
Consumer<BingTile> addIntersecting = tile -> {
TilingEntry tilingEntry = new TilingEntry(tile);
if (satisfiesTileEdgeCondition(envelope, tilingEntry) && ogcGeometry.intersects(tilingEntry.polygon)) {
stack.push(tilingEntry);
}
};
// Populate with initial tiles. Since there aren't many low zoom tiles,
// and throwing away totally disjoint ones is cheap (envelope check),
// we might as well start comprehensively.
ImmutableList.of(BingTile.fromCoordinates(0, 0, 1), BingTile.fromCoordinates(0, 1, 1), BingTile.fromCoordinates(1, 0, 1), BingTile.fromCoordinates(1, 1, 1)).forEach(addIntersecting);
List<BingTile> outputTiles = new ArrayList<>();
while (!stack.isEmpty()) {
TilingEntry entry = stack.pop();
if (entry.tile.getZoomLevel() == maxZoom || ogcGeometry.contains(entry.polygon)) {
outputTiles.add(entry.tile);
} else {
entry.tile.findChildren().forEach(addIntersecting);
checkCondition(outputTiles.size() + stack.size() <= MAX_COVERING_COUNT, "The zoom level is too high or the geometry is too large to compute a set " + "of covering Bing tiles. Please use a lower zoom level, or tile only a section " + "of the geometry.");
}
}
return outputTiles;
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class GeometryUtils method getEnvelope.
public static Envelope getEnvelope(OGCGeometry ogcGeometry) {
GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
Envelope overallEnvelope = new Envelope();
while (true) {
Geometry geometry = cursor.next();
if (geometry == null) {
return overallEnvelope;
}
Envelope envelope = new Envelope();
geometry.queryEnvelope(envelope);
overallEnvelope.merge(envelope);
}
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class EsriGeometrySerde method getSimpleGeometryEnvelope.
private static Envelope getSimpleGeometryEnvelope(BasicSliceInput input, int length) {
// skip type injected by esri
input.readInt();
Envelope envelope = readEnvelope(input);
int skipLength = length - (4 * Double.BYTES) - Integer.BYTES;
verify(input.skip(skipLength) == skipLength);
return envelope;
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class EsriGeometrySerde method getGeometryCollectionOverallEnvelope.
private static Envelope getGeometryCollectionOverallEnvelope(BasicSliceInput input) {
Envelope overallEnvelope = new Envelope();
while (input.available() > 0) {
int length = input.readInt() - 1;
GeometrySerializationType type = GeometrySerializationType.getForCode(input.readByte());
Envelope envelope = getEnvelope(input, type, length);
overallEnvelope = merge(overallEnvelope, envelope);
}
return overallEnvelope;
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class TestGeometrySerialization method testDeserializeEnvelope.
@Test
public void testDeserializeEnvelope() {
assertDeserializeEnvelope("MULTIPOINT (20 20, 25 25)", new Envelope(20, 20, 25, 25));
assertDeserializeEnvelope("MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))", new Envelope(1, 1, 5, 4));
assertDeserializeEnvelope("POLYGON ((0 0, 0 4, 4 0))", new Envelope(0, 0, 4, 4));
assertDeserializeEnvelope("MULTIPOLYGON (((0 0 , 0 2, 2 2, 2 0)), ((2 2, 2 4, 4 4, 4 2)))", new Envelope(0, 0, 4, 4));
assertDeserializeEnvelope("GEOMETRYCOLLECTION (POINT (3 7), LINESTRING (4 6, 7 10))", new Envelope(3, 6, 7, 10));
assertDeserializeEnvelope("POLYGON EMPTY", new Envelope());
assertDeserializeEnvelope("POINT (1 2)", new Envelope(1, 2, 1, 2));
assertDeserializeEnvelope("POINT EMPTY", new Envelope());
assertDeserializeEnvelope("GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (2 7), LINESTRING (4 6, 7 10)), POINT (3 7), LINESTRING (4 6, 7 10))", new Envelope(2, 6, 7, 10));
}
Aggregations