use of org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl 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.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl 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.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl 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.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl 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.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl in project ddf by codice.
the class TwitterFilterVisitor 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();
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 Intersects filter is supported");
}
} else {
LOGGER.warn(ONLY_AND_MSG);
}
LOGGER.trace("EXITING: Intersects filter");
return super.visit(filter, data);
}
Aggregations