use of org.geotools.filter.spatial.IntersectsImpl in project ddf by codice.
the class OpenSearchQueryTest method testBboxSpatialFilter.
@Test
public void testBboxSpatialFilter() throws Exception {
String bboxCorners = "0,10,20,30";
OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
query.addBBoxSpatialFilter(bboxCorners);
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();
printFilterStatusMap(map);
// List<Filter> filters = getFilters( map, ContainsImpl.class.getName() );
List<Filter> filters = getFilters(map, IntersectsImpl.class.getName());
assertEquals(1, filters.size());
// ContainsImpl containsFilter = (ContainsImpl) filters.get( 0 );
IntersectsImpl containsFilter = (IntersectsImpl) 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.SurfaceImpl@64a7c45e</ogc:Literal>
Literal literalWrapper = (Literal) containsFilter.getExpression2();
// Luckily we know what type the geometry expression should be, so we can cast it
SurfaceImpl bbox = (SurfaceImpl) literalWrapper.evaluate(null);
String[] expectedCoords = bboxCorners.split(",");
double[] lowerCornerCoords = bbox.getEnvelope().getLowerCorner().getCoordinate();
LOGGER.debug("lowerCornerCoords: [0] = {}, [1] = {}", lowerCornerCoords[0], lowerCornerCoords[1]);
assertEquals(Double.parseDouble(expectedCoords[0]), lowerCornerCoords[0], DOUBLE_DELTA);
assertEquals(Double.parseDouble(expectedCoords[1]), lowerCornerCoords[1], DOUBLE_DELTA);
double[] upperCornerCoords = bbox.getEnvelope().getUpperCorner().getCoordinate();
LOGGER.debug("upperCornerCoords: [0] = {}, [1] = {}", upperCornerCoords[0], upperCornerCoords[1]);
assertEquals(Double.parseDouble(expectedCoords[2]), upperCornerCoords[0], DOUBLE_DELTA);
assertEquals(Double.parseDouble(expectedCoords[3]), upperCornerCoords[1], DOUBLE_DELTA);
}
use of org.geotools.filter.spatial.IntersectsImpl 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));
}
}
}
}
use of org.geotools.filter.spatial.IntersectsImpl in project ddf by codice.
the class OpenSearchQueryTest method testBboxSpatialFilter.
@Test
public void testBboxSpatialFilter() {
String bboxCorners = "0,10,20,30";
OpenSearchQuery query = new OpenSearchQuery(0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
query.addBBoxSpatialFilter(bboxCorners);
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();
printFilterStatusMap(map);
// List<Filter> filters = getFilters( map, ContainsImpl.class.getName() );
List<Filter> filters = getFilters(map, IntersectsImpl.class.getName());
assertEquals(1, filters.size());
// ContainsImpl containsFilter = (ContainsImpl) filters.get( 0 );
IntersectsImpl containsFilter = (IntersectsImpl) 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.SurfaceImpl@64a7c45e</ogc:Literal>
Literal literalWrapper = (Literal) containsFilter.getExpression2();
// Luckily we know what type the geometry expression should be, so we can cast it
SurfaceImpl bbox = (SurfaceImpl) literalWrapper.evaluate(null);
String[] expectedCoords = bboxCorners.split(",");
double[] lowerCornerCoords = bbox.getEnvelope().getLowerCorner().getCoordinate();
LOGGER.debug("lowerCornerCoords: [0] = {}, [1] = {}", lowerCornerCoords[0], lowerCornerCoords[1]);
assertEquals(Double.parseDouble(expectedCoords[0]), lowerCornerCoords[0], DOUBLE_DELTA);
assertEquals(Double.parseDouble(expectedCoords[1]), lowerCornerCoords[1], DOUBLE_DELTA);
double[] upperCornerCoords = bbox.getEnvelope().getUpperCorner().getCoordinate();
LOGGER.debug("upperCornerCoords: [0] = {}, [1] = {}", upperCornerCoords[0], upperCornerCoords[1]);
assertEquals(Double.parseDouble(expectedCoords[2]), upperCornerCoords[0], DOUBLE_DELTA);
assertEquals(Double.parseDouble(expectedCoords[3]), upperCornerCoords[1], DOUBLE_DELTA);
}
use of org.geotools.filter.spatial.IntersectsImpl in project ddf by codice.
the class OpenSearchQueryTest method testPolygonSpatialFilter.
@Test
public void testPolygonSpatialFilter() throws Exception {
String latLon = "0,10,0,30,20,30,20,10,0,10";
String lonLat = "10,0,30,0,30,20,10,20,10,0";
OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
query.addPolygonSpatialFilter(latLon);
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();
printFilterStatusMap(map);
// List<Filter> filters = getFilters( map, ContainsImpl.class.getName() );
List<Filter> filters = getFilters(map, IntersectsImpl.class.getName());
assertEquals(1, filters.size());
// ContainsImpl containsFilter = (ContainsImpl) filters.get( 0 );
IntersectsImpl containsFilter = (IntersectsImpl) 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.SurfaceImpl@64a7c45e</ogc:Literal>
Literal literalWrapper = (Literal) containsFilter.getExpression2();
// Luckily we know what type the geometry expression should be, so we can cast it
SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
// WKT is lon/lat, polygon is lat/lon
String[] expectedCoords = lonLat.split(",");
Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
int i = 0;
for (Coordinate coord : coords) {
LOGGER.debug("coord {}: x = {}, y = {}", (i + 1), coord.x, coord.y);
int index = i * 2 + 1;
assertEquals(Double.parseDouble(expectedCoords[index - 1]), coord.x, DOUBLE_DELTA);
assertEquals(Double.parseDouble(expectedCoords[index]), coord.y, DOUBLE_DELTA);
i++;
}
}
use of org.geotools.filter.spatial.IntersectsImpl in project ddf by codice.
the class OpenSearchQueryTest method testPolygonSpatialFilter.
@Test
public void testPolygonSpatialFilter() {
String latLon = "0,10,0,30,20,30,20,10,0,10";
String lonLat = "10,0,30,0,30,20,10,20,10,0";
OpenSearchQuery query = new OpenSearchQuery(0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
query.addPolygonSpatialFilter(latLon);
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();
printFilterStatusMap(map);
// List<Filter> filters = getFilters( map, ContainsImpl.class.getName() );
List<Filter> filters = getFilters(map, IntersectsImpl.class.getName());
assertEquals(1, filters.size());
// ContainsImpl containsFilter = (ContainsImpl) filters.get( 0 );
IntersectsImpl containsFilter = (IntersectsImpl) 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.SurfaceImpl@64a7c45e</ogc:Literal>
Literal literalWrapper = (Literal) containsFilter.getExpression2();
// Luckily we know what type the geometry expression should be, so we can cast it
SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
// WKT is lon/lat, polygon is lat/lon
String[] expectedCoords = lonLat.split(",");
Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
int i = 0;
for (Coordinate coord : coords) {
LOGGER.debug("coord {}: x = {}, y = {}", (i + 1), coord.x, coord.y);
int index = i * 2 + 1;
assertEquals(Double.parseDouble(expectedCoords[index - 1]), coord.x, DOUBLE_DELTA);
assertEquals(Double.parseDouble(expectedCoords[index]), coord.y, DOUBLE_DELTA);
i++;
}
}
Aggregations