Search in sources :

Example 6 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 7 with Geometry

use of com.esri.core.geometry.Geometry in project reverse-geocoder-for-geoevent by Esri.

the class ReverseGeocoderProcessor method processGeoEvent.

private GeoEvent processGeoEvent(GeoEvent geoEvent) throws MalformedURLException, JSONException, ConfigurationException, GeoEventDefinitionManagerException, FieldException {
    if (geoEvent.getTrackId() == null || geoEvent.getGeometry() == null) {
        LOGGER.warn("NULL_ERROR: TrackID and/or Geometry is NULL.");
        return null;
    }
    Geometry geom = geoEvent.getGeometry().getGeometry();
    if (geom.isEmpty())
        return geoEvent;
    if (!Geometry.isPoint(geom.getType().value()))
        return geoEvent;
    if (Geometry.isMultiVertex(geom.getType().value()))
        return geoEvent;
    Point point = (Point) geom;
    double lon = point.getX();
    double lat = point.getY();
    int wkid = geoEvent.getGeometry().getSpatialReference().getID();
    // fetch nearest street address (reverse geocode) via ArcGIS Online World GeoCode service
    // The response format. Values: html | json | kmz
    // The default response format is html.
    agolSearchFormat = "json";
    URL agolURL = new URL("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=" + Double.toString(lon) + "," + Double.toString(lat) + "&distance=" + Integer.toString(agolSearchDistance) + "&outSR=" + Integer.toString(wkid) + "&f=" + agolSearchFormat);
    String addressJson = getReverseGeocode(agolURL);
    GeoEvent agolStreetAddress = augmentGeoEventWithAddress(geoEvent, addressJson);
    return agolStreetAddress;
}
Also used : Geometry(com.esri.core.geometry.Geometry) Point(com.esri.core.geometry.Point) Point(com.esri.core.geometry.Point) URL(java.net.URL) GeoEvent(com.esri.ges.core.geoevent.GeoEvent)

Aggregations

Geometry (com.esri.core.geometry.Geometry)7 MapGeometry (com.esri.core.geometry.MapGeometry)4 SpatialReference (com.esri.core.geometry.SpatialReference)2 Envelope2D (com.esri.core.geometry.Envelope2D)1 OperatorBoundary (com.esri.core.geometry.OperatorBoundary)1 Point (com.esri.core.geometry.Point)1 GeoEvent (com.esri.ges.core.geoevent.GeoEvent)1 URL (java.net.URL)1 SemiStrict (org.apache.calcite.linq4j.function.SemiStrict)1 AbstractIdentifiedType (org.apache.sis.feature.AbstractIdentifiedType)1 DefaultFeatureType (org.apache.sis.feature.DefaultFeatureType)1 DefaultFeatureTypeTest (org.apache.sis.feature.DefaultFeatureTypeTest)1 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 Test (org.junit.Test)1