use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project ddf by codice.
the class TestGeoNamesQueryLuceneIndex method setUp.
@Before
public void setUp() throws IOException {
directoryIndex = spy(new GeoNamesQueryLuceneDirectoryIndex());
directoryIndex.setIndexLocation(null);
final SpatialPrefixTree grid = new GeohashPrefixTree(SPATIAL_CONTEXT, GeoNamesLuceneConstants.GEOHASH_LEVELS);
strategy = new RecursivePrefixTreeStrategy(grid, GeoNamesLuceneConstants.GEO_FIELD);
initializeIndex();
doReturn(directory).when(directoryIndex).openDirectory();
}
use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree 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.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project janusgraph by JanusGraph.
the class LuceneExample method getSpatialStrategy.
private SpatialStrategy getSpatialStrategy(String key) {
SpatialStrategy strategy = spatial.get(key);
if (strategy == null) {
final int maxLevels = 11;
SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
strategy = new RecursivePrefixTreeStrategy(grid, key);
spatial.put(key, strategy);
}
return strategy;
}
use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project elasticsearch by elastic.
the class GeoFilterIT method testRelationSupport.
protected static boolean testRelationSupport(SpatialOperation relation) {
if (relation == SpatialOperation.IsDisjointTo) {
// disjoint works in terms of intersection
relation = SpatialOperation.Intersects;
}
try {
GeohashPrefixTree tree = new GeohashPrefixTree(SpatialContext.GEO, 3);
RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(tree, "area");
Shape shape = SpatialContext.GEO.makePoint(0, 0);
SpatialArgs args = new SpatialArgs(relation, shape);
strategy.makeQuery(args);
return true;
} catch (UnsupportedSpatialOperation e) {
final SpatialOperation finalRelation = relation;
ESLoggerFactory.getLogger(GeoFilterIT.class.getName()).info((Supplier<?>) () -> new ParameterizedMessage("Unsupported spatial operation {}", finalRelation), e);
return false;
}
}
use of org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree in project elasticsearch by elastic.
the class GeoUtilsTests method testPrefixTreeCellSizes.
public void testPrefixTreeCellSizes() {
assertThat(GeoUtils.EARTH_SEMI_MAJOR_AXIS, equalTo(DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM * 1000));
assertThat(GeoUtils.quadTreeCellWidth(0), lessThanOrEqualTo(GeoUtils.EARTH_EQUATOR));
SpatialContext spatialContext = new SpatialContext(true);
GeohashPrefixTree geohashPrefixTree = new GeohashPrefixTree(spatialContext, GeohashPrefixTree.getMaxLevelsPossible() / 2);
Cell gNode = geohashPrefixTree.getWorldCell();
for (int i = 0; i < geohashPrefixTree.getMaxLevels(); i++) {
double width = GeoUtils.geoHashCellWidth(i);
double height = GeoUtils.geoHashCellHeight(i);
double size = GeoUtils.geoHashCellSize(i);
double degrees = 360.0 * width / GeoUtils.EARTH_EQUATOR;
int level = GeoUtils.quadTreeLevelsForPrecision(size);
assertThat(GeoUtils.quadTreeCellWidth(level), lessThanOrEqualTo(width));
assertThat(GeoUtils.quadTreeCellHeight(level), lessThanOrEqualTo(height));
assertThat(GeoUtils.geoHashLevelsForPrecision(size), equalTo(geohashPrefixTree.getLevelForDistance(degrees)));
assertThat("width at level " + i, gNode.getShape().getBoundingBox().getWidth(), equalTo(360.d * width / GeoUtils.EARTH_EQUATOR));
assertThat("height at level " + i, gNode.getShape().getBoundingBox().getHeight(), equalTo(180.d * height / GeoUtils.EARTH_POLAR_DISTANCE));
gNode = gNode.getNextLevelCells(null).next();
}
QuadPrefixTree quadPrefixTree = new QuadPrefixTree(spatialContext);
Cell qNode = quadPrefixTree.getWorldCell();
for (int i = 0; i < quadPrefixTree.getMaxLevels(); i++) {
double degrees = 360.0 / (1L << i);
double width = GeoUtils.quadTreeCellWidth(i);
double height = GeoUtils.quadTreeCellHeight(i);
double size = GeoUtils.quadTreeCellSize(i);
int level = GeoUtils.quadTreeLevelsForPrecision(size);
assertThat(GeoUtils.quadTreeCellWidth(level), lessThanOrEqualTo(width));
assertThat(GeoUtils.quadTreeCellHeight(level), lessThanOrEqualTo(height));
assertThat(GeoUtils.quadTreeLevelsForPrecision(size), equalTo(quadPrefixTree.getLevelForDistance(degrees)));
assertThat("width at level " + i, qNode.getShape().getBoundingBox().getWidth(), equalTo(360.d * width / GeoUtils.EARTH_EQUATOR));
assertThat("height at level " + i, qNode.getShape().getBoundingBox().getHeight(), equalTo(180.d * height / GeoUtils.EARTH_POLAR_DISTANCE));
qNode = qNode.getNextLevelCells(null).next();
}
}
Aggregations