/** Returns the original source file, is present in the metadata, and if the coverage */ private File getSourceFile(GridCoverage2D coverage) { final Object fileSource = coverage.getProperty(AbstractGridCoverage2DReader.FILE_SOURCE_PROPERTY); if (fileSource != null && fileSource instanceof String) { File file = new File((String) fileSource); if (file.exists()) { GeoTiffReader reader = null; try { reader = new GeoTiffReader(file); GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(); Envelope envelope = coverage.getEnvelope(); if (originalEnvelope.equals(envelope, 1e-9, false)) { GridCoverage2D test = reader.read(null); ImageUtilities.disposeImage(test.getRenderedImage()); return file; } } catch (Exception e) { // ok, not a geotiff! } finally { if (reader != null) { reader.dispose(); } } } } return null; }
if (!envelope.equals(this.envelope, DELTA, true)) {
/** * Sets this envelope to the same coordinate values than the specified envelope. * * @param envelope The new envelope to copy coordinates from. * @throws MismatchedDimensionException if the specified envelope doesn't have the expected * number of dimensions. * @since 2.2 */ public void setEnvelope(final GeneralEnvelope envelope) throws MismatchedDimensionException { ensureNonNull("envelope", envelope); AbstractDirectPosition.ensureDimensionMatch( "envelope", envelope.getDimension(), getDimension()); System.arraycopy(envelope.ordinates, 0, ordinates, 0, ordinates.length); if (envelope.crs != null) { crs = envelope.crs; assert crs.getCoordinateSystem().getDimension() == getDimension() : crs; assert !envelope.getClass().equals(getClass()) || equals(envelope) : envelope; } }
envelope.getCoordinateReferenceSystem()); if (LOGGER.isLoggable(Level.FINE) && !tempEnvelope.equals(envelope, scale * 1E-3, true)) { LOGGER.log( Level.FINE,
assertNotSame(e1, e2); assertEquals(e1, e2); assertTrue(e1.equals(e2, 1E-4, true)); assertTrue(e1.equals(e2, 1E-4, false)); assertEquals(e1.hashCode(), e2.hashCode()); assertTrue(e1.contains(e2, true)); assertFalse(e1.contains(e2, false)); assertFalse(e1.equals(e2)); assertTrue(e1.equals(e2, 1E-4, true)); assertTrue(e1.equals(e2, 1E-4, false)); assertFalse(e1.hashCode() == e2.hashCode()); assertTrue(e1.contains(e2, true)); assertFalse(e1.contains(e2, false)); assertFalse(e1.equals(e2)); assertFalse(e1.equals(e2, 1E-4, true)); assertFalse(e1.equals(e2, 1E-4, false)); assertFalse(e1.hashCode() == e2.hashCode());
protected static void assertEnvelopeEquals( GeneralEnvelope expected, double scaleExpected, GeneralEnvelope actual, double scaleActual) { final double tolerance; if (scaleExpected <= scaleActual) { tolerance = scaleExpected * 1E-1; } else if (!Double.isNaN(scaleActual)) { tolerance = scaleActual * 1E-1; } else { tolerance = EPS; } assertTrue(expected.equals(actual, tolerance, false)); }
/** 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)); }
|| !intersectionEnvelope.equals(sourceEnvelope, tolerance / 2.0, false)) { cropEnvelope = intersectionEnvelope.clone(); return buildResult(
@Test public void testCoverageTrimmingBordersOverlapVertical() throws Exception { final File xml = new File( "./src/test/resources/trimming/requestGetCoverageTrimmingBordersOverlapVertical.xml"); testCoverageResult( xml, targetCoverage -> { final GeneralEnvelope expectedEnvelope = new GeneralEnvelope(new double[] {13, 37}, new double[] {14, 39}); expectedEnvelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4326", true)); double pixelSize = 0.057934032977228; // check the whole extent has been returned assertTrue( expectedEnvelope.equals( targetCoverage.getEnvelope(), pixelSize, false)); }); }
@Test public void testCoverageTrimmingBordersOverlap() throws Exception { final File xml = new File( "./src/test/resources/trimming/requestGetCoverageTrimmingBordersOverlap.xml"); testCoverageResult( xml, targetCoverage -> { final GeneralEnvelope expectedEnvelope = new GeneralEnvelope(new double[] {7, 40}, new double[] {11, 43}); expectedEnvelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4326", true)); double pixelSize = 0.057934032977228; // check the whole extent has been returned assertTrue( expectedEnvelope.equals( targetCoverage.getEnvelope(), pixelSize, false)); }); }
@Test public void testCoverageTrimmingBordersOverlapOutside() throws Exception { final File xml = new File( "./src/test/resources/trimming/requestGetCoverageTrimmingBordersOverlapOutside.xml"); testCoverageResult( xml, targetCoverage -> { // the expected envelope is the intersection between the requested and native // one final GeneralEnvelope expectedEnvelope = new GeneralEnvelope(new double[] {6.344, 40}, new double[] {11, 46.59}); expectedEnvelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4326", true)); double pixelSize = 0.057934032977228; // check the whole extent has been returned assertTrue( expectedEnvelope.equals( targetCoverage.getEnvelope(), pixelSize, false)); }); }
final GeneralEnvelope tempEnvelope = CRS.transform(tr,toEnvelope(gridRange)); tempEnvelope.setCoordinateReferenceSystem(envelope.getCoordinateReferenceSystem()); if(LOGGER.isLoggable(Level.FINE) && !tempEnvelope.equals(envelope,scale*1E-3,true)) { LOGGER.log(Level.FINE, "Unable to preserve the envelope for this GridGeometry, expected " + envelope + ", actual " + tempEnvelope);
throw new IllegalArgumentException( "The provided envelope is outside the source CRS definition area"); if (!intersectedEnvelope.equals(envelope)) { final double scale0 = intersectedEnvelope.getLength(0) / envelope.getLength(0);
throw new CannotCropException(Errors .format(ErrorKeys.CANT_CROP)); if (cropEnvelope.equals(sourceEnvelope, scaleFactor / 2.0, false)) return sourceCoverage; cropEnvelope.getCoordinateReferenceSystem(), XAffineTransform.transform(sourceGridToWorldTransform, finalGridRange,null))); assert testEnvelope.equals(cropEnvelope, XAffineTransform.getScale(sourceGridToWorldTransform)/2,false );
if (!intersectionEnvelope.equals((GeneralEnvelope) sourceEnvelope)) {
.equals(sourceEnvelope, tolerance / 2.0, false)) { envelopeParameter.setValue(intersectionEnvelope.clone()); return CroppedCoverage2D
if (cropRoi != null || !intersectionEnvelope.equals(sourceEnvelope, tolerance / 2.0, false)) { cropEnvelope = intersectionEnvelope.clone(); return buildResult(