Search in sources :

Example 1 with SpatialDistanceFilter

use of ddf.catalog.impl.filter.SpatialDistanceFilter 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 2 with SpatialDistanceFilter

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

the class TestOpenSearchSiteUtil method populateNullGeospatial.

/**
     * Verify that passing in null will still remove the parameters from the URL.
     */
@Test
public void populateNullGeospatial() throws Exception {
    SpatialDistanceFilter spatial = null;
    WebClient webClient = WebClient.create(url.toString());
    OpenSearchSiteUtil.populateGeospatial(webClient, spatial, true, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    URI urlStr = webClient.getCurrentURI();
    assertTrue(urlStr.toString().indexOf(OpenSearchSiteUtil.GEO_LAT) == -1);
    assertTrue(urlStr.toString().indexOf(OpenSearchSiteUtil.GEO_LON) == -1);
    assertTrue(urlStr.toString().indexOf(OpenSearchSiteUtil.GEO_RADIUS) == -1);
}
Also used : SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) WebClient(org.apache.cxf.jaxrs.client.WebClient) URI(java.net.URI) Test(org.junit.Test)

Example 3 with SpatialDistanceFilter

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

the class MockQuery method addSpatialDistanceFilter.

public void addSpatialDistanceFilter(String lon, String lat, String radius) {
    SpatialDistanceFilter distanceFilter = new SpatialDistanceFilter(lon, lat, radius);
    Geometry geometry = distanceFilter.getGeometry();
    if (geometry != null) {
        Filter filter = FILTER_FACTORY.dwithin(Metacard.ANY_GEO, geometry, Double.parseDouble(radius), UomOgcMapping.METRE.getSEString());
        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) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter)

Example 4 with SpatialDistanceFilter

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

the class TestOpenSearchSiteUtil method populateLatLonRadGeospatial.

@Test
public void populateLatLonRadGeospatial() throws Exception {
    String lat = "43.25";
    String lon = "-123.45";
    String radius = "10000";
    String wktPoint = "POINT(" + lon + " " + lat + ")";
    SpatialDistanceFilter spatial = new SpatialDistanceFilter(wktPoint, radius);
    WebClient webClient = WebClient.create(url.toString());
    OpenSearchSiteUtil.populateGeospatial(webClient, spatial, false, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    String urlStr = webClient.getCurrentURI().toString();
    assertTrue(urlStr.indexOf(lat) != -1);
    assertTrue(urlStr.indexOf(lon) != -1);
    assertTrue(urlStr.indexOf(radius) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.GEO_LAT) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.GEO_LON) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.GEO_RADIUS) != -1);
    try {
        new URL(urlStr.toString());
    } catch (MalformedURLException mue) {
        fail("URL is not valid: " + mue.getMessage());
    }
    LOGGER.info("URL after lat lon geospatial population: {}", urlStr.toString());
}
Also used : MalformedURLException(java.net.MalformedURLException) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 5 with SpatialDistanceFilter

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

the class OpenSearchQuery method addSpatialDistanceFilter.

public void addSpatialDistanceFilter(String lon, String lat, String radius) {
    SpatialDistanceFilter distanceFilter = new SpatialDistanceFilter(lon, lat, radius);
    Geometry geometry = distanceFilter.getGeometry();
    if (geometry != null) {
        Filter filter = FILTER_FACTORY.dwithin(Metacard.ANY_GEO, geometry, Double.parseDouble(radius), UomOgcMapping.METRE.name());
        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) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter)

Aggregations

SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)7 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)4 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)4 Filter (org.opengis.filter.Filter)3 Geometry (org.opengis.geometry.Geometry)3 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 Test (org.junit.Test)2 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 BBoxSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter)1 PolygonSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter)1 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)1 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)1 PointImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Literal (org.opengis.filter.expression.Literal)1