Java Code Examples for com.esri.core.geometry.ogc.OGCGeometry#getEsriGeometryCursor()

The following examples show how to use com.esri.core.geometry.ogc.OGCGeometry#getEsriGeometryCursor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: presto   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
@Description("Returns the 2D Euclidean area of a geometry")
@ScalarFunction("ST_Area")
@SqlType(DOUBLE)
public static double stArea(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    OGCGeometry geometry = deserialize(input);

    // The Esri geometry library does not support area for geometry collections. We compute the area
    // of collections by summing the area of the individual components.
    GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType());
    if (type == GeometryType.GEOMETRY_COLLECTION) {
        double area = 0.0;
        GeometryCursor cursor = geometry.getEsriGeometryCursor();
        while (true) {
            com.esri.core.geometry.Geometry esriGeometry = cursor.next();
            if (esriGeometry == null) {
                return area;
            }

            area += esriGeometry.calculateArea2D();
        }
    }
    return geometry.getEsriGeometry().calculateArea2D();
}
 
Example 2
Source Project: presto   File: GeometryUtils.java    License: Apache License 2.0 6 votes vote down vote up
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();
        }
    }
}
 
Example 3
private static void accelerateGeometry(OGCGeometry ogcGeometry, Operator relateOperator)
{
    // Recurse into GeometryCollections
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    while (true) {
        com.esri.core.geometry.Geometry esriGeometry = cursor.next();
        if (esriGeometry == null) {
            break;
        }
        relateOperator.accelerateGeometry(esriGeometry, null, Geometry.GeometryAccelerationDegree.enumMild);
    }
}
 
Example 4
Source Project: presto   File: GeoFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Description("Converts a Geometry object to a SphericalGeography object")
@ScalarFunction("to_spherical_geography")
@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME)
public static Slice toSphericalGeography(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    // "every point in input is in range" <=> "the envelope of input is in range"
    Envelope envelope = deserializeEnvelope(input);
    if (!envelope.isEmpty()) {
        checkLatitude(envelope.getYMin());
        checkLatitude(envelope.getYMax());
        checkLongitude(envelope.getXMin());
        checkLongitude(envelope.getXMax());
    }
    OGCGeometry geometry = deserialize(input);
    if (geometry.is3D()) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert 3D geometry to a spherical geography");
    }

    GeometryCursor cursor = geometry.getEsriGeometryCursor();
    while (true) {
        com.esri.core.geometry.Geometry subGeometry = cursor.next();
        if (subGeometry == null) {
            break;
        }

        if (!GEOMETRY_TYPES_FOR_SPHERICAL_GEOGRAPHY.contains(subGeometry.getType())) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert geometry of this type to spherical geography: " + subGeometry.getType());
        }
    }

    return input;
}
 
Example 5
Source Project: presto   File: GeometryUtils.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 6
Source Project: presto   File: GeometryUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean disjoint(Envelope envelope, OGCGeometry ogcGeometry)
{
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    while (true) {
        Geometry geometry = cursor.next();
        if (geometry == null) {
            return true;
        }

        if (!GeometryEngine.disjoint(geometry, envelope, null)) {
            return false;
        }
    }
}
 
Example 7
Source Project: presto   File: GeometryUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean contains(OGCGeometry ogcGeometry, Envelope envelope)
{
    GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor();
    while (true) {
        Geometry geometry = cursor.next();
        if (geometry == null) {
            return false;
        }

        if (GeometryEngine.contains(geometry, envelope, null)) {
            return true;
        }
    }
}