示例#1
0
 @Override
 public Rectangle calcBoxByDistFromPt(
     Point from, double distDEG, SpatialContext ctx, Rectangle reuse) {
   double minX = from.getX() - distDEG;
   double maxX = from.getX() + distDEG;
   double minY = from.getY() - distDEG;
   double maxY = from.getY() + distDEG;
   if (reuse == null) {
     return ctx.makeRectangle(minX, maxX, minY, maxY);
   } else {
     reuse.reset(minX, maxX, minY, maxY);
     return reuse;
   }
 }
  /**
   * Spatial4J shapes have no knowledge of directed edges. For this reason, a bounding box that
   * wraps the dateline can have a min longitude that is mathematically > than the Rectangles'
   * minX value. This is an issue for geometric collections (e.g., MultiPolygon and ShapeCollection)
   * Until geometry logic can be cleaned up in Spatial4J, ES provides the following expansion
   * algorithm for GeometryCollections
   */
  private Rectangle expandBBox(Rectangle bbox, Rectangle expand) {
    if (bbox.equals(expand) || bbox.equals(SpatialContext.GEO.getWorldBounds())) {
      return bbox;
    }

    double minX = bbox.getMinX();
    double eMinX = expand.getMinX();
    double maxX = bbox.getMaxX();
    double eMaxX = expand.getMaxX();
    double minY = bbox.getMinY();
    double eMinY = expand.getMinY();
    double maxY = bbox.getMaxY();
    double eMaxY = expand.getMaxY();

    bbox.reset(
        Math.min(Math.min(minX, maxX), Math.min(eMinX, eMaxX)),
        Math.max(Math.max(minX, maxX), Math.max(eMinX, eMaxX)),
        Math.min(Math.min(minY, maxY), Math.min(eMinY, eMaxY)),
        Math.max(Math.max(minY, maxY), Math.max(eMinY, eMaxY)));

    return bbox;
  }