use of org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl 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++;
}
}
Aggregations