Search in sources :

Example 1 with SpatialFilter

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

the class OpenSearchQuery method addSpatialFilter.

private void addSpatialFilter(SpatialFilter spatialFilter) {
    Geometry geometry = spatialFilter.getGeometry();
    if (geometry != null) {
        Filter filter = FILTER_FACTORY.intersects(Metacard.ANY_GEO, geometry);
        LOGGER.debug("Adding spatial filter");
        filters.add(filter);
    }
}
Also used : Geometry(org.opengis.geometry.Geometry) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)

Example 2 with SpatialFilter

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

the class OpenSearchSource method applyFilters.

private void applyFilters(OpenSearchFilterVisitor visitor, WebClient client) {
    TemporalFilter temporalFilter = visitor.getTemporalSearch();
    if (temporalFilter != null) {
        LOGGER.debug("startDate = {}", temporalFilter.getStartDate());
        LOGGER.debug("endDate = {}", temporalFilter.getEndDate());
        OpenSearchSiteUtil.populateTemporal(client, temporalFilter, parameters);
    }
    SpatialFilter spatialFilter = visitor.getSpatialSearch();
    if (spatialFilter != null) {
        if (spatialFilter instanceof SpatialDistanceFilter) {
            try {
                OpenSearchSiteUtil.populateGeospatial(client, (SpatialDistanceFilter) spatialFilter, shouldConvertToBBox, parameters);
            } catch (UnsupportedQueryException e) {
                LOGGER.debug("Problem with populating geospatial criteria. ", e);
            }
        } else {
            try {
                OpenSearchSiteUtil.populateGeospatial(client, spatialFilter, shouldConvertToBBox, parameters);
            } catch (UnsupportedQueryException e) {
                LOGGER.debug("Problem with populating geospatial criteria. ", e);
            }
        }
    }
    if (localQueryOnly) {
        client.replaceQueryParam(URL_SRC_PARAMETER, LOCAL_SEARCH_PARAMETER);
    } else {
        client.replaceQueryParam(URL_SRC_PARAMETER, "");
    }
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter)

Example 3 with SpatialFilter

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

the class MockQuery method addSpatialFilter.

public void addSpatialFilter(String geometryWkt) {
    SpatialFilter spatialFilter = new SpatialFilter(geometryWkt);
    Geometry geometry = spatialFilter.getGeometry();
    if (geometry != null) {
        Filter filter = FILTER_FACTORY.contains(Metacard.ANY_GEO, geometry);
        filters.add(filter);
        this.filter = getFilter();
    }
}
Also used : Geometry(org.opengis.geometry.Geometry) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter)

Example 4 with SpatialFilter

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

the class OpenSearchFilterVisitor method visit.

/**
     * Contains filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Contains filter, Object data) {
    LOGGER.trace("ENTERING: Contains filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // The geometric point is wrapped in a <Literal> element, so have to
        // get geometry expression as literal and then evaluate it to get
        // the geometry.
        // Example:
        // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl@64a7c45e</ogc:Literal>
        Literal literalWrapper = (Literal) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        StringBuffer geometryWkt = new StringBuffer();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
            geometryWkt.append("POLYGON((");
            for (int i = 0; i < coords.length; i++) {
                geometryWkt.append(coords[i].x);
                geometryWkt.append(" ");
                geometryWkt.append(coords[i].y);
                if (i != (coords.length - 1)) {
                    geometryWkt.append(",");
                }
            }
            geometryWkt.append("))");
            this.spatialSearch = new SpatialFilter(geometryWkt.toString());
            LOGGER.debug("geometryWkt = [{}]", geometryWkt.toString());
            filters.add(filter);
        } else {
            LOGGER.debug("Only POLYGON geometry WKT for Contains filter is supported");
        }
    } else {
        LOGGER.debug(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Contains filter");
    return super.visit(filter, data);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)

Example 5 with SpatialFilter

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

the class OpenSearchFilterVisitor method visit.

/**
     * Intersects filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Intersects filter, Object data) {
    LOGGER.trace("ENTERING: Intersects filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // The geometric point is wrapped in a <Literal> element, so have to
        // get geometry expression as literal and then evaluate it to get
        // the geometry.
        // Example:
        // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl@64a7c45e</ogc:Literal>
        Literal literalWrapper = (Literal) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        StringBuffer geometryWkt = new StringBuffer();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
            geometryWkt.append("POLYGON((");
            for (int i = 0; i < coords.length; i++) {
                geometryWkt.append(coords[i].x);
                geometryWkt.append(" ");
                geometryWkt.append(coords[i].y);
                if (i != (coords.length - 1)) {
                    geometryWkt.append(",");
                }
            }
            geometryWkt.append("))");
            this.spatialSearch = new SpatialFilter(geometryWkt.toString());
            LOGGER.debug("geometryWkt = [{}]", geometryWkt.toString());
            filters.add(filter);
        } else {
            LOGGER.debug("Only POLYGON geometry WKT for Intersects filter is supported");
        }
    } else {
        LOGGER.debug(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Intersects filter");
    return super.visit(filter, data);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)

Aggregations

SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)7 SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)3 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)2 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)2 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)2 SurfaceImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)2 Filter (org.opengis.filter.Filter)2 Literal (org.opengis.filter.expression.Literal)2 Geometry (org.opengis.geometry.Geometry)2 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1