use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class TestGeoNamesFileExtractor method testFileExtractionStreaming.
private void testFileExtractionStreaming(final String fileLocation) throws GeoEntryExtractionException, GeoNamesRemoteDownloadException, GeoEntryIndexingException {
final ExtractionCallback extractionCallback = mock(ExtractionCallback.class);
final ArgumentCaptor<GeoEntry> geoEntryArgumentCaptor = ArgumentCaptor.forClass(GeoEntry.class);
geoNamesFileExtractor.pushGeoEntriesToExtractionCallback(fileLocation, extractionCallback);
verify(extractionCallback, atLeastOnce()).updateProgress(anyInt());
verify(extractionCallback, times(3)).extracted(geoEntryArgumentCaptor.capture());
final List<GeoEntry> capturedGeoEntryList = geoEntryArgumentCaptor.getAllValues();
verifyGeoEntryList(capturedGeoEntryList);
}
use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class GeoNamesLuceneIndexer method indexGeoEntries.
private void indexGeoEntries(final IndexWriter indexWriter, final List<GeoEntry> geoEntryList, final ProgressCallback progressCallback) throws IOException {
int progress = 0;
int currentEntry = 0;
final int numGeoEntries = geoEntryList.size();
final SpatialPrefixTree grid = new GeohashPrefixTree(SPATIAL_CONTEXT, GeoNamesLuceneConstants.GEOHASH_LEVELS);
final SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, GeoNamesLuceneConstants.GEO_FIELD);
for (GeoEntry geoEntry : geoEntryList) {
addDocument(indexWriter, geoEntry, strategy);
if (currentEntry == (int) (numGeoEntries * (progress / 100.0f))) {
if (progressCallback != null) {
progressCallback.updateProgress(progress);
}
progress += 5;
}
++currentEntry;
}
// the work is complete.
if (progressCallback != null) {
progressCallback.updateProgress(100);
}
}
use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class TestGeoNamesLocalIndex method testWithNoResults.
@Test
public void testWithNoResults() throws GeoEntryQueryException {
final List<GeoEntry> noResults = Collections.emptyList();
doReturn(noResults).when(geoEntryQueryable).query("Tempe", 1);
final GeoResult geoResult = geoNamesLocalIndex.getLocation("Tempe");
assertThat(geoResult, is(nullValue()));
}
use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class GeoNamesLocalIndex method getLocation.
@Override
public GeoResult getLocation(final String location) {
try {
final List<GeoEntry> topResults = geoEntryQueryable.query(location, 1);
if (topResults.size() > 0) {
final GeoEntry topResult = topResults.get(0);
final String name = topResult.getName();
final double latitude = topResult.getLatitude();
final double longitude = topResult.getLongitude();
final String featureCode = topResult.getFeatureCode();
final long population = topResult.getPopulation();
return GeoResultCreator.createGeoResult(name, latitude, longitude, featureCode, population);
}
} catch (GeoEntryQueryException e) {
LOGGER.debug("Error querying the local GeoNames index", e);
}
return null;
}
use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class TestGeoNamesCreator method testSomeEmptyFields.
@Test
public void testSomeEmptyFields() {
final String geoNamesEntryStr = "5288858\tCave Creek\tCave Creek\t\t33.83333\t" + "-111.95083\tP\tPPL\tUS\t\tAZ\t013\t\t\t5015\t648\t649\tAmerica/Phoenix\t" + "2011-05-14";
final GeoEntry geoEntry = GEONAMES_CREATOR.createGeoEntry(geoNamesEntryStr);
verifyGeoEntry(geoEntry, "Cave Creek", 33.83333, -111.95083, "PPL", 5015, "", "US");
}
Aggregations