Search in sources :

Example 11 with Intersects

use of org.opengis.filter.spatial.Intersects in project ddf by codice.

the class OpenSearchFilterVisitorTest method testIntersectsNullNest.

@Test
public void testIntersectsNullNest() {
    Intersects intersectsFilter = (Intersects) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).intersecting().wkt(WKT_POLYGON);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(intersectsFilter, openSearchFilterVisitorObject);
    assertThat(result.getGeometrySearches(), contains(hasToString(is(WKT_POLYGON))));
}
Also used : Intersects(org.opengis.filter.spatial.Intersects) Test(org.junit.Test)

Example 12 with Intersects

use of org.opengis.filter.spatial.Intersects in project ddf by codice.

the class OpenSearchFilterVisitorTest method testMultipleSpatialFilters.

@Test
public void testMultipleSpatialFilters() {
    final double pointRadiusFilter1Radius = 4;
    final DWithin pointRadiusFilter1 = (DWithin) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).is().withinBuffer().wkt(WKT_POINT, pointRadiusFilter1Radius);
    final DWithin pointRadiusFilter1Duplicate = (DWithin) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).is().withinBuffer().wkt(WKT_POINT, pointRadiusFilter1Radius);
    final double pointRadiusFilter2Radius = pointRadiusFilter1Radius + 1;
    final DWithin pointRadiusFilter2 = (DWithin) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).is().withinBuffer().wkt(WKT_POINT, pointRadiusFilter2Radius);
    final Contains polygonFilter1 = (Contains) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).containing().wkt(WKT_POLYGON);
    final Intersects polygonFilter1Duplicate = (Intersects) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).intersecting().wkt(WKT_POLYGON);
    final String anotherWktPolygon = "POLYGON ((1.2 1.2, 1.2 2.2, 2.2 2.2, 2.2 1.2, 1.2 1.2))";
    final Intersects polygonFilter2 = (Intersects) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).intersecting().wkt(anotherWktPolygon);
    final Or orFilter = geotoolsFilterBuilder.anyOf(pointRadiusFilter1, pointRadiusFilter1Duplicate, pointRadiusFilter2, geotoolsFilterBuilder.allOf(polygonFilter1, polygonFilter1Duplicate, polygonFilter2));
    final OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    openSearchFilterVisitorObject.setCurrentNest(NestedTypes.OR);
    final OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(orFilter, openSearchFilterVisitorObject);
    final Queue<PointRadius> pointRadiusSearches = result.getPointRadiusSearches();
    assertThat("The OpenSearchFilterVisitorObject should contain two point-radius searches from the two unique point-radius filters in the OR filter.", pointRadiusSearches, hasSize(2));
    assertThat("The OpenSearchFilterVisitorObject should contain the point-radius searches in the order that they appear in the OR filter.", pointRadiusSearches, contains(allOf(hasProperty("lon", is(WKT_LON)), hasProperty("lat", is(WKT_LAT)), hasProperty("radius", is(pointRadiusFilter1Radius))), allOf(hasProperty("lon", is(WKT_LON)), hasProperty("lat", is(WKT_LAT)), hasProperty("radius", is(pointRadiusFilter2Radius)))));
    final Queue<Geometry> geometrySearches = result.getGeometrySearches();
    assertThat("The OpenSearchFilterVisitorObject should contain contain two geometry searches from the two unique geometry filters in the OR filter.", geometrySearches, hasSize(2));
    assertThat("The OpenSearchFilterVisitorObject should contain contain the geometry searches in the order that they appear in the OR filter.", geometrySearches, contains(hasToString(is(WKT_POLYGON)), hasToString(is(anotherWktPolygon))));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Or(org.opengis.filter.Or) DWithin(org.opengis.filter.spatial.DWithin) Intersects(org.opengis.filter.spatial.Intersects) Contains(org.opengis.filter.spatial.Contains) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Test(org.junit.Test)

Example 13 with Intersects

use of org.opengis.filter.spatial.Intersects in project ddf by codice.

the class OpenSearchFilterVisitorTest method testIntersectsWithPoint.

@Test
public void testIntersectsWithPoint() {
    Intersects intersectsFilter = (Intersects) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).intersecting().wkt(WKT_POINT);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    openSearchFilterVisitorObject.setCurrentNest(NestedTypes.OR);
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(intersectsFilter, openSearchFilterVisitorObject);
    assertThat(result.getPointRadiusSearches(), is(empty()));
    assertThat(result.getGeometrySearches(), contains(hasToString(is(WKT_POINT))));
}
Also used : Intersects(org.opengis.filter.spatial.Intersects) Test(org.junit.Test)

Example 14 with Intersects

use of org.opengis.filter.spatial.Intersects 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 15 with Intersects

use of org.opengis.filter.spatial.Intersects in project ddf by codice.

the class CswRecordMapperFilterVisitorTest method testIntersectsUtm.

@Test
public void testIntersectsUtm() throws FactoryException, TransformException {
    double lon = 33.45;
    double lat = 25.22;
    double easting = 545328.48;
    double northing = 2789384.24;
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32636");
    GeometryFactory geoFactory = new GeometryFactory();
    Geometry utmPoint = geoFactory.createPoint(new Coordinate(easting, northing));
    utmPoint.setUserData(sourceCRS);
    Expression pt1 = factory.literal(geoFactory.createPoint(new Coordinate(1, 2)));
    Expression pt2 = factory.literal(utmPoint);
    Intersects filter = factory.intersects(pt1, pt2);
    visitor.visit(filter, null);
    assertThat(pt2, instanceOf(Literal.class));
    Literal literalExpression = (Literal) pt2;
    assertThat(literalExpression.getValue(), instanceOf(Geometry.class));
    Geometry geometry = (Geometry) literalExpression.getValue();
    assertThat(geometry.getCoordinates()[0].x, closeTo(lon, .00001));
    assertThat(geometry.getCoordinates()[0].y, closeTo(lat, .00001));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Expression(org.opengis.filter.expression.Expression) Intersects(org.opengis.filter.spatial.Intersects) Literal(org.opengis.filter.expression.Literal) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Aggregations

Intersects (org.opengis.filter.spatial.Intersects)15 Test (org.junit.Test)14 Literal (org.opengis.filter.expression.Literal)3 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)2 DefaultFilterVisitor (org.geotools.filter.visitor.DefaultFilterVisitor)2 Geometry (org.locationtech.jts.geom.Geometry)2 Filter (org.opengis.filter.Filter)2 Expression (org.opengis.filter.expression.Expression)2 Contains (org.opengis.filter.spatial.Contains)2 DWithin (org.opengis.filter.spatial.DWithin)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)1 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BBoxSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter)1