Search in sources :

Example 11 with Geometry

use of com.esri.core.geometry.Geometry in project sis by apache.

the class ESRI method tryGetEnvelope.

/**
 * If the given object is an ESRI geometry and its envelope is non-empty, returns
 * that envelope as an Apache SIS implementation. Otherwise returns {@code null}.
 *
 * @param  geometry  the geometry from which to get the envelope, or {@code null}.
 * @return the envelope of the given object, or {@code null} if the object is not
 *         a recognized geometry or its envelope is empty.
 */
@Override
final GeneralEnvelope tryGetEnvelope(final Object geometry) {
    if (geometry instanceof Geometry) {
        final Envelope2D bounds = new Envelope2D();
        ((Geometry) geometry).queryEnvelope2D(bounds);
        if (!bounds.isEmpty()) {
            // Test if there is NaN values.
            final GeneralEnvelope env = new GeneralEnvelope(2);
            env.setRange(0, bounds.xmin, bounds.xmax);
            env.setRange(1, bounds.ymin, bounds.ymax);
            return env;
        }
    }
    return null;
}
Also used : Geometry(com.esri.core.geometry.Geometry) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) Envelope2D(com.esri.core.geometry.Envelope2D)

Example 12 with Geometry

use of com.esri.core.geometry.Geometry 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;
}
Also used : StandardTypes(com.facebook.presto.common.type.StandardTypes) Slice(io.airlift.slice.Slice) PriorityQueue(java.util.PriorityQueue) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) PrestoException(com.facebook.presto.spi.PrestoException) Deque(java.util.Deque) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) INVALID_FUNCTION_ARGUMENT(com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT) Point(com.esri.core.geometry.Point) OperatorIntersects(com.esri.core.geometry.OperatorIntersects) Set(java.util.Set) Geometry(com.esri.core.geometry.Geometry) String.format(java.lang.String.format) Consumer(java.util.function.Consumer) List(java.util.List) Envelope(com.esri.core.geometry.Envelope) GeometryUtils.accelerateGeometry(com.facebook.presto.geospatial.GeometryUtils.accelerateGeometry) MAX_ZOOM_LEVEL(com.facebook.presto.plugin.geospatial.BingTile.MAX_ZOOM_LEVEL) Optional(java.util.Optional) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) GeometryUtils.getEnvelope(com.facebook.presto.geospatial.GeometryUtils.getEnvelope) SqlType(com.facebook.presto.spi.function.SqlType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Envelope(com.esri.core.geometry.Envelope) GeometryUtils.getEnvelope(com.facebook.presto.geospatial.GeometryUtils.getEnvelope) ArrayDeque(java.util.ArrayDeque)

Example 13 with Geometry

use of com.esri.core.geometry.Geometry in project presto by prestodb.

the class GeometryUtils method getPointCount.

public static int getPointCount(OGCGeometry ogcGeometry) {
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    int points = 0;
    while (true) {
        com.esri.core.geometry.Geometry geometry = cursor.next();
        if (geometry == null) {
            return points;
        }
        if (geometry.isEmpty()) {
            continue;
        }
        if (geometry instanceof Point) {
            points++;
        } else {
            points += ((MultiVertexGeometry) geometry).getPointCount();
        }
    }
}
Also used : GeometryCursor(com.esri.core.geometry.GeometryCursor) Geometry(com.esri.core.geometry.Geometry) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point)

Example 14 with Geometry

use of com.esri.core.geometry.Geometry 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);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) MultiVertexGeometry(com.esri.core.geometry.MultiVertexGeometry) Geometry(com.esri.core.geometry.Geometry) GeometryCursor(com.esri.core.geometry.GeometryCursor) Envelope(com.esri.core.geometry.Envelope)

Example 15 with Geometry

use of com.esri.core.geometry.Geometry in project drill by apache.

the class ShpBatchReader method next.

@Override
public boolean next() {
    Geometry geom = null;
    while (!rowWriter.isFull()) {
        Object[] dbfRow = dbfReader.nextRecord();
        geom = geomCursor.next();
        if (geom == null) {
            return false;
        }
        processShapefileSet(rowWriter, geomCursor.getGeometryID(), geom, dbfRow);
    }
    return true;
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Geometry(com.esri.core.geometry.Geometry)

Aggregations

Geometry (com.esri.core.geometry.Geometry)16 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)8 Point (com.esri.core.geometry.Point)5 GeometryCursor (com.esri.core.geometry.GeometryCursor)4 MapGeometry (com.esri.core.geometry.MapGeometry)4 Envelope (com.esri.core.geometry.Envelope)3 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)3 MultiPoint (com.esri.core.geometry.MultiPoint)2 MultiVertexGeometry (com.esri.core.geometry.MultiVertexGeometry)2 SpatialReference (com.esri.core.geometry.SpatialReference)2 OGCMultiPoint (com.esri.core.geometry.ogc.OGCMultiPoint)2 PrestoException (com.facebook.presto.spi.PrestoException)2 SqlType (com.facebook.presto.spi.function.SqlType)2 Envelope2D (com.esri.core.geometry.Envelope2D)1 OperatorBoundary (com.esri.core.geometry.OperatorBoundary)1 OperatorIntersects (com.esri.core.geometry.OperatorIntersects)1 GeoEvent (com.esri.ges.core.geoevent.GeoEvent)1 StandardTypes (com.facebook.presto.common.type.StandardTypes)1 GeometryUtils.accelerateGeometry (com.facebook.presto.geospatial.GeometryUtils.accelerateGeometry)1 GeometryUtils.getEnvelope (com.facebook.presto.geospatial.GeometryUtils.getEnvelope)1