org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree Java Examples
The following examples show how to use
org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Test public void test28() throws ParseException { SpatialContext ctx = SpatialContext.GEO; ShapeReadWriter<SpatialContext> shapeReadWriter = new ShapeReadWriter<SpatialContext>(ctx); int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_KM)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); String writeSpatialArgs = SpatialArgsParser.writeSpatialArgs(args, shapeReadWriter); // This has to be done because of rounding. SpatialArgs spatialArgs = SpatialArgsParser.parse(writeSpatialArgs, shapeReadWriter); Query q1 = sq(strategy.makeQuery(spatialArgs)); Query q = parseSq("a.id_gis:\"" + writeSpatialArgs + "\""); boolean equals = q1.equals(q); assertTrue(equals); }
Example #2
Source File: QueryEqualsHashCodeTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testEqualsHashCode() { switch (random().nextInt(4)) {//0-3 case 0: predicate = SpatialOperation.Contains; break; case 1: predicate = SpatialOperation.IsWithin; break; default: predicate = SpatialOperation.Intersects; break; } final SpatialPrefixTree gridQuad = new QuadPrefixTree(ctx,10); final SpatialPrefixTree gridGeohash = new GeohashPrefixTree(ctx,10); Collection<SpatialStrategy> strategies = new ArrayList<>(); RecursivePrefixTreeStrategy recursive_geohash = new RecursivePrefixTreeStrategy(gridGeohash, "recursive_geohash"); strategies.add(recursive_geohash); strategies.add(new TermQueryPrefixTreeStrategy(gridQuad, "termquery_quad")); strategies.add(PointVectorStrategy.newInstance(ctx, "pointvector")); strategies.add(BBoxStrategy.newInstance(ctx, "bbox")); final SerializedDVStrategy serialized = new SerializedDVStrategy(ctx, "serialized"); strategies.add(serialized); strategies.add(new CompositeSpatialStrategy("composite", recursive_geohash, serialized)); for (SpatialStrategy strategy : strategies) { testEqualsHashcode(strategy); } }
Example #3
Source File: CompositeStrategyTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void setupGeohashGrid(int maxLevels) { this.ctx = SpatialContext.GEO; //A fairly shallow grid if (maxLevels == -1) maxLevels = randomIntBetween(1, 3);//max 16k cells (32^3) this.grid = new GeohashPrefixTree(ctx, maxLevels); this.rptStrategy = newRPT(); }
Example #4
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test47() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(strategy.makeQuery(args)); Query q = parseSq("<a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\">"); boolean equals = q1.equals(q); assertTrue(equals); }
Example #5
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test46() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(bq(bc_m(strategy.makeQuery(args)), bc(tq("rowid", "12345")))); Query q = parseSq("<+a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\" rowid:12345>"); boolean equals = q1.equals(q); assertTrue(equals); }
Example #6
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test45() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(bq(bc_m(strategy.makeQuery(args)))); Query q = parseSq("<+a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\">"); boolean equals = q1.equals(q); assertTrue(equals); }
Example #7
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test30() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_MI)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(strategy.makeQuery(args)); Query q = parseSq("a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0m))\""); boolean equals = q1.equals(q); assertTrue(equals); }
Example #8
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test29() throws ParseException { SpatialContext ctx = SpatialContext.GEO; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false); Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_KM)); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); Query q1 = sq(strategy.makeQuery(args)); Query q = parseSq("a.id_gis:\"Intersects(Circle(33.000000,-80.000000 d=10.0km))\""); boolean equals = q1.equals(q); assertTrue(equals); }
Example #9
Source File: OLuceneSpatialIndexManager.java From orientdb-lucene with Apache License 2.0 | 5 votes |
public OLuceneSpatialIndexManager(OShapeFactory factory) { super(); this.ctx = SpatialContext.GEO; this.factory = factory; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 11); this.strategy = new RecursivePrefixTreeStrategy(grid, "location"); }
Example #10
Source File: GeoShapeMapper.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Builds a new {@link GeoShapeMapper}. */ @JsonCreator public GeoShapeMapper(@JsonProperty("max_levels") Integer maxLevels) { super(new AbstractType<?>[]{AsciiType.instance, UTF8Type.instance}); this.maxLevels = maxLevels == null ? DEFAULT_MAX_LEVELS : maxLevels; this.grid = new GeohashPrefixTree(spatialContext, this.maxLevels); }
Example #11
Source File: Geo3dRptTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void setupGrid() { int type = random().nextInt(4); if (type == 0) { this.grid = new GeohashPrefixTree(ctx, 2); } else if (type == 1) { this.grid = new QuadPrefixTree(ctx, 5); } else { int arity = random().nextInt(3) + 1; this.grid = new S2PrefixTree(ctx, 5 - arity, arity); } this.rptStrategy = newRPT(); this.rptStrategy.setPruneLeafyBranches(random().nextBoolean()); }
Example #12
Source File: SpatialExample.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void init() { //Typical geospatial context // These can also be constructed from SpatialContextFactory this.ctx = SpatialContext.GEO; int maxLevels = 11;//results in sub-meter precision for geohash //TODO demo lookup by detail distance // This can also be constructed from SpatialPrefixTreeFactory SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField"); this.directory = new ByteBuffersDirectory(); }
Example #13
Source File: JtsPolygonTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public JtsPolygonTest() { try { HashMap<String, String> args = new HashMap<>(); args.put("spatialContextFactory", "org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory"); ctx = SpatialContextFactory.makeSpatialContext(args, getClass().getClassLoader()); } catch (NoClassDefFoundError e) { assumeTrue("This test requires JTS jar: "+e, false); } GeohashPrefixTree grid = new GeohashPrefixTree(ctx, 11);//< 1 meter == 11 maxLevels this.strategy = new RecursivePrefixTreeStrategy(grid, getClass().getSimpleName()); ((RecursivePrefixTreeStrategy)this.strategy).setDistErrPct(LUCENE_4464_distErrPct);//1% radius (small!) }
Example #14
Source File: RandomSpatialOpFuzzyPrefixTreeTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void setupGeohashGrid(int maxLevels) { this.ctx = SpatialContext.GEO; //A fairly shallow grid, and default 2.5% distErrPct if (maxLevels == -1) maxLevels = randomIntBetween(1, 3);//max 16k cells (32^3) this.grid = new GeohashPrefixTree(ctx, maxLevels); this.strategy = newRPT(); }
Example #15
Source File: TestRecursivePrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testPrecision() throws IOException{ init(GeohashPrefixTree.getMaxLevelsPossible()); Point iPt = ctx.getShapeFactory().pointXY(2.8028712999999925, 48.3708044);//lon, lat addDocument(newDoc("iPt", iPt)); commit(); Point qPt = ctx.getShapeFactory().pointXY(2.4632387000000335, 48.6003516); final double KM2DEG = DistanceUtils.dist2Degrees(1, DistanceUtils.EARTH_MEAN_RADIUS_KM); final double DEG2KM = 1 / KM2DEG; final double DIST = 35.75;//35.7499... assertEquals(DIST, ctx.getDistCalc().distance(iPt, qPt) * DEG2KM, 0.001); //distErrPct will affect the query shape precision. The indexed precision // was set to nearly zilch via init(GeohashPrefixTree.getMaxLevelsPossible()); final double distErrPct = 0.025; //the suggested default, by the way final double distMult = 1+distErrPct; assertTrue(35.74*distMult >= DIST); checkHits(q(qPt, 35.74 * KM2DEG, distErrPct), 1, null); assertTrue(30*distMult < DIST); checkHits(q(qPt, 30 * KM2DEG, distErrPct), 0, null); assertTrue(33*distMult < DIST); checkHits(q(qPt, 33 * KM2DEG, distErrPct), 0, null); assertTrue(34*distMult < DIST); checkHits(q(qPt, 34 * KM2DEG, distErrPct), 0, null); }
Example #16
Source File: TestRecursivePrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testOneMeterPrecision() { init(GeohashPrefixTree.getMaxLevelsPossible()); GeohashPrefixTree grid = (GeohashPrefixTree) ((RecursivePrefixTreeStrategy) strategy).getGrid(); //DWS: I know this to be true. 11 is needed for one meter double degrees = DistanceUtils.dist2Degrees(0.001, DistanceUtils.EARTH_MEAN_RADIUS_KM); assertEquals(11, grid.getLevelForDistance(degrees)); }
Example #17
Source File: TestRecursivePrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testFilterWithVariableScanLevel() throws IOException { init(GeohashPrefixTree.getMaxLevelsPossible()); getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS); //execute queries for each prefix grid scan level for(int i = 0; i <= maxLength; i++) { ((RecursivePrefixTreeStrategy)strategy).setPrefixGridScanLevel(i); executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox); } }
Example #18
Source File: TestRecursivePrefixTreeStrategy.java From lucene-solr with Apache License 2.0 | 4 votes |
private void init(int maxLength) { this.maxLength = maxLength; this.ctx = SpatialContext.GEO; GeohashPrefixTree grid = new GeohashPrefixTree(ctx, maxLength); this.strategy = new RecursivePrefixTreeStrategy(grid, getClass().getSimpleName()); }