use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class TestGeoNamesQueryLuceneIndex method testDoGetNearestCitiesIOExceptionBranch.
@Test(expected = GeoEntryQueryException.class)
public void testDoGetNearestCitiesIOExceptionBranch() throws IOException, GeoEntryQueryException {
doThrow(IOException.class).when(directoryIndex).createIndexReader(directory);
Shape shape = mock(Shape.class);
directoryIndex.doGetNearestCities(shape, 10, 10, directory);
}
use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class TestGeoNamesQueryLuceneIndex method testDoGetNearestCitiesNullDirectory.
@Test
public void testDoGetNearestCitiesNullDirectory() throws IOException, GeoEntryQueryException {
Shape shape = mock(Shape.class);
List<NearbyLocation> nearestCities = directoryIndex.doGetNearestCities(shape, 10, 10, null);
assertThat(nearestCities, is(Collections.emptyList()));
}
use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class TestGeoNamesQueryLuceneIndex method createDocumentFromGeoEntry.
private Document createDocumentFromGeoEntry(final GeoEntry geoEntry) {
final Document document = new Document();
document.add(new TextField(GeoNamesLuceneConstants.NAME_FIELD, geoEntry.getName(), Field.Store.YES));
document.add(new StoredField(GeoNamesLuceneConstants.LATITUDE_FIELD, geoEntry.getLatitude()));
document.add(new StoredField(GeoNamesLuceneConstants.LONGITUDE_FIELD, geoEntry.getLongitude()));
document.add(new StringField(GeoNamesLuceneConstants.FEATURE_CODE_FIELD, geoEntry.getFeatureCode(), Field.Store.YES));
document.add(new StoredField(GeoNamesLuceneConstants.POPULATION_FIELD, geoEntry.getPopulation()));
document.add(new NumericDocValuesField(GeoNamesLuceneConstants.POPULATION_DOCVALUES_FIELD, geoEntry.getPopulation()));
document.add(new StringField(GeoNamesLuceneConstants.COUNTRY_CODE_FIELD, geoEntry.getCountryCode(), Field.Store.YES));
document.add(new TextField(GeoNamesLuceneConstants.ALTERNATE_NAMES_FIELD, geoEntry.getAlternateNames(), Field.Store.NO));
final Shape point = SPATIAL_CONTEXT.getShapeFactory().pointXY(geoEntry.getLongitude(), geoEntry.getLatitude());
for (IndexableField field : strategy.createIndexableFields(point)) {
document.add(field);
}
return document;
}
use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class GeoNamesLuceneIndexer method addDocument.
private void addDocument(final IndexWriter indexWriter, final GeoEntry geoEntry, final SpatialStrategy strategy) throws IOException {
final Document document = new Document();
document.add(new TextField(GeoNamesLuceneConstants.NAME_FIELD, geoEntry.getName(), Field.Store.YES));
document.add(new StoredField(GeoNamesLuceneConstants.LATITUDE_FIELD, geoEntry.getLatitude()));
document.add(new StoredField(GeoNamesLuceneConstants.LONGITUDE_FIELD, geoEntry.getLongitude()));
document.add(new StringField(GeoNamesLuceneConstants.FEATURE_CODE_FIELD, geoEntry.getFeatureCode(), Field.Store.YES));
document.add(new TextField(GeoNamesLuceneConstants.COUNTRY_CODE_FIELD, geoEntry.getCountryCode(), Field.Store.YES));
document.add(new StoredField(GeoNamesLuceneConstants.POPULATION_FIELD, geoEntry.getPopulation()));
// This DocValues field is used for sorting by population.
document.add(new NumericDocValuesField(GeoNamesLuceneConstants.POPULATION_DOCVALUES_FIELD, geoEntry.getPopulation()));
document.add(new TextField(GeoNamesLuceneConstants.ALTERNATE_NAMES_FIELD, geoEntry.getAlternateNames(), Field.Store.NO));
// Add each entry's spatial information for fast spatial filtering.
final Shape point = SPATIAL_CONTEXT.getShapeFactory().pointXY(geoEntry.getLongitude(), geoEntry.getLatitude());
for (IndexableField field : strategy.createIndexableFields(point)) {
document.add(field);
}
final float boost = calculateBoost(geoEntry);
document.add(new FloatDocValuesField(GeoNamesLuceneConstants.BOOST_FIELD, boost));
indexWriter.addDocument(document);
}
use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class GeoNamesQueryLuceneDirectoryIndex method getNearestCities.
@Override
public List<NearbyLocation> getNearestCities(final String location, final int radiusInKm, final int maxResults) throws ParseException, GeoEntryQueryException {
if (location == null) {
throw new IllegalArgumentException("GeoNamesQueryLuceneDirectoryIndex.getNearestCities(): argument 'location' may not be null.");
}
Shape shape = getShape(location);
final Directory directory = openDirectoryAndCheckForIndex();
return doGetNearestCities(shape, radiusInKm, maxResults, directory);
}
Aggregations