/** * Transforms a point represented by a GridCoordinates2D object from grid to world coordinates. * The coordinates returned are those of the centre of the grid cell in which the point lies. * * <p>Users needing more control over the nature of the conversion (e.g. calculating cell corner * coordinates) can use the {@code MathsTransform} provided by {@linkplain * GridGeometry2D#getGridToCRS2D(PixelOrientation) } which is accessed via {@linkplain * #getGridGeometry()}. * * @param point The point in world coordinate system. * @return A new point in the grid coordinate system as a GridCoordinates2D object * @throws TransformException if the transformation failed. * @throws IllegalArgumentException if the point lies outside the coverage * @since 2.6 */ public final DirectPosition gridToWorld(final GridCoordinates2D point) throws TransformException { if (getGridRange2D().contains(point)) { Point2D trPoint = getGridToCRS2D().transform(point, null); return new DirectPosition2D( getCoordinateReferenceSystem2D(), trPoint.getX(), trPoint.getY()); } else { throw new IllegalArgumentException( Errors.format(ErrorKeys.POINT_OUTSIDE_COVERAGE_$1, point)); } }
/** * Transforms a rectangle represented by a GridEnvelope2D object from grid to world coordinates. * The bounds of the Envelope2D object returned correspond to the outer edges of the grid cells * within the input envelope. * * <p>Users needing more control over the nature of the conversion can use the {@code * MathsTransform} provided by {@linkplain GridGeometry2D#getGridToCRS2D(PixelOrientation) } * which is accessed via {@linkplain #getGridGeometry()}. * * @param gridEnv The rectangle of grid coordinates to convert * @return World coordinates of the rectangle as a new Envelope2D object * @throws TransformException if the transformation failed. * @throws IllegalArgumentException if the input rectangle lies outside the coverage * @since 2.6 */ public final Envelope2D gridToWorld(final GridEnvelope2D gridEnv) throws TransformException { MathTransform2D mt = getGridToCRS2D(); if (getGridRange2D().contains(gridEnv)) { GridCoordinates2D low = gridEnv.getLow(); Point2D trLow = mt.transform(new Point2D.Double(low.x - 0.5, low.y - 0.5), null); GridCoordinates2D high = gridEnv.getHigh(); Point2D trHigh = mt.transform(new Point2D.Double(high.x + 0.5, high.y + 0.5), null); return new Envelope2D( new DirectPosition2D(crs2D, trLow.getX(), trLow.getY()), new DirectPosition2D(crs2D, trHigh.getX(), trHigh.getY())); } else { throw new IllegalArgumentException( Errors.format(ErrorKeys.POINT_OUTSIDE_COVERAGE_$1, gridEnv)); } }
fullTilesRaster.getWidth(), fullTilesRaster.getHeight()); if (!origDim.contains(crop)) { throw new IllegalArgumentException( "Original image ("
/** Maps the provided point from destination space to source space for the provided source. */ @Override public Point2D mapDestPoint(Point2D destPt, int sourceIndex) { if (destPt == null) { throw new IllegalArgumentException("Bad dest pt"); // JaiI18N.getString("Generic0")); } if (sourceIndex < 0 || sourceIndex >= getNumSources()) { throw new IndexOutOfBoundsException("Bad src"); // JaiI18N.getString("Generic1")); } double coords[] = new double[] {destPt.getX(), destPt.getY()}; try { mapDestPoint(coords); } catch (TransformException e) { LOGGER.log(Level.WARNING, "Error transforming coords", e); return null; } Point2D ret = ((Point2D) destPt.clone()); ret.setLocation(coords[0], coords[1]); if (src.getGridGeometry().getGridRange2D().contains(coords[0], coords[1])) return ret; else return null; }
if (dstGridGeometry.getGridRange2D().contains(ret)) return ret; else { LOGGER.log(
/** * Transforms a point represented by a GridCoordinates2D object from grid * to world coordinates. The coordinates returned are those of the centre * of the grid cell in which the point lies. * <p> * Users needing more control over the nature of the conversion (e.g. calculating * cell corner coordinates) can use the {@code MathsTransform} provided by * {@linkplain GridGeometry2D#getGridToCRS2D(PixelOrientation) } * which is accessed via {@linkplain #getGridGeometry()}. * * @param point The point in world coordinate system. * @return A new point in the grid coordinate system as a GridCoordinates2D object * * @throws TransformException if the transformation failed. * * @throws IllegalArgumentException if the point lies outside the coverage * * @since 2.6 */ public final DirectPosition gridToWorld(final GridCoordinates2D point) throws TransformException { if (getGridRange2D().contains(point)) { Point2D trPoint = getGridToCRS2D().transform(point, null); return new DirectPosition2D(getCoordinateReferenceSystem2D(), trPoint.getX(), trPoint.getY()); } else { throw new IllegalArgumentException( Errors.format(ErrorKeys.POINT_OUTSIDE_COVERAGE_$1, point)); } }
if (getGridRange2D().contains(gridEnv)) { GridCoordinates2D low = gridEnv.getLow(); Point2D trLow = mt.transform(new Point2D.Double(low.x - 0.5, low.y - 0.5), null);
if (!origDim.contains(crop)) { throw new IllegalArgumentException("Original image (" + origDim + ") does not contain desired dimension (" + crop + ")");