use of org.opengis.filter.expression.Literal 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.opengis.filter.expression.Literal in project ddf by codice.
the class TestCswRecordMapperFilterVisitor method testLiteralWithUnknownType.
@Test
public void testLiteralWithUnknownType() {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
String dateString = formatter.format(date);
Literal val = factory.literal(dateString);
Literal literal = (Literal) visitor.visit(val, attrExpr);
assertThat(literal.getValue(), instanceOf(String.class));
assertThat(literal.getValue(), is(dateString));
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class TestCswRecordMapperFilterVisitor 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));
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class TestCswRecordMapperFilterVisitor method testLiteralWithMappableType.
@Test
public void testLiteralWithMappableType() {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
String dateString = formatter.format(date);
Literal val = factory.literal(dateString);
Literal literal = (Literal) visitor.visit(val, created);
assertThat(literal.getValue(), instanceOf(Date.class));
assertThat(literal.getValue(), is(date));
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class OpenSearchFilterVisitor method handleTemporal.
private void handleTemporal(BinaryTemporalOperator filter) {
Literal literalWrapper = (Literal) filter.getExpression2();
LOGGER.trace("literalWrapper.getValue() = {}", literalWrapper.getValue());
Object literal = literalWrapper.evaluate(null);
if (literal instanceof Period) {
Period period = (Period) literal;
// Extract the start and end dates from the filter
Date start = period.getBeginning().getPosition().getDate();
Date end = period.getEnding().getPosition().getDate();
temporalSearch = new TemporalFilter(start, end);
filters.add(filter);
} else if (literal instanceof PeriodDuration) {
DefaultPeriodDuration duration = (DefaultPeriodDuration) literal;
// Extract the start and end dates from the filter
Date end = Calendar.getInstance().getTime();
Date start = new Date(end.getTime() - duration.getTimeInMillis());
temporalSearch = new TemporalFilter(start, end);
filters.add(filter);
}
}
Aggregations