use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl 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.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.
the class GeotoolsFilterAdapterImpl method geometryToWkt.
private String geometryToWkt(Object literal) {
String wkt;
// WKT from the getBoundary method
if (literal instanceof GeometryImpl) {
GeometryImpl surface = (GeometryImpl) literal;
org.locationtech.jts.geom.Geometry jtsGeometry = surface.getJTSGeometry();
wkt = jtsGeometry.toText();
} else if (literal instanceof org.locationtech.jts.geom.Geometry) {
org.locationtech.jts.geom.Geometry jtsGeometry = (org.locationtech.jts.geom.Geometry) literal;
wkt = jtsGeometry.toText();
} else {
throw new UnsupportedOperationException("Unsupported implementation of Geometry for spatial filters.");
}
return wkt;
}
use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.
the class OpenSearchQueryTest method testGeometrySpatialFilter.
@Test
public void testGeometrySpatialFilter() {
OpenSearchQuery query = new OpenSearchQuery(0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
query.addGeometrySpatialFilter(GEOMETRY_WKT);
Filter filter = query.getFilter();
assertThat(filter, notNullValue());
Intersects intersects = (Intersects) filter;
Literal literalWrapper = (Literal) intersects.getExpression2();
Object geometryExpression = literalWrapper.getValue();
assertThat(geometryExpression, instanceOf(GeometryImpl.class));
org.locationtech.jts.geom.Geometry polygon = ((GeometryImpl) geometryExpression).getJTSGeometry();
assertThat(WKT_WRITER.write(polygon), is(GEOMETRY_WKT));
}
use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.
the class OpenSearchFilterVisitor method buildGeometrySearch.
protected static void buildGeometrySearch(BinarySpatialOperator filter, Object data) {
OpenSearchFilterVisitorObject openSearchFilterVisitorObject = getOpenSearchFilterVisitorObjectFromData(data);
if (openSearchFilterVisitorObject == null) {
return;
}
if (NestedTypes.NOT.equals(openSearchFilterVisitorObject.getCurrentNest())) {
LOGGER.debug(NOT_OPERATOR_UNSUPPORTED_MSG);
return;
}
final org.opengis.filter.expression.Expression expression1 = filter.getExpression1();
final String expectedSpatialSearchTerm = OpenSearchConstants.SUPPORTED_SPATIAL_SEARCH_TERM;
if (!expectedSpatialSearchTerm.equals(expression1.toString())) {
LOGGER.debug("Opensearch only supports spatial criteria on the term \"{}\", but expression1 is \"{}\". Ignoring filter.", expectedSpatialSearchTerm, expression1);
return;
}
// The geometry is wrapped in a <Literal> element, so have to get the geometry expression as a
// 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();
Object geometryExpression = literalWrapper.getValue();
if (geometryExpression instanceof SurfaceImpl) {
SurfaceImpl surface = (SurfaceImpl) literalWrapper.evaluate(null);
Geometry polygon = surface.getJTSGeometry();
openSearchFilterVisitorObject.addGeometrySearch(polygon);
} else if (geometryExpression instanceof Polygon) {
Geometry polygon = (Geometry) literalWrapper.evaluate(null);
openSearchFilterVisitorObject.addGeometrySearch(polygon);
} else if (geometryExpression instanceof GeometryImpl) {
Geometry polygon = ((GeometryImpl) geometryExpression).getJTSGeometry();
openSearchFilterVisitorObject.addGeometrySearch(polygon);
} else if (geometryExpression instanceof MultiPolygon) {
Geometry polygon = ((MultiPolygon) geometryExpression);
openSearchFilterVisitorObject.addGeometrySearch(polygon);
} else if (geometryExpression instanceof LineString) {
Geometry polygon = ((LineString) geometryExpression);
openSearchFilterVisitorObject.addGeometrySearch(polygon);
} else if (geometryExpression instanceof MultiLineString) {
Geometry polygon = ((MultiLineString) geometryExpression);
openSearchFilterVisitorObject.addGeometrySearch(polygon);
} else {
LOGGER.debug("Unsupported filter constraint");
}
}
use of org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl in project ddf by codice.
the class SubscriptionFilterVisitor method getJtsGeometery.
private org.locationtech.jts.geom.Geometry getJtsGeometery(LiteralExpressionImpl geoExpression) {
org.locationtech.jts.geom.Geometry jtsGeometry;
if (geoExpression.getValue() instanceof GeometryImpl) {
GeometryImpl geo = (GeometryImpl) geoExpression.getValue();
jtsGeometry = geo.getJTSGeometry();
} else if (geoExpression.getValue() instanceof org.locationtech.jts.geom.Geometry) {
jtsGeometry = (org.locationtech.jts.geom.Geometry) geoExpression.getValue();
} else {
throw new UnsupportedOperationException("Unsupported implementation of Geometry for spatial filters.");
}
return jtsGeometry;
}
Aggregations