com.spatial4j.core.shape.Circle Java Examples
The following examples show how to use
com.spatial4j.core.shape.Circle.
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: ShapeReadWriter.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
/** Overloaded to provide a number format. */ public String writeShape(Shape shape, NumberFormat nf) { if (shape instanceof Point) { Point point = (Point) shape; return nf.format(point.getX()) + " " + nf.format(point.getY()); } else if (shape instanceof Rectangle) { Rectangle rect = (Rectangle) shape; return nf.format(rect.getMinX()) + " " + nf.format(rect.getMinY()) + " " + nf.format(rect.getMaxX()) + " " + nf.format(rect.getMaxY()); } else if (shape instanceof Circle) { Circle c = (Circle) shape; return "Circle(" + nf.format(c.getCenter().getX()) + " " + nf.format(c.getCenter().getY()) + " " + "d=" + nf.format(c.getRadius()) + ")"; } return shape.toString(); }
Example #2
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 #3
Source File: OLuceneNearOperator.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft, Object iRight, OCommandContext iContext) { List<Number> left = (List<Number>) iLeft; double lat = left.get(0).doubleValue(); double lon = left.get(1).doubleValue(); Shape shape = SpatialContext.GEO.makePoint(lon, lat); List<Number> right = (List<Number>) iRight; double lat1 = right.get(0).doubleValue(); double lon1 = right.get(1).doubleValue(); Shape shape1 = SpatialContext.GEO.makePoint(lon1, lat1); Map map = (Map) right.get(2); double distance = 0; Number n = (Number) map.get("maxDistance"); if (n != null) { distance = n.doubleValue(); } Point p = (Point) shape1; Circle circle = SpatialContext.GEO.makeCircle(p.getX(), p.getY(), DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM)); double docDistDEG = SpatialContext.GEO.getDistCalc().distance((Point) shape, p); final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM); iContext.setVariable("distance", docDistInKM); return shape.relate(circle) == SpatialRelation.WITHIN; }
Example #4
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 #5
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 #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 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 #8
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 #9
Source File: CircleBuilder.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Circle build() { return SPATIAL_CONTEXT.makeCircle(center.x, center.y, 360 * radius / unit.getEarthCircumference()); }