Search in sources :

Example 16 with Point

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

the class AttributeConventionTest method testGetCrsCharacteristic.

/**
 * Tests {@code AttributeConvention.characterizedByCRS(IdentifiedType)} and
 * {@code AttributeConvention.getCRSCharacteristic(Property)} methods.
 */
@Test
public void testGetCrsCharacteristic() {
    final Map<String, ?> properties = Collections.singletonMap(DefaultAttributeType.NAME_KEY, "geometry");
    DefaultAttributeType<Point> type = new DefaultAttributeType<>(properties, Point.class, 1, 1, null);
    assertFalse("characterizedByCRS", AttributeConvention.characterizedByCRS(type));
    assertNull("getCRSCharacteristic", AttributeConvention.getCRSCharacteristic(type.newInstance()));
    /*
         * Creates an attribute associated to an attribute (i.e. a "characteristic") for storing
         * the Coordinate Reference System of the "geometry" attribute. Then test again.
         */
    final DefaultAttributeType<CoordinateReferenceSystem> characteristic = new DefaultAttributeType<>(Collections.singletonMap(DefaultAttributeType.NAME_KEY, AttributeConvention.CRS_CHARACTERISTIC), CoordinateReferenceSystem.class, 1, 1, HardCodedCRS.WGS84);
    type = new DefaultAttributeType<>(properties, Point.class, 1, 1, null, characteristic);
    assertTrue("characterizedByCRS", AttributeConvention.characterizedByCRS(type));
    assertEquals(HardCodedCRS.WGS84, AttributeConvention.getCRSCharacteristic(type.newInstance()));
    assertEquals(HardCodedCRS.WGS84, AttributeConvention.getCRSCharacteristic(null, type));
    /*
         * Test again AttributeConvention.getCRSCharacteristic(…, PropertyType), but following link.
         */
    final AbstractOperation link = FeatureOperations.link(Collections.singletonMap(DefaultAttributeType.NAME_KEY, "geom"), type);
    final DefaultFeatureType feat = new DefaultFeatureType(Collections.singletonMap(DefaultAttributeType.NAME_KEY, "feat"), false, null, type, link);
    assertEquals(HardCodedCRS.WGS84, AttributeConvention.getCRSCharacteristic(feat, link));
    assertNull(AttributeConvention.getCRSCharacteristic(null, link));
}
Also used : AbstractOperation(org.apache.sis.feature.AbstractOperation) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) DefaultAttributeType(org.apache.sis.feature.DefaultAttributeType) Point(com.esri.core.geometry.Point) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 17 with Point

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

the class ESRI method tryMergePolylines.

/**
 * Merges a sequence of points or paths if the first instance is an implementation of this library.
 *
 * @throws ClassCastException if an element in the iterator is not a JTS geometry.
 */
@Override
final Geometry tryMergePolylines(Object next, final Iterator<?> polylines) {
    if (!(next instanceof MultiPath || next instanceof Point)) {
        return null;
    }
    final Polyline path = new Polyline();
    boolean lineTo = false;
    for (; ; next = polylines.next()) {
        if (next != null) {
            if (next instanceof Point) {
                final double x = ((Point) next).getX();
                final double y = ((Point) next).getY();
                if (Double.isNaN(x) || Double.isNaN(y)) {
                    lineTo = false;
                } else if (lineTo) {
                    path.lineTo(x, y);
                } else {
                    path.startPath(x, y);
                    lineTo = true;
                }
            } else {
                path.add((MultiPath) next, false);
                lineTo = false;
            }
        }
        if (!polylines.hasNext()) {
            // to skip this condition during the first iteration.
            break;
        }
    }
    return path;
}
Also used : MultiPath(com.esri.core.geometry.MultiPath) Polyline(com.esri.core.geometry.Polyline) Point(com.esri.core.geometry.Point)

Example 18 with Point

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

the class ReaderTest method verifyTrack.

/**
 * Verifies property values for the given track.
 *
 * @param  f         the track to verify.
 * @param  v11       {@code true} for GPX 1.1, or {@code false} for GPX 1.0.
 * @param  numLinks  expected number of links.
 */
@SuppressWarnings("fallthrough")
private static void verifyTrack(final AbstractFeature f, final boolean v11, final int numLinks) {
    assertEquals("name", "Track name", f.getPropertyValue("name"));
    assertEquals("cmt", "Track comment", f.getPropertyValue("cmt"));
    assertEquals("desc", "Track description", f.getPropertyValue("desc"));
    assertEquals("src", "Track source", f.getPropertyValue("src"));
    assertEquals("type", v11 ? "Track type" : null, f.getPropertyValue("type"));
    assertEquals("number", 7, f.getPropertyValue("number"));
    final List<?> links = (List<?>) f.getPropertyValue("link");
    assertEquals("links.size()", numLinks, links.size());
    switch(numLinks) {
        // Fallthrough everywhere.
        default:
        case 3:
            assertStringEquals("http://track-address3.org", links.get(2));
        case 2:
            assertStringEquals("http://track-address2.org", links.get(1));
        case 1:
            assertStringEquals("http://track-address1.org", links.get(0));
        case 0:
            break;
    }
    final List<?> segments = (List<?>) f.getPropertyValue("trkseg");
    assertEquals("segments.size()", 2, segments.size());
    final AbstractFeature seg1 = (AbstractFeature) segments.get(0);
    final AbstractFeature seg2 = (AbstractFeature) segments.get(1);
    final List<?> points = (List<?>) seg1.getPropertyValue("trkpt");
    assertEquals("points.size()", 3, points.size());
    verifyPoint((AbstractFeature) points.get(0), 0, v11);
    verifyPoint((AbstractFeature) points.get(1), 1, v11);
    verifyPoint((AbstractFeature) points.get(2), 2, v11);
    assertTrue(((Collection<?>) seg2.getPropertyValue("trkpt")).isEmpty());
    final Polyline p = (Polyline) f.getPropertyValue("sis:geometry");
    assertEquals("pointCount", 3, p.getPointCount());
    assertEquals("point(0)", new Point(15, 10), p.getPoint(0));
    assertEquals("point(1)", new Point(25, 20), p.getPoint(1));
    assertEquals("point(2)", new Point(35, 30), p.getPoint(2));
    assertEnvelopeEquals(15, 35, 10, 30, (Envelope) f.getPropertyValue("sis:envelope"));
}
Also used : Polyline(com.esri.core.geometry.Polyline) AbstractFeature(org.apache.sis.feature.AbstractFeature) List(java.util.List) Point(com.esri.core.geometry.Point)

Example 19 with Point

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

the class ReaderTest method verifyRoute.

/**
 * Verifies property values for the given route.
 *
 * @param  f         the route to verify.
 * @param  v11       {@code true} for GPX 1.1, or {@code false} for GPX 1.0.
 * @param  numLinks  expected number of links.
 */
@SuppressWarnings("fallthrough")
private static void verifyRoute(final AbstractFeature f, final boolean v11, final int numLinks) {
    assertEquals("name", "Route name", f.getPropertyValue("name"));
    assertEquals("cmt", "Route comment", f.getPropertyValue("cmt"));
    assertEquals("desc", "Route description", f.getPropertyValue("desc"));
    assertEquals("src", "Route source", f.getPropertyValue("src"));
    assertEquals("type", v11 ? "Route type" : null, f.getPropertyValue("type"));
    assertEquals("number", 7, f.getPropertyValue("number"));
    final List<?> links = (List<?>) f.getPropertyValue("link");
    assertEquals("links.size()", numLinks, links.size());
    switch(numLinks) {
        // Fallthrough everywhere.
        default:
        case 3:
            assertStringEquals("http://route-address3.org", links.get(2));
        case 2:
            assertStringEquals("http://route-address2.org", links.get(1));
        case 1:
            assertStringEquals("http://route-address1.org", links.get(0));
        case 0:
            break;
    }
    final List<?> points = (List<?>) f.getPropertyValue("rtept");
    assertEquals("points.size()", 3, points.size());
    verifyPoint((AbstractFeature) points.get(0), 0, v11);
    verifyPoint((AbstractFeature) points.get(1), 1, v11);
    verifyPoint((AbstractFeature) points.get(2), 2, v11);
    final Polyline p = (Polyline) f.getPropertyValue("sis:geometry");
    assertEquals("pointCount", 3, p.getPointCount());
    assertEquals("point(0)", new Point(15, 10), p.getPoint(0));
    assertEquals("point(1)", new Point(25, 20), p.getPoint(1));
    assertEquals("point(2)", new Point(35, 30), p.getPoint(2));
    assertEnvelopeEquals(15, 35, 10, 30, (Envelope) f.getPropertyValue("sis:envelope"));
}
Also used : Polyline(com.esri.core.geometry.Polyline) List(java.util.List) Point(com.esri.core.geometry.Point)

Example 20 with Point

use of com.esri.core.geometry.Point 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

Point (com.esri.core.geometry.Point)33 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)13 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)7 Polyline (com.esri.core.geometry.Polyline)6 Description (com.facebook.presto.spi.function.Description)6 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 SqlType (com.facebook.presto.spi.function.SqlType)6 Polygon (com.esri.core.geometry.Polygon)4 GeometryUtils.createJtsEmptyPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint)4 GeometryUtils.createJtsMultiPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint)4 GeometryUtils.createJtsPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsPoint)4 SqlNullable (com.facebook.presto.spi.function.SqlNullable)4 Test (org.testng.annotations.Test)4 Geometry (com.esri.core.geometry.Geometry)3 Line (com.esri.core.geometry.Line)3 MultiPath (com.esri.core.geometry.MultiPath)3 OGCPolygon (com.esri.core.geometry.ogc.OGCPolygon)3 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)3 CartesianPoint (com.facebook.presto.geospatial.SphericalGeographyUtils.CartesianPoint)3 PrestoException (com.facebook.presto.spi.PrestoException)3