Search in sources :

Example 6 with PointImpl

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

the class OpenSearchQueryTest method testSpatialDistanceFilter.

@Test
public void testSpatialDistanceFilter() throws Exception {
    String lon = "10";
    String lat = "20";
    String radius = "5000";
    OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addSpatialDistanceFilter(lon, lat, radius);
    Filter filter = query.getFilter();
    // String filterXml = getFilterAsXml( filter );
    VerificationVisitor verificationVisitor = new VerificationVisitor();
    filter.accept(verificationVisitor, null);
    HashMap<String, FilterStatus> map = (HashMap<String, FilterStatus>) verificationVisitor.getMap();
    List<Filter> filters = getFilters(map, DWithinImpl.class.getName());
    assertEquals(1, filters.size());
    DWithinImpl dwithinFilter = (DWithinImpl) filters.get(0);
    // 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.PointImpl@dc33f184</ogc:Literal>
    Literal literalWrapper = (Literal) dwithinFilter.getExpression2();
    // Luckily we know what type the geometry expression should be, so we can cast it
    PointImpl point = (PointImpl) literalWrapper.evaluate(null);
    double[] coords = point.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
    assertEquals(Double.parseDouble(lon), coords[0], DOUBLE_DELTA);
    assertEquals(Double.parseDouble(lat), coords[1], DOUBLE_DELTA);
    LOGGER.debug("dwithinFilter.getDistance() = {}", dwithinFilter.getDistance());
    assertEquals(Double.parseDouble(radius), dwithinFilter.getDistance(), DOUBLE_DELTA);
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) HashMap(java.util.HashMap) Literal(org.opengis.filter.expression.Literal) DWithinImpl(org.geotools.filter.spatial.DWithinImpl) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl) Test(org.junit.Test)

Example 7 with PointImpl

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

the class OpenSearchFilterVisitor method visit.

/**
     * DWithin filter maps to a Point/Radius distance Spatial search criteria.
     */
@Override
public Object visit(DWithin filter, Object data) {
    LOGGER.trace("ENTERING: DWithin 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.PointImpl@dc33f184</ogc:Literal>
        Literal literalWrapper = (Literal) filter.getExpression2();
        // Luckily we know what type the geometry expression should be, so
        // we
        // can cast it
        PointImpl point = (PointImpl) literalWrapper.evaluate(null);
        double[] coords = point.getCentroid().getCoordinate();
        double distance = filter.getDistance();
        LOGGER.debug("point: coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
        LOGGER.debug("radius = {}", distance);
        this.spatialSearch = new SpatialDistanceFilter(coords[0], coords[1], distance);
        filters.add(filter);
    } else {
        LOGGER.debug(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: DWithin filter");
    return super.visit(filter, data);
}
Also used : PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)

Aggregations

PointImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)7 DirectPositionImpl (org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl)5 Test (org.junit.Test)3 Point (org.opengis.geometry.primitive.Point)3 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 ArrayList (java.util.ArrayList)2 SortByImpl (org.geotools.filter.SortByImpl)2 Filter (org.opengis.filter.Filter)2 Literal (org.opengis.filter.expression.Literal)2 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)1 SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)1 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 HashMap (java.util.HashMap)1 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)1 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)1