Search in sources :

Example 1 with JTSGeometryWrapper

use of ddf.catalog.impl.filter.JTSGeometryWrapper in project ddf by codice.

the class GeotoolsBuilder method toGeometry.

public Geometry toGeometry(String wkt) {
    Geometry geometry = null;
    try {
        if (wkt.toLowerCase(Locale.US).startsWith("multi") || wkt.toLowerCase(Locale.US).trim().indexOf("geometrycollection") != -1) {
            // WKTParser does not currently support MultiPolygon,
            // MultiLineString, or MultiPoint
            org.locationtech.jts.geom.Geometry geo = reader.read(wkt);
            geometry = new JTSGeometryWrapper(geo);
        } else {
            geometry = parser.parse(wkt);
        }
    } catch (ParseException | java.text.ParseException e) {
        LOGGER.debug("Unable to compute geometry for WKT = {}", wkt, e);
    }
    return geometry;
}
Also used : Geometry(org.opengis.geometry.Geometry) JTSGeometryWrapper(ddf.catalog.impl.filter.JTSGeometryWrapper) ParseException(org.locationtech.jts.io.ParseException)

Example 2 with JTSGeometryWrapper

use of ddf.catalog.impl.filter.JTSGeometryWrapper in project ddf by codice.

the class FilterAdapterTest method testSpatialWrappedGeometry.

@Test
public void testSpatialWrappedGeometry() throws org.locationtech.jts.io.ParseException {
    WKTReader reader = new WKTReader();
    org.locationtech.jts.geom.Geometry geo = reader.read(MULTIPOLYGON_WKT);
    Geometry geometry = new JTSGeometryWrapper(geo);
    assertFilterEquals("beyond(Test,wkt(" + MULTIPOLYGON_WKT + "),10.0)", FF.beyond(TEST_PROPERTY_VALUE, geometry, DISTANCE_10, UomOgcMapping.METRE.name()));
    assertFilterEquals("beyond(Test,wkt(" + MULTIPOLYGON_WKT + "),0.001)", FF.beyond(TEST_PROPERTY_VALUE, geometry, DISTANCE_001, UomOgcMapping.METRE.name()));
    assertFilterEquals("contains(Test,wkt(" + MULTIPOLYGON_WKT + "))", FF.contains(TEST_PROPERTY_VALUE, geometry));
    assertFilterEquals("dwithin(Test,wkt(" + MULTIPOLYGON_WKT + "),10.0)", FF.dwithin(TEST_PROPERTY_VALUE, geometry, DISTANCE_10, UomOgcMapping.METRE.name()));
    assertFilterEquals("dwithin(Test,wkt(" + MULTIPOLYGON_WKT + "),0.001)", FF.dwithin(TEST_PROPERTY_VALUE, geometry, DISTANCE_001, UomOgcMapping.METRE.name()));
    assertFilterEquals("intersects(Test,wkt(" + MULTIPOLYGON_WKT + "))", FF.intersects(TEST_PROPERTY_VALUE, geometry));
    assertFilterEquals("within(Test,wkt(" + MULTIPOLYGON_WKT + "))", FF.within(TEST_PROPERTY_VALUE, geometry));
}
Also used : Geometry(org.opengis.geometry.Geometry) JTSGeometryWrapper(ddf.catalog.impl.filter.JTSGeometryWrapper) WKTReader(org.locationtech.jts.io.WKTReader) Test(org.junit.Test)

Aggregations

JTSGeometryWrapper (ddf.catalog.impl.filter.JTSGeometryWrapper)2 Geometry (org.opengis.geometry.Geometry)2 Test (org.junit.Test)1 ParseException (org.locationtech.jts.io.ParseException)1 WKTReader (org.locationtech.jts.io.WKTReader)1