Search in sources :

Example 1 with GeometryImpl

use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.

the class OpenSearchQueryTest method testMultipleSpatialFilter.

@Test
public void testMultipleSpatialFilter() {
    OpenSearchQuery query = new OpenSearchQuery(0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addGeometrySpatialFilter(GEOMETRY_WKT);
    query.addPolygonSpatialFilter("30.943,-120.032,35.039,-120.032,35.039,-110.856,30.943,-110.856,30.943,-120.032");
    query.addBBoxSpatialFilter("-120.032,30.943,-110.856,35.039");
    query.addPointRadiusSpatialFilter("117.3425", "33.9283", "5000");
    query.addPolygonSpatialFilter("-30,100,-35,100,-35,110,-30,110,-30,100");
    Filter filter = query.getFilter();
    assertThat(filter, instanceOf(OrImpl.class));
    OrImpl topFilter = (OrImpl) filter;
    List<Filter> spatialFilters = topFilter.getChildren();
    assertThat(spatialFilters.size(), is(5));
    for (Filter spatialFilter : spatialFilters) {
        if (spatialFilter instanceof DWithinImpl) {
            assertThat(spatialFilter, notNullValue());
            DWithinImpl dWithin = (DWithinImpl) spatialFilter;
            assertThat(dWithin.getDistance(), is(5000.0));
            Literal literal = (Literal) dWithin.getExpression2();
            PointImpl point = (PointImpl) literal.getValue();
            String wkt = WKT_WRITER.write(point.getJTSGeometry());
            assertThat(wkt, is(POINT_WKT));
        } else if (spatialFilter instanceof IntersectsImpl) {
            assertThat(spatialFilter, notNullValue());
            IntersectsImpl intersects = (IntersectsImpl) spatialFilter;
            Literal literal = (Literal) intersects.getExpression2();
            Object geometryExpression = literal.getValue();
            if (geometryExpression instanceof SurfaceImpl) {
                SurfaceImpl surface = (SurfaceImpl) literal.getValue();
                String wkt = WKT_WRITER.write(surface.getJTSGeometry());
                assertThat(wkt, anyOf(is(POLYGON_WKT), is(POLYGON_WKT_2)));
            } else if (geometryExpression instanceof GeometryImpl) {
                org.locationtech.jts.geom.Geometry polygon = ((GeometryImpl) geometryExpression).getJTSGeometry();
                assertThat(WKT_WRITER.write(polygon), is(GEOMETRY_WKT));
            }
        }
    }
}
Also used : GeometryImpl(org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl) IntersectsImpl(org.geotools.filter.spatial.IntersectsImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter) Literal(org.opengis.filter.expression.Literal) OrImpl(org.geotools.filter.OrImpl) DWithinImpl(org.geotools.filter.spatial.DWithinImpl) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl) Test(org.junit.Test)

Example 2 with GeometryImpl

use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.

the class GeotoolsFilterAdapterImpl method geometryToWkt.

private String geometryToWkt(Object literal) {
    String wkt;
    // WKT from the getBoundary method
    if (literal instanceof GeometryImpl) {
        GeometryImpl surface = (GeometryImpl) literal;
        org.locationtech.jts.geom.Geometry jtsGeometry = surface.getJTSGeometry();
        wkt = jtsGeometry.toText();
    } else if (literal instanceof org.locationtech.jts.geom.Geometry) {
        org.locationtech.jts.geom.Geometry jtsGeometry = (org.locationtech.jts.geom.Geometry) literal;
        wkt = jtsGeometry.toText();
    } else {
        throw new UnsupportedOperationException("Unsupported implementation of Geometry for spatial filters.");
    }
    return wkt;
}
Also used : GeometryImpl(org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl)

Example 3 with GeometryImpl

use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.

the class OpenSearchQueryTest method testGeometrySpatialFilter.

@Test
public void testGeometrySpatialFilter() {
    OpenSearchQuery query = new OpenSearchQuery(0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addGeometrySpatialFilter(GEOMETRY_WKT);
    Filter filter = query.getFilter();
    assertThat(filter, notNullValue());
    Intersects intersects = (Intersects) filter;
    Literal literalWrapper = (Literal) intersects.getExpression2();
    Object geometryExpression = literalWrapper.getValue();
    assertThat(geometryExpression, instanceOf(GeometryImpl.class));
    org.locationtech.jts.geom.Geometry polygon = ((GeometryImpl) geometryExpression).getJTSGeometry();
    assertThat(WKT_WRITER.write(polygon), is(GEOMETRY_WKT));
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter) Intersects(org.opengis.filter.spatial.Intersects) Literal(org.opengis.filter.expression.Literal) GeometryImpl(org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl) Test(org.junit.Test)

Example 4 with GeometryImpl

use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.

the class OpenSearchFilterVisitor method buildGeometrySearch.

protected static void buildGeometrySearch(BinarySpatialOperator filter, Object data) {
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = getOpenSearchFilterVisitorObjectFromData(data);
    if (openSearchFilterVisitorObject == null) {
        return;
    }
    if (NestedTypes.NOT.equals(openSearchFilterVisitorObject.getCurrentNest())) {
        LOGGER.debug(NOT_OPERATOR_UNSUPPORTED_MSG);
        return;
    }
    final org.opengis.filter.expression.Expression expression1 = filter.getExpression1();
    final String expectedSpatialSearchTerm = OpenSearchConstants.SUPPORTED_SPATIAL_SEARCH_TERM;
    if (!expectedSpatialSearchTerm.equals(expression1.toString())) {
        LOGGER.debug("Opensearch only supports spatial criteria on the term \"{}\", but expression1 is \"{}\". Ignoring filter.", expectedSpatialSearchTerm, expression1);
        return;
    }
    // The geometry is wrapped in a <Literal> element, so have to get the geometry expression as a
    // literal and then evaluate it to get the geometry.
    // Example:
    // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl@dc33f184</ogc:Literal>
    Literal literalWrapper = (Literal) filter.getExpression2();
    Object geometryExpression = literalWrapper.getValue();
    if (geometryExpression instanceof SurfaceImpl) {
        SurfaceImpl surface = (SurfaceImpl) literalWrapper.evaluate(null);
        Geometry polygon = surface.getJTSGeometry();
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof Polygon) {
        Geometry polygon = (Geometry) literalWrapper.evaluate(null);
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof GeometryImpl) {
        Geometry polygon = ((GeometryImpl) geometryExpression).getJTSGeometry();
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof MultiPolygon) {
        Geometry polygon = ((MultiPolygon) geometryExpression);
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof LineString) {
        Geometry polygon = ((LineString) geometryExpression);
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof MultiLineString) {
        Geometry polygon = ((MultiLineString) geometryExpression);
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else {
        LOGGER.debug("Unsupported filter constraint");
    }
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) Expression(org.opengis.filter.expression.Expression) GeometryImpl(org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl) Geometry(org.locationtech.jts.geom.Geometry) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Literal(org.opengis.filter.expression.Literal) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 5 with GeometryImpl

use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.

the class SubscriptionFilterVisitor method getJtsGeometery.

private org.locationtech.jts.geom.Geometry getJtsGeometery(LiteralExpressionImpl geoExpression) {
    org.locationtech.jts.geom.Geometry jtsGeometry;
    if (geoExpression.getValue() instanceof GeometryImpl) {
        GeometryImpl geo = (GeometryImpl) geoExpression.getValue();
        jtsGeometry = geo.getJTSGeometry();
    } else if (geoExpression.getValue() instanceof org.locationtech.jts.geom.Geometry) {
        jtsGeometry = (org.locationtech.jts.geom.Geometry) geoExpression.getValue();
    } else {
        throw new UnsupportedOperationException("Unsupported implementation of Geometry for spatial filters.");
    }
    return jtsGeometry;
}
Also used : GeometryImpl(org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl)

Aggregations

GeometryImpl (org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl)5 Literal (org.opengis.filter.expression.Literal)3 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)2 BBoxSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter)2 PolygonSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter)2 SurfaceImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)2 Test (org.junit.Test)2 Filter (org.opengis.filter.Filter)2 OrImpl (org.geotools.filter.OrImpl)1 DWithinImpl (org.geotools.filter.spatial.DWithinImpl)1 IntersectsImpl (org.geotools.filter.spatial.IntersectsImpl)1 PointImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)1 Geometry (org.locationtech.jts.geom.Geometry)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)1 Polygon (org.locationtech.jts.geom.Polygon)1 Expression (org.opengis.filter.expression.Expression)1 Intersects (org.opengis.filter.spatial.Intersects)1