Search in sources :

Example 1 with PointImpl

use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl 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 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() {
    String lon = "10";
    String lat = "20";
    String radius = "5000";
    OpenSearchQuery query = new OpenSearchQuery(0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addPointRadiusSpatialFilter(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) PolygonSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter) 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 3 with PointImpl

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

the class OpenSearchFilterVisitor method buildPointRadiusSearch.

protected static void buildPointRadiusSearch(DWithin 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("The OpenSearch Source 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();
    double distance = filter.getDistance();
    final double radiusRangeLowerBound = 0;
    if (distance <= radiusRangeLowerBound) {
        LOGGER.debug("Radius must be greater than {}. Ignoring DWithin filter.", radiusRangeLowerBound);
    } else if (geometryExpression instanceof PointImpl) {
        PointImpl point = (PointImpl) literalWrapper.evaluate(null);
        double[] coords = point.getCentroid().getCoordinate();
        LOGGER.trace("point: coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
        LOGGER.trace("radius = {}", distance);
        openSearchFilterVisitorObject.addPointRadiusSearch(new PointRadius(coords[0], coords[1], distance));
    } else if (geometryExpression instanceof Point) {
        Point point = (Point) literalWrapper.evaluate(null);
        Coordinate coords = point.getCoordinate();
        LOGGER.trace("point: coords.x = {},   coords.y = {}", coords.x, coords.y);
        LOGGER.trace("radius = {}", distance);
        openSearchFilterVisitorObject.addPointRadiusSearch(new PointRadius(coords.x, coords.y, distance));
    } else {
        LOGGER.debug("The OpenSearch Source only supports POINT geometry WKT for DWithin filter, but the geometry is {}.", geometryExpression);
    }
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Literal(org.opengis.filter.expression.Literal) Expression(org.opengis.filter.expression.Expression) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)

Example 4 with PointImpl

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

the class SolrProviderSpatial method pointRadius.

/**
 * Creates a point radius {@link QueryImpl} with units of measurement of meters.
 */
private QueryImpl pointRadius(double x, double y, double distance) {
    double[] coords = { x, y };
    QueryImpl query = new QueryImpl(filterFactory.dwithin(Metacard.ANY_GEO, new PointImpl(new DirectPositionImpl(coords), DefaultGeographicCRS.WGS84), distance, UomOgcMapping.METRE.name()));
    query.setStartIndex(1);
    SortByImpl sortby = new SortByImpl(filterFactory.property(Result.DISTANCE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortby);
    return query;
}
Also used : DirectPositionImpl(org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(org.geotools.filter.SortByImpl) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)

Example 5 with PointImpl

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

the class GazetteerGeoCoderTest method testWithResults.

@Test
public void testWithResults() throws GeoEntryQueryException {
    final List<GeoEntry> topResults = Arrays.asList(GEO_ENTRY_1, GEO_ENTRY_2);
    doReturn(topResults).when(geoEntryQueryable).query("Phoenix", 1);
    final GeoResult geoResult = gazetteerGeoCoder.getLocation("Phoenix");
    assertThat(geoResult.getFullName(), is(equalTo(GEO_ENTRY_1.getName())));
    final Point point = new PointImpl(new DirectPositionImpl(GEO_ENTRY_1.getLongitude(), GEO_ENTRY_1.getLatitude()));
    assertThat(geoResult.getPoint(), is(equalTo(point)));
}
Also used : DirectPositionImpl(org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl) GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) Point(org.opengis.geometry.primitive.Point) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl) Test(org.junit.Test)

Aggregations

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