public MCIndexedPointInAreaLocator(Geometry g) {
   areaGeom = g;
   if (!(g instanceof Polygonal)) throw new IllegalArgumentException("Argument must be Polygonal");
   buildIndex(g);
   Envelope env = g.getEnvelopeInternal();
   maxXExtent = env.getMaxX() + 1.0;
 }
示例#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);
  }