Search in sources :

Example 16 with NearbyLocation

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));
}
Also used : NearbyLocation(org.codice.ddf.spatial.geocoding.context.NearbyLocation) Test(org.junit.Test)

Example 17 with NearbyLocation

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) QueryResponse(ddf.catalog.operation.QueryResponse) NearbyLocation(org.codice.ddf.spatial.geocoding.context.NearbyLocation) Test(org.junit.Test)

Example 18 with NearbyLocation

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));
}
Also used : NearbyLocation(org.codice.ddf.spatial.geocoding.context.NearbyLocation) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with NearbyLocation

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());
}
Also used : NearbyLocation(org.codice.ddf.spatial.geocoding.context.NearbyLocation) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 20 with NearbyLocation

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;
    }
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) JSONObject(net.minidev.json.JSONObject) NearbyLocation(org.codice.ddf.spatial.geocoding.context.NearbyLocation)

Aggregations

NearbyLocation (org.codice.ddf.spatial.geocoding.context.NearbyLocation)24 Test (org.junit.Test)18 GeoEntryQueryException (org.codice.ddf.spatial.geocoding.GeoEntryQueryException)5 ParseException (java.text.ParseException)4 Shape (org.locationtech.spatial4j.shape.Shape)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Metacard (ddf.catalog.data.Metacard)3 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)3 QueryRequest (ddf.catalog.operation.QueryRequest)3 QueryResponse (ddf.catalog.operation.QueryResponse)3 IOException (java.io.IOException)3 Collections (java.util.Collections)3 List (java.util.List)3 Optional (java.util.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 COLLECTION_NAME (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COLLECTION_NAME)2 COUNTRY_CODE (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COUNTRY_CODE)2 FEATURE_CODE (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.FEATURE_CODE)2 GAZETTEER_REQUEST_HANDLER (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.GAZETTEER_REQUEST_HANDLER)2 ID (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.ID)2