return new Geoshape.Point(shape.getBoundingBox().getMinY(), shape.getBoundingBox().getMinX()); else return new Geoshape.Point(shape.getBoundingBox().getMaxY(), shape.getBoundingBox().getMaxX()); case GEOMETRYCOLLECTION: return ((ShapeCollection<Shape>) shape).getShapes().stream()
public static Range yRange(Rectangle rect, SpatialContext ctx) { return new Range(rect.getMinY(), rect.getMaxY()); }
@Override public double area(Rectangle rect) { //From http://mathforum.org/library/drmath/view/63767.html double lat1 = toRadians(rect.getMinY()); double lat2 = toRadians(rect.getMaxY()); return Math.PI / 180 * radiusDEG * radiusDEG * Math.abs(Math.sin(lat1) - Math.sin(lat2)) * rect.getWidth(); }
/** * All {@link Rectangle} implementations should use this definition of {@link Object#hashCode()}. */ public static int hashCode(Rectangle thiz) { int result; long temp; temp = thiz.getMinX() != +0.0d ? Double.doubleToLongBits(thiz.getMinX()) : 0L; result = (int) (temp ^ (temp >>> 32)); temp = thiz.getMaxX() != +0.0d ? Double.doubleToLongBits(thiz.getMaxX()) : 0L; result = 31 * result + (int) (temp ^ (temp >>> 32)); temp = thiz.getMinY() != +0.0d ? Double.doubleToLongBits(thiz.getMinY()) : 0L; result = 31 * result + (int) (temp ^ (temp >>> 32)); temp = thiz.getMaxY() != +0.0d ? Double.doubleToLongBits(thiz.getMaxY()) : 0L; result = 31 * result + (int) (temp ^ (temp >>> 32)); return result; } }
/** Copy constructor. */ public RectangleImpl(Rectangle r, SpatialContext ctx) { this(r.getMinX(), r.getMaxX(), r.getMinY(), r.getMaxY(), ctx); }
@Override public void verifyY(double y) { Rectangle bounds = ctx.getWorldBounds(); if (y < bounds.getMinY() || y > bounds.getMaxY())//NaN will pass throw new InvalidShapeException("Bad Y value "+y+" is not in boundary "+bounds); }
/** * All {@link Rectangle} implementations should use this definition of {@link Object#equals(Object)}. */ public static boolean equals(Rectangle thiz, Object o) { assert thiz != null; if (thiz == o) return true; if (!(o instanceof Rectangle)) return false; RectangleImpl rectangle = (RectangleImpl) o; if (Double.compare(rectangle.getMaxX(), thiz.getMaxX()) != 0) return false; if (Double.compare(rectangle.getMaxY(), thiz.getMaxY()) != 0) return false; if (Double.compare(rectangle.getMinX(), thiz.getMinX()) != 0) return false; if (Double.compare(rectangle.getMinY(), thiz.getMinY()) != 0) return false; return true; }
/** 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(); }
public static void cornerByQuadrant(Rectangle r, int cornerQuad, Point out) { double x = (cornerQuad == 1 || cornerQuad == 4) ? r.getMaxX() : r.getMinX(); double y = (cornerQuad == 1 || cornerQuad == 2) ? r.getMaxY() : r.getMinY(); out.reset(x, y); }
public void expandRange(Rectangle rect) { expandRange(rect.getMinX(), rect.getMaxX(), rect.getMinY(), rect.getMaxY()); }
/** * Decodes the given geohash into a longitude (X) and latitude (Y) */ public static Point decode(String geohash, SpatialContext ctx) { Rectangle rect = decodeBoundary(geohash,ctx); double latitude = (rect.getMinY() + rect.getMaxY()) / 2D; double longitude = (rect.getMinX() + rect.getMaxX()) / 2D; return ctx.makePoint(longitude,latitude); }
double newMaxX = Math.min(worldBounds.getMaxX(), maxX + distance); double newMinY = Math.max(worldBounds.getMinY(), minY - distance); double newMaxY = Math.min(worldBounds.getMaxY(), maxY + distance); return ctx.makeRectangle(newMinX, newMaxX, newMinY, newMaxY);
public void writeRect(DataOutput dataOutput, Rectangle r) throws IOException { writeDim(dataOutput, r.getMinX()); writeDim(dataOutput, r.getMaxX()); writeDim(dataOutput, r.getMinY()); writeDim(dataOutput, r.getMaxY()); }
/** Returns either 0 for none, 1 for some, or 4 for all. */ private int numCornersIntersect(Rectangle r) { //We play some logic games to avoid calling contains() which can be expensive. boolean bool;//if true then all corners intersect, if false then no corners intersect // for partial, we exit early with 1 and ignore bool. bool = (contains(r.getMinX(),r.getMinY())); if (contains(r.getMinX(),r.getMaxY())) { if (!bool) return 1;//partial } else { if (bool) return 1;//partial } if (contains(r.getMaxX(),r.getMinY())) { if (!bool) return 1;//partial } else { if (bool) return 1;//partial } if (contains(r.getMaxX(),r.getMaxY())) { if (!bool) return 1;//partial } else { if (bool) return 1;//partial } return bool?4:0; }
public SpatialRelation relate(Rectangle rect) { SpatialRelation yIntersect = relateYRange(rect.getMinY(), rect.getMaxY()); if (yIntersect == SpatialRelation.DISJOINT) return SpatialRelation.DISJOINT; SpatialRelation xIntersect = relateXRange(rect.getMinX(), rect.getMaxX()); if (xIntersect == SpatialRelation.DISJOINT) return SpatialRelation.DISJOINT; if (xIntersect == yIntersect)//in agreement return xIntersect; //if one side is equal, return the other if (getMinY() == rect.getMinY() && getMaxY() == rect.getMaxY()) return xIntersect; if (getMinX() == rect.getMinX() && getMaxX() == rect.getMaxX() || (ctx.isGeo() && verticalAtDateline(this, rect))) { return yIntersect; } return SpatialRelation.INTERSECTS; }
if (bounds.getMinX() > bounds.getMaxX()) throw new IllegalArgumentException("worldBounds minX should be <= maxX: "+ bounds); if (bounds.getMinY() > bounds.getMaxY()) throw new IllegalArgumentException("worldBounds minY should be <= maxY: "+ bounds);
Collection<Geometry> pair = new ArrayList<>(2); pair.add(geometryFactory.toGeometry(new Envelope( r.getMinX(), ctx.getWorldBounds().getMaxX(), r.getMinY(), r.getMaxY()))); pair.add(geometryFactory.toGeometry(new Envelope( ctx.getWorldBounds().getMinX(), r.getMaxX(), r.getMinY(), r.getMaxY()))); return geometryFactory.buildGeometry(pair);//a MultiPolygon or MultiLineString } else { return geometryFactory.toGeometry(new Envelope(r.getMinX(), r.getMaxX(), r.getMinY(), r.getMaxY()));
@Override public Rectangle rect(double minX, double maxX, double minY, double maxY) { Rectangle bounds = ctx.getWorldBounds(); // Y if (minY < bounds.getMinY() || maxY > bounds.getMaxY())//NaN will pass throw new InvalidShapeException("Y values ["+minY+" to "+maxY+"] not in boundary "+bounds); if (minY > maxY) throw new InvalidShapeException("maxY must be >= minY: " + minY + " to " + maxY); // X if (ctx.isGeo()) { verifyX(minX); verifyX(maxX); //TODO consider removing this logic so that there is no normalization here //if (minX != maxX) { USUALLY TRUE, inline check below //If an edge coincides with the dateline then don't make this rect cross it if (minX == 180 && minX != maxX) { minX = -180; } else if (maxX == -180 && minX != maxX) { maxX = 180; } //} } else { if (minX < bounds.getMinX() || maxX > bounds.getMaxX())//NaN will pass throw new InvalidShapeException("X values ["+minX+" to "+maxX+"] not in boundary "+bounds); if (minX > maxX) throw new InvalidShapeException("maxX must be >= minX: " + minX + " to " + maxX); } return new RectangleImpl(minX, maxX, minY, maxY, ctx); }
double yBotOverlap = -90 - yBot; assert yBotOverlap <= 90; if (r.getMaxY() <= -90 + yBotOverlap) return SpatialRelation.CONTAINS; } else {