/** * All {@link Circle} implementations should use this definition of {@link Object#equals(Object)}. */ public static boolean equals(Circle thiz, Object o) { assert thiz != null; if (thiz == o) return true; if (!(o instanceof Circle)) return false; Circle circle = (Circle) o; if (!thiz.getCenter().equals(circle.getCenter())) return false; if (Double.compare(circle.getRadius(), thiz.getRadius()) != 0) return false; return true; }
@Override public double area(Circle circle) { return circle.getArea(null); }
@Override public Query makeQuery(SpatialArgs args) { if(! SpatialOperation.is( args.getOperation(), SpatialOperation.Intersects, SpatialOperation.IsWithin )) throw new UnsupportedSpatialOperation(args.getOperation()); Shape shape = args.getShape(); if (shape instanceof Rectangle) { Rectangle bbox = (Rectangle) shape; return new ConstantScoreQuery(makeWithin(bbox)); } else if (shape instanceof Circle) { Circle circle = (Circle)shape; Rectangle bbox = circle.getBoundingBox(); return new DistanceRangeQuery(makeWithin(bbox), makeDistanceValueSource(circle.getCenter()), circle.getRadius()); } else { throw new UnsupportedOperationException("Only Rectangles and Circles are currently supported, " + "found [" + shape.getClass() + "]");//TODO } }
if (circle.getBoundingBox().getCrossesDateLine()) throw new IllegalArgumentException("Doesn't support dateline cross yet: "+circle);//TODO GeometricShapeFactory gsf = new GeometricShapeFactory(geometryFactory); gsf.setSize(circle.getBoundingBox().getWidth()); gsf.setNumPoints(4*25);//multiple of 4 is best gsf.setCentre(new Coordinate(circle.getCenter().getX(), circle.getCenter().getY())); return gsf.createCircle();
/** * Returns the radius in kilometers of this circle. Only applicable to circle shapes. * @return */ public double getRadius() { Preconditions.checkArgument(getType()==Type.CIRCLE,"This shape is not a circle"); double radiusInDeg = ((Circle) shape).getRadius(); return DistanceUtils.degrees2Dist(radiusInDeg, DistanceUtils.EARTH_MEAN_RADIUS_KM); }
@Override public Rectangle calcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse) { Circle circle = ctx.getShapeFactory().circle(from, distDEG); return circle.getBoundingBox(); }
@Override public double area(Circle circle) { //formula is a simplified case of area(rect). double lat = toRadians(90 - circle.getRadius()); return 2 * Math.PI * radiusDEG * radiusDEG * (1 - Math.sin(lat)); }
org.locationtech.jts.geom.Point point = (org.locationtech.jts.geom.Point) geom; SpatialRelation rel = calcSqd.distance(circle.getCenter(), point.getX(), point.getY()) > radiusSquared ? SpatialRelation.DISJOINT : SpatialRelation.WITHIN; result[0] = rel.combine(result[0]);
/** * All {@link Circle} implementations should use this definition of {@link Object#hashCode()}. */ public static int hashCode(Circle thiz) { int result; long temp; result = thiz.getCenter().hashCode(); temp = thiz.getRadius() != +0.0d ? Double.doubleToLongBits(thiz.getRadius()) : 0L; result = 31 * result + (int) (temp ^ (temp >>> 32)); return result; } }
@Override public int compareTo(Object o) { Circle circle = (Circle) o; return Double.compare(getArea(), circle.getArea()); }
public SpatialRelation relate(Circle circle) { double crossDist = ctx.getDistCalc().distance(point, circle.getCenter()); double aDist = radiusDEG, bDist = circle.getRadius(); if (crossDist > aDist + bDist) return SpatialRelation.DISJOINT; if (crossDist < aDist && crossDist + bDist <= aDist) return SpatialRelation.CONTAINS; if (crossDist < bDist && crossDist + aDist <= bDist) return SpatialRelation.WITHIN; return SpatialRelation.INTERSECTS; }
/** Overloaded to provide a number format. */ public static 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(); }