Search in sources :

Example 1 with Geometry

use of org.opengis.geometry.Geometry 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
            com.vividsolutions.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(com.vividsolutions.jts.io.ParseException)

Example 2 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class CopyFilterDelegateTest method testSpatialDWithin.

@Test
public void testSpatialDWithin() {
    Geometry polygonGeometry = wktToGeometry(POLYGON_WKT);
    assertFilterEquals(FF.dwithin(TEST_PROPERTY_VALUE, polygonGeometry, DISTANCE_10, UomOgcMapping.METRE.name()));
}
Also used : Geometry(org.opengis.geometry.Geometry) Test(org.junit.Test)

Example 3 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class CopyFilterDelegateTest method testSpatialBeyond.

@Test
public void testSpatialBeyond() {
    Geometry polygonGeometry = wktToGeometry(POLYGON_WKT);
    assertFilterEquals(FF.beyond(TEST_PROPERTY_VALUE, polygonGeometry, DISTANCE_10, UomOgcMapping.METRE.name()));
}
Also used : Geometry(org.opengis.geometry.Geometry) Test(org.junit.Test)

Example 4 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class FilterBuilderTest method withinGeoTest.

/**
     *
     */
@Test
public void withinGeoTest() {
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.attribute(Metacard.GEOGRAPHY).within().wkt(POINT_WKT);
    filter.accept(new DefaultFilterVisitor() {

        @Override
        public Object visit(Within filter, Object data) {
            Literal literalWrapper = (Literal) filter.getExpression2();
            Geometry geometry = (Geometry) literalWrapper.evaluate(null);
            geometry.getCentroid().getCoordinate();
            return super.visit(filter, data);
        }
    }, null);
}
Also used : Geometry(org.opengis.geometry.Geometry) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Literal(org.opengis.filter.expression.Literal) DWithin(org.opengis.filter.spatial.DWithin) Within(org.opengis.filter.spatial.Within) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 5 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class FilterAdapterTest method testSpatialWrappedGeometry.

@Test
public void testSpatialWrappedGeometry() throws com.vividsolutions.jts.io.ParseException {
    WKTReader reader = new WKTReader();
    com.vividsolutions.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("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("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(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Aggregations

Geometry (org.opengis.geometry.Geometry)28 Test (org.junit.Test)22 Filter (org.opengis.filter.Filter)5 SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)4 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)4 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)4 JTSGeometryWrapper (ddf.catalog.impl.filter.JTSGeometryWrapper)2 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)2 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)2 GeometryBuilder (org.geotools.geometry.GeometryBuilder)2 PrimitiveFactoryImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl)2 WKTParser (org.geotools.geometry.text.WKTParser)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 ParseException (com.vividsolutions.jts.io.ParseException)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)1 ParseException (java.text.ParseException)1 DefaultFilterVisitor (org.geotools.filter.visitor.DefaultFilterVisitor)1 Ignore (org.junit.Ignore)1