/**
   * Calculate the rectangle that belongs to the given destination envelope in the given source
   * image.
   */
  private Object[] calcRegionRectangle(
      Envelope dstenv, Envelope srcenv, double srcwidth, double srcheight) {
    GeoTransform gt =
        new WorldToScreenTransform(
            srcenv.getMin().getX(),
            srcenv.getMin().getY(),
            srcenv.getMax().getX(),
            srcenv.getMax().getY(),
            0,
            0,
            srcwidth - 1,
            srcheight - 1);

    int minx = (int) Math.round(gt.getDestX(dstenv.getMin().getX()));
    int miny = (int) Math.round(gt.getDestY(dstenv.getMax().getY()));
    int maxx = (int) Math.round(gt.getDestX(dstenv.getMax().getX()));
    int maxy = (int) Math.round(gt.getDestY(dstenv.getMin().getY()));
    Rectangle rect = new Rectangle(minx, miny, maxx - minx + 1, maxy - miny + 1);
    LonLatEnvelope lonLatEnvelope = calcLonLatEnvelope(dstenv, getNativeSRSCode());

    return new Object[] {rect, dstenv, lonLatEnvelope};
  }
  /**
   * renders one point to the submitted graphic context considering the also submitted projection
   *
   * @param g
   * @param point
   * @param projection
   * @param image
   * @param dis displacement
   */
  private void drawPoint(
      Graphics2D g, Point point, GeoTransform projection, Image image, double[] dis) {
    Envelope destSize = projection.getDestRect();
    Position source = point.getPosition();
    int x = (int) Math.round(projection.getDestX(source.getX()) + 0.5 + dis[0]);
    int y = (int) Math.round(projection.getDestY(source.getY()) + 0.5 + dis[1]);

    int x_ = x - (image.getWidth(null) >> 1);
    int y_ = y - (image.getHeight(null) >> 1);

    int dx = Math.min(image.getWidth(null), (int) destSize.getWidth() - x_);
    int dy = Math.min(image.getHeight(null), (int) destSize.getHeight() - y_);
    int tx = Math.min((int) destSize.getWidth(), x_ + image.getWidth(null));
    int ty = Math.min((int) destSize.getHeight(), y_ + image.getHeight(null));

    g.drawImage(image, x_, y_, tx, ty, 0, 0, dx, dy, null);
  }