gpt4 book ai didi

org.geotools.geometry.util.XRectangle2D类的使用及代码示例

转载 作者:知者 更新时间:2024-03-27 14:03:05 27 4
gpt4 key购买 nike

本文整理了Java中org.geotools.geometry.util.XRectangle2D类的一些代码示例,展示了XRectangle2D类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XRectangle2D类的具体详情如下:
包路径:org.geotools.geometry.util.XRectangle2D
类名称:XRectangle2D

XRectangle2D介绍

[英]Serializable, high-performance double-precision rectangle. Instead of using x, y, width and height, this class store rectangle's coordinates into the following fields: #xmin, #xmax, #ymin et #ymax. Methods likes contains and intersects are faster, which make this class more appropriate for using intensively inside a loop. Furthermore, this class work correctly with Double#POSITIVE_INFINITY and Double#NaN values.
[中]可串行化的高性能双精度矩形。该类不使用x、y、宽度和高度,而是将矩形的坐标存储到以下字段中:#xmin、#xmax、#ymin et#ymax。像contains和intersects这样的方法速度更快,这使得这个类更适合在循环中大量使用。此外,这个类可以正确处理双#正#无穷大和双#NaN值。

代码示例

代码示例来源:origin: geotools/geotools

/**
 * Create a rectangle using maximal <var>x</var> and <var>y</var> values rather than width and
 * height. This factory avoid the problem of NaN values when extremums are infinite numbers.
 */
public static XRectangle2D createFromExtremums(
    final double xmin, final double ymin, final double xmax, final double ymax) {
  final XRectangle2D rect = new XRectangle2D();
  rect.xmin = xmin;
  rect.ymin = ymin;
  rect.xmax = xmax;
  rect.ymax = ymax;
  return rect;
}

代码示例来源:origin: geotools/geotools

/**
 * Returns a {@link Rectangle2D} with the same bounds as this {@code Envelope}. This is a
 * convenience method for interoperability with Java2D.
 *
 * @return This envelope as a twp-dimensional rectangle.
 * @throws IllegalStateException if this envelope is not two-dimensional.
 */
public Rectangle2D toRectangle2D() throws IllegalStateException {
  if (ordinates.length == 4) {
    return XRectangle2D.createFromExtremums(
        ordinates[0], ordinates[1], ordinates[2], ordinates[3]);
  } else {
    throw new IllegalStateException(
        Errors.format(ErrorKeys.NOT_TWO_DIMENSIONAL_$1, getDimension()));
  }
}

代码示例来源:origin: geotools/geotools

/** Returns {@code true} if the two rectangles are equals up to an epsilon value. */
public static boolean equalsEpsilon(final Rectangle2D rect1, final Rectangle2D rect2) {
  double dx = 0.5 * Math.abs(rect1.getWidth() + rect2.getWidth());
  double dy = 0.5 * Math.abs(rect1.getHeight() + rect2.getHeight());
  if (dx > 0) dx *= EPS;
  else dx = EPS;
  if (dy > 0) dy *= EPS;
  else dy = EPS;
  return equalsEpsilon(rect1.getMinX(), rect2.getMinX(), dx)
      && equalsEpsilon(rect1.getMinY(), rect2.getMinY(), dy)
      && equalsEpsilon(rect1.getMaxX(), rect2.getMaxX(), dx)
      && equalsEpsilon(rect1.getMaxY(), rect2.getMaxY(), dy);
}

代码示例来源:origin: geotools/geotools

private Rectangle createQueryGridEnvelope(DirectPosition pos) {
    final GridCoverage2DReader reader = sourceRef.get();
    try {
      MathTransform worldToGridTransform =
          reader.getOriginalGridToWorld(PixelInCell.CELL_CORNER).inverse();

      DirectPosition midPos = worldToGridTransform.transform(pos, null);
      int x = (int) midPos.getOrdinate(0);
      int y = (int) midPos.getOrdinate(1);
      int halfWidth = CACHED_RASTER_WIDTH / 2;

      final Rectangle queryRect =
          new Rectangle(
              x - halfWidth, y - halfWidth, CACHED_RASTER_WIDTH, CACHED_RASTER_WIDTH);

      GridEnvelope gridEnv = reader.getOriginalGridRange();
      Rectangle rect =
          new Rectangle(
              gridEnv.getLow(0), gridEnv.getLow(1),
              gridEnv.getSpan(0), gridEnv.getSpan(1));

      XRectangle2D.intersect(queryRect, rect, queryRect);
      return queryRect;

    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  }
}

代码示例来源:origin: geotools/geotools

destination.setRect(xmin, ymin, xmax - xmin, ymax - ymin);
} else {
  destination = XRectangle2D.createFromExtremums(xmin, ymin, xmax, ymax);
            || !(destination instanceof Rectangle2D.Double
                || destination instanceof Rectangle2D.Float))
        || XRectangle2D.equalsEpsilon(
            destination,
            transform(transform, new Envelope2D(null, envelope))

代码示例来源:origin: geotools/geotools

/**
 * Construct a rectangle with the same coordinates than the supplied rectangle.
 *
 * @param rect The rectangle, or {@code null} in none (in which case this constructor is
 *     equivalents to the no-argument constructor). Use {@link #INFINITY} for initializing this
 *     {@code XRectangle2D} with infinite bounds.
 */
public XRectangle2D(final Rectangle2D rect) {
  if (rect != null) {
    setRect(rect);
  }
}

代码示例来源:origin: geotools/geotools

private Rectangle computeRasterArea(
    ReferencedEnvelope computedBBox, MathTransform2D requestedWorldToGrid)
    throws TransformException, FactoryException {
  final ReferencedEnvelope cropBBOXInRequestCRS =
      Utils.reprojectEnvelope(computedBBox, requestCRS, requestedBBox);
  // make sure it falls within the requested envelope
  cropBBOXInRequestCRS.intersection((org.locationtech.jts.geom.Envelope) requestedBBox);
  // now go back to raster space
  Rectangle computedRasterArea =
      new GeneralGridEnvelope(
              CRS.transform(requestedWorldToGrid, cropBBOXInRequestCRS),
              PixelInCell.CELL_CORNER,
              false)
          .toRectangle();
  // intersect with the original requested raster space to be sure that we stay within
  // the requested raster area
  XRectangle2D.intersect(computedRasterArea, requestedRasterArea, computedRasterArea);
  return computedRasterArea;
}

代码示例来源:origin: geotools/geotools

XRectangle2D.createFromExtremums(
        -3943612.4042124213,
        -4078471.954436003,
    XRectangle2D.createFromExtremums(
        -178.49352310409273,
        -88.99136583196398,
assertTrue(XRectangle2D.equalsEpsilon(expected, actual));
expected = XRectangle2D.createFromExtremums(-180, -90, 180, -40.905775004205864);
actual = CRS.transform(operation, envelope, actual);
assertTrue(XRectangle2D.equalsEpsilon(expected, actual));
envelope = XRectangle2D.createFromExtremums(-4000000, -4000000, 300000, 30000);
expected = XRectangle2D.createFromExtremums(-180, -90, 180, -41.03163170198091);
actual = CRS.transform(operation, envelope, actual);
assertTrue(XRectangle2D.equalsEpsilon(expected, actual));

代码示例来源:origin: geotools/geotools

XRectangle2D.intersect(
    coverageRequestedRasterArea,
    coverageRasterArea,

代码示例来源:origin: geotools/geotools

/**
 * Returns a new {@code Rectangle2D} object representing the union of this {@code Rectangle2D}
 * with the specified {@code Rectangle2D}.
 *
 * @param rect the {@code Rectangle2D} to be combined with this {@code Rectangle2D}
 * @return the smallest {@code Rectangle2D} containing both the specified {@code Rectangle2D}
 *     and this {@code Rectangle2D}.
 */
public Rectangle2D createUnion(final Rectangle2D rect) {
  final XRectangle2D r = new XRectangle2D();
  r.xmin = Math.min(xmin, rect.getMinX());
  r.ymin = Math.min(ymin, rect.getMinY());
  r.xmax = Math.max(xmax, rect.getMaxX());
  r.ymax = Math.max(ymax, rect.getMaxY());
  return r;
}

代码示例来源:origin: geotools/geotools

final Rectangle tempRect = finalRange.toRectangle();
  XRectangle2D.intersect(tempRect, requestedDim, tempRect);
  requestedDim.setRect(tempRect);
} catch (TransformException te) {

代码示例来源:origin: geotools/geotools

/**
 * Returns a new {@code Rectangle2D} object representing the intersection of this {@code
 * Rectangle2D} with the specified {@code Rectangle2D}.
 *
 * @param rect the {@code Rectangle2D} to be intersected with this {@code Rectangle2D}
 * @return the largest {@code Rectangle2D} contained in both the specified {@code Rectangle2D}
 *     and in this {@code Rectangle2D}.
 */
public Rectangle2D createIntersection(final Rectangle2D rect) {
  final XRectangle2D r = new XRectangle2D();
  r.xmin = Math.max(xmin, rect.getMinX());
  r.ymin = Math.max(ymin, rect.getMinY());
  r.xmax = Math.min(xmax, rect.getMaxX());
  r.ymax = Math.min(ymax, rect.getMaxY());
  return r;
}

代码示例来源:origin: geotools/geotools

.toRectangle2D()
        .getBounds();
XRectangle2D.intersect(
    sourceArea,
    selectedlevel.rasterDimensions,

代码示例来源:origin: geotools/geotools

new XRectangle2D(
    raster.getMinX() + 0.5,
    raster.getMinY() + 0.5,

代码示例来源:origin: geotools/geotools

sourceArea.grow(2, 2);
XRectangle2D.intersect(
    sourceArea,
    selectedlevel.rasterDimensions,

代码示例来源:origin: geotools/geotools

/**
 * This method is responsible for computing the raster bounds of the final mosaic.
 *
 * @throws TransformException In case transformation fails during the process.
 */
private void initRasterBounds() throws TransformException {
  final GeneralEnvelope tempRasterBounds = CRS.transform(finalWorldToGridCorner, mosaicBBox);
  rasterBounds = tempRasterBounds.toRectangle2D().getBounds();
  // SG using the above may lead to problems since the reason is that may be a little (1 px)
  // bigger
  // than what we need. The code below is a bit better since it uses a proper logic (see
  // GridEnvelope
  // Javadoc)
  rasterBounds =
      new GridEnvelope2D(new Envelope2D(tempRasterBounds), PixelInCell.CELL_CORNER);
  if (rasterBounds.width == 0) rasterBounds.width++;
  if (rasterBounds.height == 0) rasterBounds.height++;
  if (oversampledRequest) rasterBounds.grow(2, 2);
  // make sure the expanded bounds are still within the reach of the granule bounds, not
  // larger
  // (the above expansion might have made them so)
  final GeneralEnvelope levelRasterArea_ =
      CRS.transform(
          finalWorldToGridCorner, request.spatialRequestHelper.getCoverageBBox());
  final GridEnvelope2D levelRasterArea =
      new GridEnvelope2D(new Envelope2D(levelRasterArea_), PixelInCell.CELL_CORNER);
  XRectangle2D.intersect(levelRasterArea, rasterBounds, rasterBounds);
}

代码示例来源:origin: geotools/geotools

XRectangle2D.intersect(
      destinationRasterArea, requestedRasterArea, destinationRasterArea);
} catch (NoninvertibleTransformException e) {

代码示例来源:origin: geotools/geotools

XRectangle2D.intersect(
      destinationRasterArea, requestedRasterArea, destinationRasterArea);
} catch (NoninvertibleTransformException e) {

代码示例来源:origin: geotools/geotools

XRectangle2D.intersect(
    imageBounds,
    rasterLayerResponse.getRasterBounds(),

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com