use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl 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.primitive.PointImpl in project ddf by codice.
the class OpenSearchQueryTest method testSpatialDistanceFilter.
@Test
public void testSpatialDistanceFilter() {
String lon = "10";
String lat = "20";
String radius = "5000";
OpenSearchQuery query = new OpenSearchQuery(0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
query.addPointRadiusSpatialFilter(lon, lat, radius);
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();
List<Filter> filters = getFilters(map, DWithinImpl.class.getName());
assertEquals(1, filters.size());
DWithinImpl dwithinFilter = (DWithinImpl) 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.PointImpl@dc33f184</ogc:Literal>
Literal literalWrapper = (Literal) dwithinFilter.getExpression2();
// Luckily we know what type the geometry expression should be, so we can cast it
PointImpl point = (PointImpl) literalWrapper.evaluate(null);
double[] coords = point.getCentroid().getCoordinate();
LOGGER.debug("coords[0] = {}, coords[1] = {}", coords[0], coords[1]);
assertEquals(Double.parseDouble(lon), coords[0], DOUBLE_DELTA);
assertEquals(Double.parseDouble(lat), coords[1], DOUBLE_DELTA);
LOGGER.debug("dwithinFilter.getDistance() = {}", dwithinFilter.getDistance());
assertEquals(Double.parseDouble(radius), dwithinFilter.getDistance(), DOUBLE_DELTA);
}
use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.
the class OpenSearchFilterVisitor method buildPointRadiusSearch.
protected static void buildPointRadiusSearch(DWithin 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("The OpenSearch Source 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();
double distance = filter.getDistance();
final double radiusRangeLowerBound = 0;
if (distance <= radiusRangeLowerBound) {
LOGGER.debug("Radius must be greater than {}. Ignoring DWithin filter.", radiusRangeLowerBound);
} else if (geometryExpression instanceof PointImpl) {
PointImpl point = (PointImpl) literalWrapper.evaluate(null);
double[] coords = point.getCentroid().getCoordinate();
LOGGER.trace("point: coords[0] = {}, coords[1] = {}", coords[0], coords[1]);
LOGGER.trace("radius = {}", distance);
openSearchFilterVisitorObject.addPointRadiusSearch(new PointRadius(coords[0], coords[1], distance));
} else if (geometryExpression instanceof Point) {
Point point = (Point) literalWrapper.evaluate(null);
Coordinate coords = point.getCoordinate();
LOGGER.trace("point: coords.x = {}, coords.y = {}", coords.x, coords.y);
LOGGER.trace("radius = {}", distance);
openSearchFilterVisitorObject.addPointRadiusSearch(new PointRadius(coords.x, coords.y, distance));
} else {
LOGGER.debug("The OpenSearch Source only supports POINT geometry WKT for DWithin filter, but the geometry is {}.", geometryExpression);
}
}
use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.
the class SolrProviderSpatial method pointRadius.
/**
* Creates a point radius {@link QueryImpl} with units of measurement of meters.
*/
private QueryImpl pointRadius(double x, double y, double distance) {
double[] coords = { x, y };
QueryImpl query = new QueryImpl(filterFactory.dwithin(Metacard.ANY_GEO, new PointImpl(new DirectPositionImpl(coords), DefaultGeographicCRS.WGS84), distance, UomOgcMapping.METRE.name()));
query.setStartIndex(1);
SortByImpl sortby = new SortByImpl(filterFactory.property(Result.DISTANCE), org.opengis.filter.sort.SortOrder.ASCENDING);
query.setSortBy(sortby);
return query;
}
use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.
the class GazetteerGeoCoderTest method testWithResults.
@Test
public void testWithResults() throws GeoEntryQueryException {
final List<GeoEntry> topResults = Arrays.asList(GEO_ENTRY_1, GEO_ENTRY_2);
doReturn(topResults).when(geoEntryQueryable).query("Phoenix", 1);
final GeoResult geoResult = gazetteerGeoCoder.getLocation("Phoenix");
assertThat(geoResult.getFullName(), is(equalTo(GEO_ENTRY_1.getName())));
final Point point = new PointImpl(new DirectPositionImpl(GEO_ENTRY_1.getLongitude(), GEO_ENTRY_1.getLatitude()));
assertThat(geoResult.getPoint(), is(equalTo(point)));
}
Aggregations