public static double diagonalSize(Envelope env) {
    if (env.isNull()) return 0.0;

    double width = env.getWidth();
    double hgt = env.getHeight();
    return Math.sqrt(width * width + hgt * hgt);
  }
Exemplo n.º 2
0
  /**
   * Creates a {@link Geometry} with the same extent as the given envelope. The Geometry returned is
   * guaranteed to be valid. To provide this behaviour, the following cases occur:
   *
   * <p>If the <code>Envelope</code> is:
   *
   * <ul>
   *   <li>null : returns an empty {@link Point}
   *   <li>a point : returns a non-empty {@link Point}
   *   <li>a line : returns a two-point {@link LineString}
   *   <li>a rectangle : returns a {@link Polygon} whose points are (minx, miny), (minx, maxy),
   *       (maxx, maxy), (maxx, miny), (minx, miny).
   * </ul>
   *
   * @param envelope the <code>Envelope</code> to convert
   * @return an empty <code>Point</code> (for null <code>Envelope</code>s), a <code>Point</code>
   *     (when min x = max x and min y = max y) or a <code>Polygon</code> (in all other cases)
   */
  public Geometry toGeometry(Envelope envelope) {
    // null envelope - return empty point geometry
    if (envelope.isNull()) {
      return createPoint((CoordinateSequence) null);
    }

    // point?
    if (envelope.getMinX() == envelope.getMaxX() && envelope.getMinY() == envelope.getMaxY()) {
      return createPoint(new Coordinate(envelope.getMinX(), envelope.getMinY()));
    }

    // vertical or horizontal line?
    if (envelope.getMinX() == envelope.getMaxX() || envelope.getMinY() == envelope.getMaxY()) {
      return createLineString(
          new Coordinate[] {
            new Coordinate(envelope.getMinX(), envelope.getMinY()),
            new Coordinate(envelope.getMaxX(), envelope.getMaxY())
          });
    }

    // create a CW ring for the polygon
    return createPolygon(
        createLinearRing(
            new Coordinate[] {
              new Coordinate(envelope.getMinX(), envelope.getMinY()),
              new Coordinate(envelope.getMinX(), envelope.getMaxY()),
              new Coordinate(envelope.getMaxX(), envelope.getMaxY()),
              new Coordinate(envelope.getMaxX(), envelope.getMinY()),
              new Coordinate(envelope.getMinX(), envelope.getMinY())
            }),
        null);
  }
Exemplo n.º 3
0
 /**
  * Tests if the <code>Envelope other</code> lies wholely inside this <code>Envelope</code>
  * (inclusive of the boundary).
  *
  * @param other the <code>Envelope</code> to check
  * @return true if this <code>Envelope</code> covers the <code>other</code>
  */
 @Override
 public boolean covers(final Envelope other) {
   if (isNull() || other.isNull()) {
     return false;
   }
   if (!super.covers(other)) {
     return false;
   }
   return getMinZOf(other) >= minz && getMaxZOf(other) <= maxz;
 }
Exemplo n.º 4
0
 /**
  * Computes the intersection of two {@link Envelope}s.
  *
  * @param env the envelope to intersect with
  * @return a new Envelope representing the intersection of the envelopes (this will be the null
  *     envelope if either argument is null, or they do not intersect
  */
 @Override
 public Envelope3D intersection(final Envelope env) {
   if (isNull() || env.isNull() || !intersects(env)) {
     return new Envelope3D();
   }
   Envelope xyInt = super.intersection(env);
   double otherMinZ = getMinZOf(env);
   double intMinZ = minz > otherMinZ ? minz : otherMinZ;
   double otherMaxZ = getMaxZOf(env);
   double intMaxZ = maxz < otherMaxZ ? maxz : otherMaxZ;
   return new Envelope3D(
       xyInt.getMinX(), xyInt.getMaxX(), xyInt.getMinY(), xyInt.getMaxY(), intMinZ, intMaxZ);
 }
Exemplo n.º 5
0
 /**
  * Enlarges this <code>Envelope</code> so that it contains the <code>other</code> Envelope. Has no
  * effect if <code>other</code> is wholly on or within the envelope.
  *
  * @param other the <code>Envelope</code> to expand to include
  */
 @Override
 public void expandToInclude(final Envelope other) {
   if (other.isNull()) {
     return;
   }
   double otherMinZ = getMinZOf(other);
   double otherMaxZ = getMaxZOf(other);
   if (isNull()) {
     super.expandToInclude(other);
     minz = otherMinZ;
     maxz = otherMaxZ;
   } else {
     super.expandToInclude(other);
     if (otherMinZ < minz) {
       minz = otherMinZ;
     }
     if (otherMaxZ > maxz) {
       maxz = otherMaxZ;
     }
   }
 }