Search in sources :

Example 6 with GeoEntry

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);
}
Also used : GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) ExtractionCallback(org.codice.ddf.spatial.geocoding.GeoEntryExtractor.ExtractionCallback)

Example 7 with GeoEntry

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);
    }
}
Also used : GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) SpatialStrategy(org.apache.lucene.spatial.SpatialStrategy) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)

Example 8 with GeoEntry

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

Example 9 with GeoEntry

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;
}
Also used : GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) GeoEntryQueryException(org.codice.ddf.spatial.geocoding.GeoEntryQueryException)

Example 10 with GeoEntry

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

Aggregations

GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)17 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)4 GeoEntryExtractionException (org.codice.ddf.spatial.geocoding.GeoEntryExtractionException)3 ExtractionCallback (org.codice.ddf.spatial.geocoding.GeoEntryExtractor.ExtractionCallback)3 GeoEntryIndexingException (org.codice.ddf.spatial.geocoding.GeoEntryIndexingException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 SpatialStrategy (org.apache.lucene.spatial.SpatialStrategy)2 RecursivePrefixTreeStrategy (org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy)2 GeohashPrefixTree (org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)2 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)2 GeoResult (org.codice.ddf.spatial.geocoder.GeoResult)2 GeoEntryExtractor (org.codice.ddf.spatial.geocoding.GeoEntryExtractor)2 GeoEntryQueryException (org.codice.ddf.spatial.geocoding.GeoEntryQueryException)2 ProgressCallback (org.codice.ddf.spatial.geocoding.ProgressCallback)2 List (java.util.List)1 Document (org.apache.lucene.document.Document)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1