/** * Tests the "Resample" operation with a stereographic coordinate system. * * @throws FactoryException * @throws NoSuchAuthorityCodeException */ @Test public void testReproject() throws NoSuchAuthorityCodeException, FactoryException { // do it again, make sure the image does not turn black since GridCoverage2D coverage_ = project(ushortCoverage, CRS.parseWKT(GOOGLE_MERCATOR_WKT), null, "nearest", null, true); // reproject the ushort and check that things did not go bad, that is it turned black coverage_ = (GridCoverage2D) Operations.DEFAULT.extrema(coverage_); Object minimums = coverage_.getProperty(Extrema.GT_SYNTHETIC_PROPERTY_MINIMUM); Assert.assertTrue(minimums instanceof double[]); final double[] mins = (double[]) minimums; Object maximums = coverage_.getProperty(Extrema.GT_SYNTHETIC_PROPERTY_MAXIMUM); Assert.assertTrue(maximums instanceof double[]); final double[] max = (double[]) maximums; boolean fail = true; for (int i = 0; i < mins.length; i++) if (mins[i] != max[i] && max[i] > 0) fail = false; Assert.assertFalse("Reprojection failed", fail); // exception in case the target crs does not comply with the target gg crs try { // we supplied both crs and target gg in different crs, we get an exception backS assertEquals( "Warp", showProjected( coverage, CRS.parseWKT(GOOGLE_MERCATOR_WKT), coverage.getGridGeometry(), null, true)); Assert.assertTrue( "We should not be allowed to set different crs for target crs and target gg", false); } catch (Exception e) { // ok! } }
@Test public void testMissingNullValuesInCoverageDimensions() throws IOException { CoverageInfo ci = getCatalog().getCoverageByName(getLayerId(MockData.TASMANIA_DEM)); List<CoverageDimensionInfo> dimensions = ci.getDimensions(); // legacy layers have no null value list dimensions.get(0).getNullValues().clear(); getCatalog().save(ci); // and now go back and ask for the reader ci = getCatalog().getCoverageByName(getLayerId(MockData.TASMANIA_DEM)); GridCoverageReader reader = ci.getGridCoverageReader(null, null); GridCoverage2D gc = null; try { // check that we maintain the native info if we don't have any gc = (GridCoverage2D) reader.read(null); assertEquals(-9999d, (Double) gc.getProperty("GC_NODATA"), 0d); } finally { if (gc != null) { RenderedImage ri = gc.getRenderedImage(); if (gc instanceof GridCoverage2D) { ((GridCoverage2D) gc).dispose(true); } if (ri instanceof PlanarImage) { ImageUtilities.disposePlanarImageChain((PlanarImage) ri); } } } }
/** * Tests the "Resample" operation with a stereographic coordinate system on a paletted image * * @throws FactoryException * @throws NoSuchAuthorityCodeException */ @Test public void testReprojectPalette() throws NoSuchAuthorityCodeException, FactoryException { // do it again, make sure the image does not turn black since GridCoverage2D input = ushortCoverage; // Create a Palette image from the input coverage RenderedImage src = input.getRenderedImage(); ImageWorker iw = new ImageWorker(src).rescaleToBytes().forceIndexColorModel(false); src = iw.getRenderedOperation(); // Setting Force ReplaceIndexColorModel and CoverageProcessingView as SAME Hints hints = GeoTools.getDefaultHints().clone(); hints.put(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, true); hints.put(Hints.COVERAGE_PROCESSING_VIEW, ViewType.SAME); // Create a new GridCoverage GridCoverageFactory factory = new GridCoverageFactory(hints); GridCoverage2D palette = factory.create("test", src, input.getEnvelope()); CoordinateReferenceSystem targetCRS = CRS.parseWKT(GOOGLE_MERCATOR_WKT); GridCoverage2D coverage_ = project(palette, targetCRS, null, "bilinear", hints, true); // reproject the ushort and check that things did not go bad, that is it turned black coverage_ = (GridCoverage2D) Operations.DEFAULT.extrema(coverage_); Object minimums = coverage_.getProperty(Extrema.GT_SYNTHETIC_PROPERTY_MINIMUM); Assert.assertTrue(minimums instanceof double[]); final double[] mins = (double[]) minimums; Object maximums = coverage_.getProperty(Extrema.GT_SYNTHETIC_PROPERTY_MAXIMUM); Assert.assertTrue(maximums instanceof double[]); final double[] max = (double[]) maximums; boolean fail = true; for (int i = 0; i < mins.length; i++) if (mins[i] != max[i] && max[i] > 0) fail = false; Assert.assertFalse("Reprojection failed", fail); // Ensure the CRS is correct CoordinateReferenceSystem targetCoverageCRS = coverage_.getCoordinateReferenceSystem(); Assert.assertTrue(CRS.equalsIgnoreMetadata(targetCRS, targetCoverageCRS)); }