boolean visit(GridCoverage2D coverage) throws IOException { MathTransform2D mt = coverage.getGridGeometry().getGridToCRS2D(); // cannot do a comparison if (!(mt instanceof AffineTransform2D)) { return false; } AffineTransform2D at = (AffineTransform2D) mt; double scaleX = Math.abs(at.getScaleX()); double scaleY = Math.abs(at.getScaleY()); if (resolution == null) { this.resolution = new double[2]; this.resolution[0] = scaleX; this.resolution[1] = scaleY; return true; } if (compare(scaleX, scaleY, resolution)) { this.resolution[0] = scaleX; this.resolution[1] = scaleY; return true; } else { return false; } }
private void assertCoverageResolution(GridCoverage2D coverage, double resX, double resY) { AffineTransform2D mt = (AffineTransform2D) coverage.getGridGeometry().getGridToCRS2D(); assertEquals(resX, mt.getScaleX(), 1); assertEquals(resY, Math.abs(mt.getScaleY()), 1); }
@Override public MathTransform2D getGridToWorldTransform(ProgressListener listener) throws IOException { return gridGeometry.getGridToCRS2D(PixelOrientation.CENTER); }
/** * Static method for taking the AffineTransform from the List * * @param list * @param index * @return */ private static AffineTransform getAffineTransform(GridGeometry2D gg2D, boolean grid2crs) { MathTransform2D tr = null; if (grid2crs) { tr = gg2D.getGridToCRS2D(PixelOrientation.UPPER_LEFT); } else { tr = gg2D.getCRSToGrid2D(PixelOrientation.UPPER_LEFT); } if (tr instanceof AffineTransform2D) { return (AffineTransform2D) tr; } else { throw new IllegalArgumentException(tr.toString() + " is not an AffineTransform"); } } }
public void setRequestedGridGeometry(GridGeometry2D gridGeometry) { Utilities.ensureNonNull("girdGeometry", gridGeometry); requestedBBox = new ReferencedEnvelope((Envelope) gridGeometry.getEnvelope2D()); requestedRasterArea = gridGeometry.getGridRange2D().getBounds(); requestedGridGeometry = gridGeometry; requestedGridToWorld = (AffineTransform) gridGeometry.getGridToCRS2D(); }
public void setRequestedGridGeometry(GridGeometry2D gridGeometry) { Utilities.ensureNonNull("girdGeometry", gridGeometry); requestedBBox = new ReferencedEnvelope((Envelope) gridGeometry.getEnvelope2D()); requestedRasterArea = gridGeometry.getGridRange2D().getBounds(); requestedGridToWorld = (AffineTransform) gridGeometry.getGridToCRS2D(); }
/** * 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)); } }
g2wd = dst.getGridToCRS2D(PixelOrientation.UPPER_LEFT); g2ws = src.getGridGeometry().getGridToCRS2D(PixelOrientation.UPPER_LEFT);
mt2D = gc2d.getGridGeometry().getGridToCRS2D(PixelOrientation.UPPER_LEFT);
public ReadResolutionCalculator( GridGeometry2D requestedGridGeometry, CoordinateReferenceSystem nativeCrs, double[] fullResolution) throws FactoryException { Utilities.ensureNonNull("gridGeometry", requestedGridGeometry); this.requestedBBox = new ReferencedEnvelope((Envelope) requestedGridGeometry.getEnvelope2D()); this.requestedRasterArea = requestedGridGeometry.getGridRange2D().getBounds(); this.requestedGridToWorld = (AffineTransform) requestedGridGeometry.getGridToCRS2D(); this.fullResolution = fullResolution; // the reader might not know (e.g., wms cascading reader) in this case we // pick the classic computation results, it's better than nothing if (fullResolution == null) { this.fullResolution = computeClassicResolution(); isFullResolutionInRequestedCRS = true; } CoordinateReferenceSystem requestedCRS = requestedGridGeometry.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(nativeCrs, requestedCRS)) { this.destinationToSourceTransform = CRS.findMathTransform(requestedCRS, nativeCrs); } }
final CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem2D(); final MathTransform2D gridToCRS = coverage.getGridGeometry().getGridToCRS2D(); for (int i = 0; i < sources.length; i++) { if (sources[i] == null) { if (!CRS.equalsIgnoreMetadata(crs, source.getCoordinateReferenceSystem2D()) || !CRS.equalsIgnoreMetadata( gridToCRS, source.getGridGeometry().getGridToCRS2D())) { throw new IllegalArgumentException( Errors.format(ErrorKeys.INCOMPATIBLE_GRID_GEOMETRY));
/** * This method creates a new {@link GridGeometry2D} object based on that of the {@link * GridCoverage2D} defined by the index. * * @param sources * @param index * @return */ private static GridGeometry2D extractFinalGridGeometry( GridCoverage2D[] sources, int index) { // Select the GridGeometry of the first coverage GridGeometry2D gg = sources[index].getGridGeometry(); MathTransform g2w = gg.getGridToCRS2D(PixelOrientation.UPPER_LEFT); // Initial Bounding box Envelope2D bbox = gg.getEnvelope2D(); // Number of the sources to use int numSources = sources.length; // Cycle on all the GridCoverages in order to create the final Bounding box for (int i = 0; i < numSources; i++) { bbox.include(sources[i].getEnvelope2D()); } // Creation of a final GridGeometry containing the final Bounding Box GridGeometry2D finalGG = new GridGeometry2D( PixelInCell.CELL_CORNER, g2w, bbox, GeoTools.getDefaultHints()); return finalGG; } }
MathTransform2D mt = reduced.getGridToCRS2D(); if (mt instanceof AffineTransform2D) { AffineTransform2D at = (AffineTransform2D) mt;
crsToCorner2D = getGridToCRS2D(PixelOrientation.UPPER_LEFT).inverse(); } catch (NoninvertibleTransformException nte) { throw new InvalidGridGeometryException(ErrorKeys.NONINVERTIBLE_TRANSFORM);
GridGeometry2D readingGridGeometry; MathTransform2D crsToGrid2D = gg.getCRSToGrid2D(); MathTransform2D gridToCRS2D = gg.getGridToCRS2D(); if (sameCRS) { Envelope gridEnvelope = JTS.transform(polygon, crsToGrid2D).getEnvelopeInternal();
final GridSampleDimension[] bands, final Map<?, ?> properties) { final MathTransform transform = gridGeometry.getGridToCRS2D(); if (!(transform instanceof AffineTransform)) { throw new IllegalArgumentException(Errors.format(ErrorKeys.NOT_AN_AFFINE_TRANSFORM));
try { final MathTransform2D transform = gridGeometry.getGridToCRS2D(PixelOrientation.UPPER_LEFT); toGrid = transform.inverse(); } catch (NoninvertibleTransformException exception) {
new AffineTransform( (AffineTransform) ((GridGeometry2D) coverage.getGridGeometry()).getGridToCRS2D());
(AffineTransform) ((GridGeometry2D) gc.getGridGeometry()).getGridToCRS2D(); final double dx = XAffineTransform.getScaleX0(gridToWorld); final double dy = XAffineTransform.getScaleY0(gridToWorld);