Search in sources :

Example 6 with GeohashPrefixTree

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();
}
Also used : RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree) Before(org.junit.Before)

Example 7 with GeohashPrefixTree

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);
    }
}
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 GeohashPrefixTree

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;
}
Also used : 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 9 with GeohashPrefixTree

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;
    }
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) UnsupportedSpatialOperation(org.apache.lucene.spatial.query.UnsupportedSpatialOperation) Shape(org.locationtech.spatial4j.shape.Shape) RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) UnsupportedSpatialOperation(org.apache.lucene.spatial.query.UnsupportedSpatialOperation) SpatialOperation(org.apache.lucene.spatial.query.SpatialOperation) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)

Example 10 with GeohashPrefixTree

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();
    }
}
Also used : SpatialContext(org.locationtech.spatial4j.context.SpatialContext) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) Cell(org.apache.lucene.spatial.prefix.tree.Cell) GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)

Aggregations

GeohashPrefixTree (org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)17 RecursivePrefixTreeStrategy (org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy)11 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)10 SpatialStrategy (org.apache.lucene.spatial.SpatialStrategy)5 QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)4 ArrayList (java.util.ArrayList)3 TermQueryPrefixTreeStrategy (org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy)3 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)3 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)2 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)2 SerializedDVStrategy (org.apache.lucene.spatial.serialized.SerializedDVStrategy)2 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 Supplier (org.apache.logging.log4j.util.Supplier)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 CompositeSpatialStrategy (org.apache.lucene.spatial.composite.CompositeSpatialStrategy)1 Cell (org.apache.lucene.spatial.prefix.tree.Cell)1 PackedQuadPrefixTree (org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)1