use of org.codice.ddf.spatial.geocoding.context.NearbyLocation in project ddf by codice.
the class GazetteerQueryCatalogTest method testGetNearestCities.
@Test
public void testGetNearestCities() throws Exception {
List<NearbyLocation> nearbyLocations = queryCatalog.getNearestCities(NEAR_BOSTON_WKT, RADIUS_IN_KM, MAX_RESULTS);
assertThat(nearbyLocations.size(), is(1));
NearbyLocation nearbyLocation = nearbyLocations.get(0);
assertThat(nearbyLocation.getCardinalDirection(), is("S"));
assertThat(nearbyLocation.getDistance(), is(closeTo(1.3, .01)));
assertThat(nearbyLocation.getName(), is(BOSTON));
}
use of org.codice.ddf.spatial.geocoding.context.NearbyLocation in project ddf by codice.
the class GazetteerQueryCatalogTest method testGetNearestCitiesMissingTitle.
@Test
public void testGetNearestCitiesMissingTitle() throws Exception {
Metacard metacard = generateGeoNamesMetacard();
metacard.setAttribute(new AttributeImpl(Core.TITLE, ""));
QueryResponse queryResponse = generateQueryResponseFromMetacard(metacard);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse);
List<NearbyLocation> nearbyLocations = queryCatalog.getNearestCities(NEAR_BOSTON_WKT, RADIUS_IN_KM, MAX_RESULTS);
assertThat(nearbyLocations.size(), is(0));
}
use of org.codice.ddf.spatial.geocoding.context.NearbyLocation in project ddf by codice.
the class TestGeoNamesQueryLuceneIndex method testNearestCitiesWithBlankWKT.
@Test(expected = java.text.ParseException.class)
public void testNearestCitiesWithBlankWKT() throws java.text.ParseException, GeoEntryQueryException {
String testPoint = "";
final int requestedMaxResults = 2;
final int actualResults = 0;
final List<NearbyLocation> nearestCities = directoryIndex.getNearestCities(testPoint, 50, requestedMaxResults);
assertThat(nearestCities.size(), is(actualResults));
}
use of org.codice.ddf.spatial.geocoding.context.NearbyLocation in project ddf by codice.
the class TestGeoNamesLocalIndex method testGetNearbyCitiesParseException.
@Test
public void testGetNearbyCitiesParseException() throws ParseException, GeoEntryQueryException {
when(geoEntryQueryable.getNearestCities("POINT(1.0 20)", 50, 1)).thenThrow(new ParseException("", 1));
NearbyLocation returnedNearbyLocation = geoNamesLocalIndex.getNearbyCity("POINT(1.0 20)");
assertThat(returnedNearbyLocation, nullValue());
}
use of org.codice.ddf.spatial.geocoding.context.NearbyLocation in project ddf by codice.
the class GeoCoderServiceImpl method getNearbyCities.
@Override
public String getNearbyCities(String wkt) throws GeoEntryQueryException {
GeoCoder geoCoder = geoCoderFactory.getService();
NearbyLocation nearbyLocation = geoCoder.getNearbyCity(wkt);
if (nearbyLocation != null) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("direction", nearbyLocation.getCardinalDirection());
jsonObject.put("distance", nearbyLocation.getDistance());
jsonObject.put("name", nearbyLocation.getName());
return jsonObject.toJSONString();
} else {
return null;
}
}
Aggregations