use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.
the class OpenSearchFilterVisitor 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
PointImpl point = (PointImpl) literalWrapper.evaluate(null);
double[] coords = point.getCentroid().getCoordinate();
double distance = filter.getDistance();
LOGGER.debug("point: coords[0] = {}, coords[1] = {}", coords[0], coords[1]);
LOGGER.debug("radius = {}", distance);
this.spatialSearch = new SpatialDistanceFilter(coords[0], coords[1], distance);
filters.add(filter);
} else {
LOGGER.debug(ONLY_AND_MSG);
}
LOGGER.trace("EXITING: DWithin filter");
return super.visit(filter, data);
}
use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.
the class GeoResultCreator method createGeoResult.
public static GeoResult createGeoResult(final String name, final double latitude, final double longitude, final String featureCode, final double population) {
double offset = 0.1;
if (featureCode != null) {
if (featureCode.startsWith(ADMINISTRATIVE_DIVISION)) {
offset = getOffsetAdministrativeDivision(featureCode);
} else if (featureCode.startsWith(POLITICAL_ENTITY)) {
offset = getOffsetPoliticalEntity(population);
} else if (featureCode.startsWith(POPULATED_PLACE)) {
offset = getOffsetPopulatedPlace(population);
}
}
final DirectPosition northWest = new DirectPositionImpl(longitude - offset, latitude + offset);
final DirectPosition southEast = new DirectPositionImpl(longitude + offset, latitude - offset);
final List<Point> bbox = new ArrayList<>();
bbox.add(new PointImpl(northWest));
bbox.add(new PointImpl(southEast));
final DirectPosition directPosition = new DirectPositionImpl(longitude, latitude);
final GeoResult geoResult = new GeoResult();
geoResult.setPoint(new PointImpl(directPosition));
geoResult.setBbox(bbox);
geoResult.setFullName(name);
return geoResult;
}
use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.
the class GeoResultCreatorTest method verifyGeoResult.
private void verifyGeoResult(final String name, final double latitude, final double longitude, final double expectedLatitudeOffset, final double expectedLongitudeOffset, final GeoResult geoResult) {
assertThat(geoResult.fullName, is(equalTo(name)));
final Point point = new PointImpl(new DirectPositionImpl(longitude, latitude));
assertThat(geoResult.point, is(equalTo(point)));
assertThat(geoResult.bbox.size(), is(2));
assertEquals(geoResult.bbox.get(0).getDirectPosition().getCoordinate()[0], longitude - expectedLongitudeOffset, 0.001);
assertEquals(geoResult.bbox.get(0).getDirectPosition().getCoordinate()[1], latitude + expectedLatitudeOffset, 0.001);
assertEquals(geoResult.bbox.get(1).getDirectPosition().getCoordinate()[0], longitude + expectedLongitudeOffset, 0.001);
assertEquals(geoResult.bbox.get(1).getDirectPosition().getCoordinate()[1], latitude - expectedLatitudeOffset, 0.001);
}
use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.
the class SolrProviderSpatial method testSpatialPointRadius.
@Test
public void testSpatialPointRadius() throws Exception {
deleteAll(provider);
MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
// Add in the geometry
metacard1.setLocation(Library.FLAGSTAFF_AIRPORT_POINT_WKT);
metacard2.setLocation(Library.TAMPA_AIRPORT_POINT_WKT);
metacard3.setLocation(Library.SHOW_LOW_AIRPORT_POINT_WKT);
List<Metacard> list = Arrays.asList(metacard1, metacard2, metacard3);
// CREATE
create(list, provider);
Filter filter = getFilterBuilder().attribute(Metacard.ID).is().like().text("*");
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find all records.", 3, sourceResponse.getResults().size());
// Right on Flagstaff
QueryImpl query = pointRadius(-111.67121887207031, 35.138454437255859, 10.0);
query.setPageSize(1);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Failed to find Flagstaff record only.", 1, sourceResponse.getResults().size());
for (Result r : sourceResponse.getResults()) {
assertTrue("Wrong record, Flagstaff keyword was not found.", r.getMetacard().getMetadata().contains(Library.FLAGSTAFF_QUERY_PHRASE));
LOGGER.info("Distance to Flagstaff: {}", r.getDistanceInMeters());
// assertTrue(r.getDistanceInMeters() != null);
}
// Right on Flagstaff, finding 2 records with 195 km radius
query = pointRadius(-111.67121887207031, 35.138454437255859, 195000);
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl("foo", SortOrder.ASCENDING));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Failed to find the two records.", 2, sourceResponse.getResults().size());
ArrayList<Result> results = new ArrayList<>(sourceResponse.getResults());
// querybuilder
for (int i = 0; i < 2; i++) {
Result result = results.get(i);
LOGGER.info("Distance of [{}]]: {}", i, result.getDistanceInMeters());
if (i == 0) {
assertTrue("Grabbed the wrong record.", result.getMetacard().getMetadata().contains(Library.FLAGSTAFF_QUERY_PHRASE));
}
if (i == 1) {
assertTrue("Grabbed the wrong record - should be Show Low.", result.getMetacard().getMetadata().contains("Show Low"));
}
}
// NEGATIVE CASE
query = pointRadius(80.1, 25, 195000);
query.setPageSize(3);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Should have not found any records.", 0, sourceResponse.getResults().size());
// FEET
double[] coords = { -111.67121887207031, 35.138454437255859 };
query = new QueryImpl(filterFactory.dwithin(Metacard.ANY_GEO, new PointImpl(new DirectPositionImpl(coords), DefaultGeographicCRS.WGS84), 195000, UomOgcMapping.FOOT.name()));
query.setStartIndex(1);
SortByImpl sortby = new SortByImpl(filterFactory.property(Result.DISTANCE), org.opengis.filter.sort.SortOrder.ASCENDING);
query.setSortBy(sortby);
query.setPageSize(3);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(1, sourceResponse.getResults().size());
}
Aggregations