envelope = CRS.transform(envelope, destCRS); } catch (TransformException e) { throw (IOException)
GridGeometry2D gg = coverage.getGridGeometry(); GeneralEnvelope padRange = CRS.transform(gg.getCRSToGrid2D(PixelOrientation.UPPER_LEFT), bounds); GridEnvelope2D targetRange = new GridEnvelope2D(
final GeneralEnvelope targetEnvelope; if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { targetEnvelope = CRS.transform(envelope, targetCRS); } else { targetEnvelope = new GeneralEnvelope(envelope);
CRS.transform(gridToWorldCorner, new GeneralEnvelope(testRange.getBounds())); testEnvelope.setCoordinateReferenceSystem(reader.getCoordinateReferenceSystem());
/** * Transforms an envelope using the given {@linkplain MathTransform math transform}. The * transformation is only approximative. Note that the returned envelope may not have the same * number of dimensions than the original envelope. * * <p>Note that this method can not handle the case where the envelope contains the North or * South pole, or when it cross the ±180° longitude, because {@linkplain MathTransform * math transforms} do not carry suffisient informations. For a more robust envelope * transformation, use {@link #transform(CoordinateOperation, Envelope)} instead. * * @param transform The transform to use. * @param envelope Envelope to transform, or {@code null}. This envelope will not be modified. * @return The transformed envelope, or {@code null} if {@code envelope} was null. * @throws TransformException if a transform failed. * @since 2.4 * @see #transform(CoordinateOperation, Envelope) */ public static GeneralEnvelope transform(final MathTransform transform, final Envelope envelope) throws TransformException { return transform(transform, envelope, null); }
final CoordinateReferenceSystem nativeCRS = reader.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(requestCRS, nativeCRS)) { requestedEnvelope = CRS.transform(requestedEnvelope, nativeCRS); GeneralEnvelope requestedGrid = CRS.transform(crsToGrid, requestedEnvelope); double[] spans = new double[requestedGrid.getDimension()]; double[] resolutions = new double[requestedGrid.getDimension()];
/** * Returns the pixel coordinate of a rectangle containing the specified geographic area. If the * rectangle can't be computed, then this method returns {@code null}. */ final Rectangle inverseTransform(Rectangle2D bounds) { if (bounds != null && gridFromCRS2D != null) { try { bounds = org.geotools.referencing.CRS.transform(gridFromCRS2D, bounds, null); final int xmin = (int) Math.floor(bounds.getMinX() - 0.5); final int ymin = (int) Math.floor(bounds.getMinY() - 0.5); final int xmax = (int) Math.ceil(bounds.getMaxX() - 0.5); final int ymax = (int) Math.ceil(bounds.getMaxY() - 0.5); return new Rectangle(xmin, ymin, xmax - xmin, ymax - ymin); } catch (TransformException exception) { // Ignore, since this method is invoked from 'GridCoverage.prefetch' only. // It doesn't matter if the transformation failed; 'prefetch' is just a hint. } } return null; }
/** * @see org.geotools.coverage.io.CoverageReadRequest#setDomainSubset(java.awt.Rectangle, * org.opengis.referencing.operation.MathTransform2D, * org.opengis.referencing.crs.CoordinateReferenceSystem) */ public void setDomainSubset( final Rectangle rasterArea, final MathTransform2D gridToWorldTrasform, final CoordinateReferenceSystem crs) throws MismatchedDimensionException, TransformException { // get input elements this.rasterArea = (Rectangle) rasterArea.clone(); this.gridToWorldTransform = gridToWorldTrasform; // create a bbox GeneralEnvelope env = CRS.transform( gridToWorldTrasform, new ReferencedEnvelope(rasterArea.getBounds2D(), crs)); this.geographicArea = new ReferencedEnvelope(new ReferencedEnvelope(env), crs); }
public BoundingBox toBounds(CoordinateReferenceSystem targetCRS) throws TransformException { Envelope transformed = new GeneralEnvelope((BoundingBox) this); transformed = CRS.transform(transformed, targetCRS); return new Envelope2D(transformed); }
/** Sets BBOX and SRS using the provided Envelope. */ public void setBBox(Envelope envelope) { String version = properties.getProperty(VERSION); boolean forceXY = version == null || !version.startsWith("1.3"); String srsName = CRS.toSRS(envelope.getCoordinateReferenceSystem()); CoordinateReferenceSystem crs = toServerCRS(srsName, forceXY); Envelope bbox; try { bbox = CRS.transform(envelope, crs); } catch (TransformException e) { bbox = envelope; } StringBuffer sb = new StringBuffer(); sb.append(bbox.getMinimum(0)); sb.append(","); sb.append(bbox.getMinimum(1) + ","); sb.append(bbox.getMaximum(0) + ","); sb.append(bbox.getMaximum(1)); setBBox(sb.toString()); } /**
private void setEnvelopeFromTransform(AffineTransform tempTransform) throws TransformException { final GeneralEnvelope envelope = CRS.transform( ProjectiveTransform.create(tempTransform), new GeneralEnvelope(nativeGridRange)); envelope.setCoordinateReferenceSystem(crs); setCoverageEnvelope(envelope); }
/** * Return a crop region from a specified envelope, leveraging on the grid to world * transformation. * * @param refinedRequestedBBox the crop envelope * @return a {@code Rectangle} representing the crop region. * @throws TransformException in case a problem occurs when going back to raster space. */ private Rectangle getCropRegion() throws TransformException { final MathTransform gridToWorldTransform = getOriginalGridToWorld(PixelInCell.CELL_CORNER); final MathTransform worldToGridTransform = gridToWorldTransform.inverse(); final GeneralEnvelope rasterArea = CRS.transform(worldToGridTransform, requestedBBox); final Rectangle2D ordinates = rasterArea.toRectangle2D(); // THIS IS FUNDAMENTAL IN ORDER TO AVOID PROBLEMS WHEN DOING TILING return ordinates.getBounds(); }
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; }
public void testTransformLambertAzimuthalEqualAreaWgs84NonPolar() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3035", true); // a bbox that does _not_ include the pole Envelope2D envelope = new Envelope2D(crs); envelope.setFrameFromDiagonal(4029000, 2676000, 4696500, 3567700); Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); // check we did _not_ get the whole range of longitudes assertEquals(5.42, transformed.getMinimum(0), 1e-2); assertEquals(15.88, transformed.getMaximum(0), 1e-2); }
public void testTransformPolarStereographicToOther() throws Exception { CoordinateReferenceSystem antarcticPs = CRS.decode("EPSG:3031", true); CoordinateReferenceSystem australianPs = CRS.decode("EPSG:3032", true); Envelope2D envelope = new Envelope2D(antarcticPs); envelope.add(-4223632.8125, -559082.03125); envelope.add(5053710.9375, 3347167.96875); Envelope transformed = CRS.transform(envelope, australianPs); // has a false easting and northing, we can only check the spans are equal assertEquals(transformed.getSpan(0), transformed.getSpan(1), 1d); assertEquals(transformed.getMaximum(0), 1.2309982175378662E7, 1d); }
public void testTransformLambertAzimuthalEqualAreaWgs84() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3574", true); Envelope2D envelope = new Envelope2D(crs); // random bbox that does include the pole envelope.add(-3142000, -3142000); envelope.add(3142000, 3142000); Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); // check we got the whole range of longitudes, since the original bbox contains the pole assertEquals(-180d, transformed.getMinimum(0), 0d); assertEquals(180d, transformed.getMaximum(0), 0d); }
public void testTransformPolarStereographicWgs84FalseOrigin() throws Exception { // this one has false origins at 6000000/6000000 CoordinateReferenceSystem crs = CRS.decode("EPSG:3032", true); Envelope2D envelope = new Envelope2D(crs); envelope.add(5900000, 5900000); envelope.add(6100000, 6100000); Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); // check we got the whole range of longitudes, since the original bbox contains the pole assertEquals(-180d, transformed.getMinimum(0), 0d); assertEquals(180d, transformed.getMaximum(0), 0d); }
public void testTransformPolarStereographicWgs84() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true); Envelope2D envelope = new Envelope2D(crs); // random bbox that does include the pole envelope.add(-4223632.8125, -559082.03125); envelope.add(5053710.9375, 3347167.96875); Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); // check we got the whole range of longitudes, since the original bbox contains the pole assertEquals(-180d, transformed.getMinimum(0), 0d); assertEquals(180d, transformed.getMaximum(0), 0d); // another bbox envelope = new Envelope2D(crs); // random bbox that does not include the pole, but it's really just slightly off it envelope.add(-10718812.640513, -10006238.053703); envelope.add(12228504.561708, -344209.75803081); transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); assertEquals(-90, transformed.getMinimum(1), 0.1d); }
public void testTransformWgs84PolarStereographic() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true); Envelope2D envelope = new Envelope2D(DefaultGeographicCRS.WGS84); envelope.add(-180, -90); envelope.add(180, 0); Envelope transformed = CRS.transform(envelope, crs); // the result is a square assertEquals(transformed.getMaximum(0), transformed.getMaximum(1), 1d); assertEquals(transformed.getMinimum(0), transformed.getMinimum(1), 1d); assertEquals(Math.abs(transformed.getMinimum(0)), transformed.getMaximum(0), 1d); assertEquals(transformed.getMaximum(0), 1.236739621845986E7, 1d); }
/** Tests the transformations of an envelope. */ @Test public void testEnvelopeTransformation() throws FactoryException, TransformException { final CoordinateReferenceSystem mapCRS = CRS.parseWKT(WKT.UTM_10N); final CoordinateReferenceSystem WGS84 = DefaultGeographicCRS.WGS84; final MathTransform crsTransform = CRS.findMathTransform(WGS84, mapCRS, true); assertFalse(crsTransform.isIdentity()); final GeneralEnvelope firstEnvelope, transformedEnvelope, oldEnvelope; firstEnvelope = new GeneralEnvelope(new double[] {-124, 42}, new double[] {-122, 43}); firstEnvelope.setCoordinateReferenceSystem(WGS84); transformedEnvelope = CRS.transform(crsTransform, firstEnvelope); transformedEnvelope.setCoordinateReferenceSystem(mapCRS); oldEnvelope = CRS.transform(crsTransform.inverse(), transformedEnvelope); oldEnvelope.setCoordinateReferenceSystem(WGS84); assertTrue(oldEnvelope.contains(firstEnvelope, true)); assertTrue(oldEnvelope.equals(firstEnvelope, 0.02, true)); }