int hrWidth = reader.getWidth(0); int hrHeight = reader.getHeight(0); final Rectangle actualDim = new Rectangle(0, 0, hrWidth, hrHeight); originalGridRange = new GridEnvelope2D(actualDim); new AffineTransform((AffineTransform) raster2Model); tempTransform.translate(-0.5, -0.5); CRS.transform( ProjectiveTransform.create(tempTransform), new GeneralEnvelope(actualDim)); originalEnvelope.setCoordinateReferenceSystem(crs); highestRes = new double[2]; highestRes[0] = XAffineTransform.getScaleX0(tempTransform); highestRes[1] = XAffineTransform.getScaleY0(tempTransform); } else {
final AffineTransform tr = new AffineTransform(); tr.setToScale(1, f); assertEquals(1, XAffineTransform.getScaleX0(tr), EPS); assertEquals(1, XAffineTransform.getScaleY0(tr), EPS); assertEquals(0, XAffineTransform.getRotation(tr), EPS); assertEquals(1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr)); assertEquals(f, getFlipFromType(tr)); tr.rotate(r); assertEquals(1, XAffineTransform.getScaleX0(tr), EPS); assertEquals(1, XAffineTransform.getScaleY0(tr), EPS); assertEquals(r, XAffineTransform.getRotation(tr), EPS); assertEquals(1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr)); assertEquals(f, getFlipFromType(tr)); assertEquals(1, XAffineTransform.getScaleX0(tr), EPS); assertEquals(1, XAffineTransform.getScaleY0(tr), EPS); assertEquals(r, XAffineTransform.getRotation(tr), EPS); assertEquals(-1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr)); assertEquals(f, getFlipFromType(tr)); assertEquals(2, XAffineTransform.getScaleX0(tr), EPS); assertEquals(3, XAffineTransform.getScaleY0(tr), EPS); assertEquals(0, XAffineTransform.getRotation(tr), EPS); assertEquals(1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr));
CRS.transform(cropWorldToGrid, intersection).toRectangle2D().getBounds(); .next() .toRectangle(); sourceArea = sourceArea.intersection(initialArea); if (sourceArea.isEmpty()) { if (LOGGER.isLoggable(java.util.logging.Level.FINE)) { LOGGER.fine( sourceArea.setRect(readParameters.getSourceRegion()); double decimationScaleY = ((1.0 * sourceArea.height) / raster.getHeight()); final AffineTransform decimationScaleTranform = XAffineTransform.getScaleInstance(decimationScaleX, decimationScaleY); XAffineTransform.getTranslateInstance(sourceArea.x, sourceArea.y); finalRaster2Model.concatenate(CoverageUtilities.CENTER_TO_CORNER); if (!XAffineTransform.isIdentity(afterDecimationTranslateTranform, EPS)) finalRaster2Model.concatenate(afterDecimationTranslateTranform); if (!XAffineTransform.isIdentity(decimationScaleTranform, EPS)) finalRaster2Model.concatenate(decimationScaleTranform);
/** * Returns a global scale factor for the specified affine transform. This scale factor will * combines {@link #getScaleX0} and {@link #getScaleY0}. The way to compute such a "global" * scale is somewhat arbitrary and may change in a future version. */ public static double getScale(final AffineTransform tr) { return 0.5 * (getScaleX0(tr) + getScaleY0(tr)); }
/** * Returns an estimation of the rotation angle in radians. This method assumes that the * specified affine transform is built from arbitrary translations, scales or rotations, but no * shear. If a flip has been applied, then this method assumes that the flipped axis is the * <var>y</var> one in <cite>source CRS</cite> space. For a <cite>grid to world CRS</cite> * transform, this is the row number in grid coordinates. * * @param tr The affine transform to inspect. * @return An estimation of the rotation angle in radians, or {@link Double#NaN NaN} if the * angle can not be estimated. */ public static double getRotation(final AffineTransform tr) { final int flip = getFlip(tr); if (flip != 0) { final double scaleX = getScaleX0(tr); final double scaleY = getScaleY0(tr) * flip; return Math.atan2( tr.getShearY() / scaleY - tr.getShearX() / scaleX, tr.getScaleY() / scaleY + tr.getScaleX() / scaleX); } return Double.NaN; }
HashMap<String, Double> envelopeParams = new HashMap<String, Double>(); Envelope envelope = gridCoverage.getEnvelope(); double[] eastNorth = upperCorner.getCoordinate(); GridGeometry2D gridGeometry = gridCoverage.getGridGeometry(); GridEnvelope2D gridRange = gridGeometry.getGridRange2D(); int height = gridRange.height; int width = gridRange.width; int minY = gridRange.y; AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS(); double xRes = XAffineTransform.getScaleX0(gridToCRS); double yRes = XAffineTransform.getScaleY0(gridToCRS);
XAffineTransform.transform( crsToGrid, (area != null) ? area.getBounds2D() : this.bounds, null); final int xmin = (int) Math.round(bounds.getMinX()); final int xmax = (int) Math.round(bounds.getMaxX()); final int ymax = (int) Math.round(bounds.getMaxY()); gridBounds = new Rectangle(xmin, ymin, xmax - xmin, ymax - ymin); final Dimension tileSize = ImageUtilities.toTileSize(gridBounds.getSize()); final GridSampleDimension band = GridSampleDimension.wrap(getSampleDimension(VISIBLE_BAND)); && crsToGrid.getShearX() == 0 && crsToGrid.getShearY() == 0) { RenderingHints hints = new RenderingHints( gridBounds.width, gridBounds.height, (float) (1 / crsToGrid.getScaleX()), (float) (1 / crsToGrid.getScaleY()), (float) crsToGrid.getTranslateX(),
Rectangle2D r2d = CRS.transform(cropWorldToGrid, intersection).toRectangle2D(); sourceArea.grow(2, 2); sourceArea.setRect(readParameters.getSourceRegion()); double decimationScaleY = ((1.0 * sourceArea.height) / raster.getHeight()); final AffineTransform decimationScaleTranform = XAffineTransform.getScaleInstance(decimationScaleX, decimationScaleY); XAffineTransform.getTranslateInstance(sourceArea.x, sourceArea.y); if (!XAffineTransform.isIdentity( backToBaseLevelScaleTransform, CoverageUtilities.AFFINE_IDENTITY_EPS)) finalRaster2Model.concatenate(backToBaseLevelScaleTransform); if (!XAffineTransform.isIdentity( afterDecimationTranslateTranform, CoverageUtilities.AFFINE_IDENTITY_EPS)) finalRaster2Model.concatenate(afterDecimationTranslateTranform); if (!XAffineTransform.isIdentity( decimationScaleTranform, CoverageUtilities.AFFINE_IDENTITY_EPS)) finalRaster2Model.concatenate(decimationScaleTranform); ? Boolean.FALSE : Boolean.TRUE); if (XAffineTransform.isIdentity( finalRaster2Model, CoverageUtilities.AFFINE_IDENTITY_EPS)) { if (noData != null) {
final RenderedImage sourceImage = sourceCoverage.getRenderedImage(); final GridGeometry2D sourceGridGeometry = ((GridGeometry2D) sourceCoverage.getGridGeometry()); final GridEnvelope2D sourceGridRange = sourceGridGeometry.getGridRange2D(); sourceGridToWorldTransform.createInverse(); XAffineTransform.transform( sourceWorldToGridTransform, cropEnvelope.toRectangle2D(), null); final Rectangle finalRasterArea = finalRasterAreaDouble.getBounds(); Rectangle.intersect(finalRasterArea, sourceGridRange, finalRasterArea); if (finalRasterArea.isEmpty()) { throw new EmptyIntersectionException( "Crop envelope intersects in model space, but not in raster space"); if (finalRasterArea.equals(sourceGridRange) && isSimpleTransform && cropROI == null) return sourceCoverage; Map sourceProperties = sourceCoverage.getProperties(); Map properties = null; if (sourceProperties != null && !sourceProperties.isEmpty()) {
int hrWidth = reader.getWidth(0); int hrHeight = reader.getHeight(0); final Rectangle actualDim = new Rectangle(0, 0, hrWidth, hrHeight); originalGridRange = new GridEnvelope2D(actualDim); raster2Model = ProjectiveTransform.create(new AffineTransform()); crs = AbstractGridFormat.getDefaultCRS(); } else { new AffineTransform((AffineTransform) raster2Model); tempTransform.concatenate(CoverageUtilities.CENTER_TO_CORNER); originalEnvelope = CRS.transform( ProjectiveTransform.create(tempTransform), new GeneralEnvelope(actualDim)); originalEnvelope.setCoordinateReferenceSystem(crs); highestRes[0] = XAffineTransform.getScaleX0(tempTransform); highestRes[1] = XAffineTransform.getScaleY0(tempTransform);
final int height = raster.getHeight(); Rectangle imgBounds = new Rectangle(raster.getMinX(), raster.getMinY(), width, height); Rectangle sourceArea = imageReadParam.getSourceRegion(); new AffineTransform( (AffineTransform) originatingCoverageRequest.getRaster2Model()); finalRaster2Model.concatenate(CoverageUtilities.CENTER_TO_CORNER); double decimationScaleY = ((1.0 * sourceArea.height) / height); final AffineTransform decimationScaleTranform = XAffineTransform.getScaleInstance(decimationScaleX, decimationScaleY); final AffineTransform afterDecimationTranslateTranform = XAffineTransform.getTranslateInstance(sourceArea.x, sourceArea.y); if (!XAffineTransform.isIdentity( afterDecimationTranslateTranform, CoverageUtilities.AFFINE_IDENTITY_EPS)) { finalRaster2Model.concatenate(afterDecimationTranslateTranform); if (!XAffineTransform.isIdentity( decimationScaleTranform, CoverageUtilities.AFFINE_IDENTITY_EPS)) { finalRaster2Model.concatenate(decimationScaleTranform);
final Rectangle sourceArea = CRS.transform(cropWorldToGrid, intersection).toRectangle2D().getBounds(); sourceArea.grow(2, 2); if (sourceArea.isEmpty()) { if (LOGGER.isLoggable(java.util.logging.Level.FINE)){ LOGGER.fine("Got empty area for granuleDescriptor "+this.toString()+ sourceArea.setRect(readParameters.getSourceRegion()); final AffineTransform decimationScaleTranform = XAffineTransform.getScaleInstance(decimationScaleX, decimationScaleY); final AffineTransform afterDecimationTranslateTranform =XAffineTransform.getTranslateInstance(sourceArea.x, sourceArea.y); if(!XAffineTransform.isIdentity(backToBaseLevelScaleTransform, Utils.AFFINE_IDENTITY_EPS)) finalRaster2Model.concatenate(backToBaseLevelScaleTransform); if(!XAffineTransform.isIdentity(afterDecimationTranslateTranform, Utils.AFFINE_IDENTITY_EPS)) finalRaster2Model.concatenate(afterDecimationTranslateTranform); if(!XAffineTransform.isIdentity(decimationScaleTranform, Utils.AFFINE_IDENTITY_EPS)) finalRaster2Model.concatenate(decimationScaleTranform); if(XAffineTransform.isIdentity(finalRaster2Model,Utils.AFFINE_IDENTITY_EPS)) { return new GranuleLoadingResult(raster, granuleLoadingShape, granuleUrl, doFiltering); } else {
final CoordinateReferenceSystem sourceCRS = sourceCoverage.getCoordinateReferenceSystem(); if (targetCRS == null) { if (targetGG != null && targetGG.isDefined(GridGeometry2D.CRS_BITMASK)) { targetCRS = targetGG.getCoordinateReferenceSystem(); } else { if (targetGG != null && targetGG.isDefined(GridGeometry2D.CRS_BITMASK)) { return targetCoverage; if (CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { targetEnvelope.setCoordinateReferenceSystem(targetCRS); if (allSteps.isIdentity() || (allSteps instanceof AffineTransform && XAffineTransform.isIdentity((AffineTransform) allSteps, EPS))) { if (targetBB.equals(sourceBB)) { sourceCoverage, sourceImage, targetGG, null, null, hints, sourceProps); if ((automaticGR || targetBB.equals(sourceBB)) && allSteps instanceof AffineTransform) { if (automaticGG) {
upperCorner[i] = (Double) bbox.getUpperCorner().get(i); requestedEnvelope = new GeneralEnvelope(lowerCorner, upperCorner); requestedEnvelope.setCoordinateReferenceSystem(nativeCRS); requestedEnvelopeInNativeCRS = requestedEnvelope; } else { new GridGeometry2D( PixelInCell.CELL_CENTER, gridToCRS, if (!intersectionEnvelopeInSourceCRS.contains(coverage.getEnvelope2D(), true)) { coverage = WCSUtils.crop(coverage, intersectionEnvelopeInSourceCRS); pixelSizeX = Math.abs(XAffineTransform.getScaleX0(tx)); pixelSizeY = Math.abs(XAffineTransform.getScaleY0(tx)); gridToCRS = new AffineTransform2D(tx); new GridGeometry2D( PixelInCell.CELL_CENTER, gridToCRS, intersectionEnvelope, null); destinationGridGeometry.getGridRange2D(), bandSelectedCoverage.getRenderedImage().getSampleModel()); bandSelectedCoverage.getGridGeometry().equals(destinationGridGeometry); if (reprojectionNeeded || !sameGridGeometry) { final GridCoverage2D reprojectedCoverage =
final AffineTransform modifiedRasterToModel = new AffineTransform(rasterToModel); modifiedRasterToModel.concatenate(CoverageUtilities.CENTER_TO_CORNER);; int minx = range.getLow(0), miny = range.getLow(1); if (minx != 0 || miny != 0) { modifiedRasterToModel.concatenate(AffineTransform.getTranslateInstance(minx, miny)); boolean lonFirst = XAffineTransform.getSwapXY(modifiedRasterToModel) != -1; double rotation = XAffineTransform.getRotation(modifiedRasterToModel);
RenderedImage image = resampledCoverage.getRenderedImage(); new AffineTransform( (AffineTransform2D) resampledCoverage.getGridGeometry().getGridToCRS()); finalRaster2Model.concatenate(CoverageUtilities.CENTER_TO_CORNER); finalRaster2Model.preConcatenate(finalWorldToGridCorner); RasterLayerRequest request = rasterLayerResponse.getRequest(); final Interpolation interpolation = request.getInterpolation(); ? Boolean.FALSE : Boolean.TRUE); if (XAffineTransform.isIdentity(finalRaster2Model, CoverageUtilities.AFFINE_IDENTITY_EPS)) { return image; } else {
return new AffineTransform(); dest = XAffineTransform.inverseTransform(zoom, dest, null); } catch (NoninvertibleTransformException exception) { unexpectedException("setVisibleArea", exception); return new AffineTransform(); final AffineTransform change = AffineTransform.getTranslateInstance( (mask & TRANSLATE_X) != 0 ? dest.getCenterX() : 0, (mask & TRANSLATE_Y) != 0 ? dest.getCenterY() : 0); change.translate((mask & TRANSLATE_X) != 0 ? -source.getCenterX() : 0, (mask & TRANSLATE_Y) != 0 ? -source.getCenterY() : 0); XAffineTransform.round(change); return change;
final double minx = domain.getMinX(); final double maxx = domain.getMaxX(); final double miny = domain.getMinY(); final double maxy = domain.getMaxY(); final int width = (int) (maxx - minx); final double m12 = ordinates[1]; AffineTransform at = new AffineTransform(m00, m10, m01, m11, m02, m12); at.translate(-minx, -miny); XAffineTransform.round(at, 1e-6); LOGGER.log(Level.FINE, "Optimizing the warp into an affine transformation: {0}", at); return new WarpAffine(at);
change = zoom.createInverse(); } catch (NoninvertibleTransformException exception) { unexpectedException("transform", exception); throw new UnsupportedOperationException(); change.translate(((operation & TRANSLATE_X) != 0) ? amount : 0, ((operation & TRANSLATE_Y) != 0) ? amount : 0); } else { throw new UnsupportedOperationException(); change.rotate(amount, centerX, centerY); } else if ((operation & (SCALE_X | SCALE_Y)) != 0) { double sx = 1 / (size.getWidth() * XAffineTransform.getScaleX0(zoom)); double sy = 1 / (size.getHeight() * XAffineTransform.getScaleY0(zoom)); if ((type & UNIFORM_SCALE) == UNIFORM_SCALE) { if (sx > sy) sx = sy; change.concatenate(zoom); XAffineTransform.round(change); transform(change);
g2wd = (AffineTransform) dstGridGeometry.getGridToCRS2D(PixelOrientation.UPPER_LEFT); w2gd = g2wd.createInverse(); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("Can't compute source W2G", e); g2ws = (AffineTransform) src.getGridGeometry().getGridToCRS2D(PixelOrientation.UPPER_LEFT); try { w2gs = g2ws.createInverse(); } catch (NoninvertibleTransformException e) { throw new IllegalArgumentException("Can't compute source W2G", e); CoordinateReferenceSystem sourceCRS = src.getCoordinateReferenceSystem2D(); CoordinateReferenceSystem targetCRS = dstGridGeometry.getCoordinateReferenceSystem2D(); if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { src2dstCRSTransform = CRS.findMathTransform(sourceCRS, targetCRS, true); dst2srcCRSTransform = src2dstCRSTransform.inverse(); if (!src2dstCRSTransform.isIdentity()) { concatenatedForwardTransform = (AffineTransform) w2gd.clone(); concatenatedForwardTransform.concatenate(g2ws); concatenatedBackwardTransform = concatenatedForwardTransform.createInverse(); if (XAffineTransform.isIdentity( concatenatedForwardTransform, 1E-6)) { // TODO improve this check concatenatedForwardTransform = new AffineTransform(); // identity