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))));
}
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))));
}
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))));
}
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));
}
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));
}
Aggregations