use of org.opengis.filter.expression.Literal in project ddf by codice.
the class OpenSearchFilterVisitor method visit.
/**
* Contains filter maps to a Polygon or BBox Spatial search criteria.
*/
@Override
public Object visit(Contains filter, Object data) {
LOGGER.trace("ENTERING: Contains filter");
if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
// 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) filter.getExpression2();
Object geometryExpression = literalWrapper.getValue();
StringBuffer geometryWkt = new StringBuffer();
if (geometryExpression instanceof SurfaceImpl) {
SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
geometryWkt.append("POLYGON((");
for (int i = 0; i < coords.length; i++) {
geometryWkt.append(coords[i].x);
geometryWkt.append(" ");
geometryWkt.append(coords[i].y);
if (i != (coords.length - 1)) {
geometryWkt.append(",");
}
}
geometryWkt.append("))");
this.spatialSearch = new SpatialFilter(geometryWkt.toString());
LOGGER.debug("geometryWkt = [{}]", geometryWkt.toString());
filters.add(filter);
} else {
LOGGER.debug("Only POLYGON geometry WKT for Contains filter is supported");
}
} else {
LOGGER.debug(ONLY_AND_MSG);
}
LOGGER.trace("EXITING: Contains filter");
return super.visit(filter, data);
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class OpenSearchFilterVisitor method visit.
/**
* Intersects filter maps to a Polygon or BBox Spatial search criteria.
*/
@Override
public Object visit(Intersects filter, Object data) {
LOGGER.trace("ENTERING: Intersects filter");
if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
// 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) filter.getExpression2();
Object geometryExpression = literalWrapper.getValue();
StringBuffer geometryWkt = new StringBuffer();
if (geometryExpression instanceof SurfaceImpl) {
SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
geometryWkt.append("POLYGON((");
for (int i = 0; i < coords.length; i++) {
geometryWkt.append(coords[i].x);
geometryWkt.append(" ");
geometryWkt.append(coords[i].y);
if (i != (coords.length - 1)) {
geometryWkt.append(",");
}
}
geometryWkt.append("))");
this.spatialSearch = new SpatialFilter(geometryWkt.toString());
LOGGER.debug("geometryWkt = [{}]", geometryWkt.toString());
filters.add(filter);
} else {
LOGGER.debug("Only POLYGON geometry WKT for Intersects filter is supported");
}
} else {
LOGGER.debug(ONLY_AND_MSG);
}
LOGGER.trace("EXITING: Intersects filter");
return super.visit(filter, data);
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class TwitterFilterVisitor method visit.
/**
* Contains filter maps to a Polygon or BBox Spatial search criteria.
*/
@Override
public Object visit(Contains filter, Object data) {
LOGGER.trace("ENTERING: Contains filter");
if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
// 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) filter.getExpression2();
Object geometryExpression = literalWrapper.getValue();
if (geometryExpression instanceof SurfaceImpl) {
SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
Point point = polygon.getJTSGeometry().getCentroid();
longitude = point.getX();
latitude = point.getY();
radius = point.getBoundary().getLength() * 10;
hasSpatial = true;
filters.add(filter);
} else if (geometryExpression instanceof Polygon) {
Polygon polygon = (Polygon) geometryExpression;
Point centroid = polygon.getCentroid();
longitude = centroid.getX();
latitude = centroid.getY();
radius = polygon.getBoundary().getLength() * 10;
hasSpatial = true;
filters.add(filter);
} else {
LOGGER.warn("Only POLYGON geometry WKT for Contains filter is supported");
}
} else {
LOGGER.warn(ONLY_AND_MSG);
}
LOGGER.trace("EXITING: Contains filter");
return super.visit(filter, data);
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class TwitterFilterVisitor method visit.
/**
* DWithin filter maps to a Point/Radius distance Spatial search criteria.
*/
@Override
public Object visit(DWithin filter, Object data) {
LOGGER.trace("ENTERING: DWithin filter");
if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
// 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.PointImpl@dc33f184</ogc:Literal>
Literal literalWrapper = (Literal) filter.getExpression2();
// Luckily we know what type the geometry expression should be, so
// we
// can cast it
Point point = (Point) literalWrapper.evaluate(null);
Coordinate coords = point.getCentroid().getCoordinate();
double distance = filter.getDistance();
LOGGER.debug("point: coords[0] = {}, coords[1] = {}", coords.x, coords.y);
LOGGER.debug("radius = {}", distance);
longitude = coords.x;
latitude = coords.y;
radius = distance / 1000;
hasSpatial = true;
filters.add(filter);
} else {
LOGGER.warn(ONLY_AND_MSG);
}
LOGGER.trace("EXITING: DWithin filter");
return super.visit(filter, data);
}
use of org.opengis.filter.expression.Literal in project ddf by codice.
the class CswRecordMapperFilterVisitor method visit.
@Override
public Object visit(PropertyIsGreaterThan filter, Object extraData) {
Expression expr1 = visit(filter.getExpression1(), extraData);
Expression expr2 = visit(filter.getExpression2(), expr1);
// work around since Solr Provider doesn't support greater on temporal (DDF-311)
if (isTemporalQuery(expr1, expr2)) {
// also not supported by provider (DDF-311)
//TODO: work around 1: return getFactory(extraData).after(expr1, expr2);
Object val = null;
Expression other = null;
if (expr2 instanceof Literal) {
val = ((Literal) expr2).getValue();
other = expr1;
} else if (expr1 instanceof Literal) {
val = ((Literal) expr1).getValue();
other = expr2;
}
if (val != null) {
Date orig = (Date) val;
orig.setTime(orig.getTime() + 1);
Instant start = new DefaultInstant(new DefaultPosition(orig));
Instant end = new DefaultInstant(new DefaultPosition(new Date()));
DefaultPeriod period = new DefaultPeriod(start, end);
Literal literal = getFactory(extraData).literal(period);
return getFactory(extraData).during(other, literal);
}
} else {
AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
setExpressionType(type, typedExpression);
expr2 = visit((Expression) typedExpression, expr1);
}
return getFactory(extraData).greater(expr1, expr2);
}
Aggregations