GeoTiffReader extends AbstractGridCoverage2DReader implements
		GridCoverageReader { @Override public GridCoverage2D read(GeneralParameterValue[] params) throws IOException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Reading image from " + sourceURL.toString() + "\n" + "Highest res " + highestRes[0] + " " + highestRes[1]); } final Collection<GridCoverage2D> response = rasterManager.read(params); if (response.isEmpty()) { if (LOGGER.isLoggable(Level.FINE)){ LOGGER.fine("The response is empty. ==> returning a null GridCoverage"); } return null; } else { return response.iterator().next(); } } GeoTiffReader(Object input);  GeoTiffReader(Object input, Hints uHints); @Override int getGridCoverageCount(); @Override void dispose(); Format getFormat(); @Override GridCoverage2D read(GeneralParameterValue[] params);  }
@Test public void testReader() throws IllegalArgumentException, IOException, NoSuchAuthorityCodeException { final File file = TestData.file(this, "."); final File files[] = file.listFiles(); final int numFiles = files.length; final AbstractGridFormat format = new GeoTiffFormat(); for (int i = 0; i < numFiles; i++) { StringBuilder buffer = new StringBuilder(); final String path = files[i].getAbsolutePath().toLowerCase(); if (!path.endsWith("tif") && !path.endsWith("tiff")||path.contains("no_crs")) continue; if (path.contains("ovr.tif")) continue; buffer.append(files[i].getAbsolutePath()).append("\n"); Object o; if (i % 2 == 0) o = files[i]; else o = files[i].toURI().toURL(); if (format.accepts(o)) { buffer.append("ACCEPTED").append("\n"); GeoTiffReader reader = new GeoTiffReader(o, new Hints( Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE)); if (reader != null) { GridCoverage2D coverage = (GridCoverage2D) reader.read(null); if (TestData.isInteractiveTest()) { buffer.append("CRS: ") .append(coverage.getCoordinateReferenceSystem2D().toWKT()) .append("\n"); buffer.append("GG: ").append(coverage.getGridGeometry().toString()) .append("\n"); } if (TestData.isInteractiveTest()) coverage.show(); else PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles(); } } else buffer.append("NOT ACCEPTED").append("\n"); if (TestData.isInteractiveTest()) LOGGER.info(buffer.toString()); } }
@Test public void testExternalOverviews() throws Exception { final File file = TestData.file(GeoTiffReaderTest.class, "ovr.tif"); assertNotNull(file); assertEquals(true, file.exists()); GeoTiffReaderTester reader = new GeoTiffReaderTester(file); final int nOvrs = reader.getNumOverviews(); LOGGER.info("Number of external levels: " + nOvrs); assertEquals(4, nOvrs); double[][] overviewResolutions = reader.getOverviewResolutions(); assertEquals(overviewResolutions.length, 4); final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope envelope = reader.getOriginalEnvelope(); final Dimension dim = new Dimension(); dim.setSize(reader.getOriginalGridRange().getSpan(0) / 2.0, reader.getOriginalGridRange() .getSpan(1) / 2.0); Rectangle rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange()); rasterArea.setSize(dim); GridEnvelope2D range = new GridEnvelope2D(rasterArea); gg.setValue(new GridGeometry2D(range, envelope)); GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { gg }); RenderedImage image = coverage.getRenderedImage(); assertEquals(image.getWidth(), 180); assertEquals(image.getHeight(), 90); dim.setSize(reader.getOriginalGridRange().getSpan(0) / 4.0, reader.getOriginalGridRange() .getSpan(1) / 4.0); rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange()); rasterArea.setSize(dim); range = new GridEnvelope2D(rasterArea); gg.setValue(new GridGeometry2D(range, envelope)); coverage = reader.read(new GeneralParameterValue[] { gg }); image = coverage.getRenderedImage(); assertEquals(image.getWidth(), 90); assertEquals(image.getHeight(), 45); final double delta = 0.00001; assertEquals(overviewResolutions[0][0], 2.0, delta); assertEquals(overviewResolutions[0][1], 2.0, delta); assertEquals(overviewResolutions[1][0], 4.0, delta); assertEquals(overviewResolutions[1][1], 4.0, delta); assertEquals(overviewResolutions[2][0], 8, delta); assertEquals(overviewResolutions[2][1], 7.826086956, delta); assertEquals(overviewResolutions[3][0], 15.6521739, delta); assertEquals(overviewResolutions[3][1], 15, delta); }
@Test public void testReader() throws IllegalArgumentException, IOException, NoSuchAuthorityCodeException { final File file = TestData.file(this, "."); final File files[] = file.listFiles(); final int numFiles = files.length; final AbstractGridFormat format = new GeoTiffFormat(); for (int i = 0; i < numFiles; i++) { StringBuffer buffer = new StringBuffer(); final String path = files[i].getAbsolutePath().toLowerCase(); if (!path.endsWith("tif") && !path.endsWith("tiff")) continue; if (path.contains("ovr.tif")) continue; buffer.append(files[i].getAbsolutePath()).append("\n"); Object o; if (i % 2 == 0) o = files[i]; else o = files[i].toURI().toURL(); if (format.accepts(o)) { buffer.append("ACCEPTED").append("\n"); GeoTiffReader reader = new GeoTiffReader(o, new Hints( Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE)); if (reader != null) { GridCoverage2D coverage = (GridCoverage2D) reader.read(null); if (TestData.isInteractiveTest()) { buffer.append("CRS: ") .append(coverage.getCoordinateReferenceSystem2D().toWKT()) .append("\n"); buffer.append("GG: ").append(coverage.getGridGeometry().toString()) .append("\n"); } if (TestData.isInteractiveTest()) coverage.show(); else coverage.getRenderedImage().getData(); } } else buffer.append("NOT ACCEPTED").append("\n"); if (TestData.isInteractiveTest()) LOGGER.info(buffer.toString()); } }
@Test @Ignore public void testExternalOverviews() throws Exception { final File file = TestData.file(GeoTiffReaderTest.class, "ovr.tif"); assertNotNull(file); assertEquals(true, file.exists()); GeoTiffReaderTester reader = new GeoTiffReaderTester(file); final int nOvrs = reader.getNumOverviews(); LOGGER.info("Number of external overviews: " + nOvrs); assertEquals(4, nOvrs); double[][] overviewResolutions = reader.getOverviewResolutions(); assertEquals(overviewResolutions.length, 4); final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D .createValue(); final GeneralEnvelope envelope = reader.getOriginalEnvelope(); final Dimension dim = new Dimension(); dim.setSize(reader.getOriginalGridRange().getSpan(0) / 4.0, reader.getOriginalGridRange() .getSpan(1) / 4.0); final Rectangle rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange()); rasterArea.setSize(dim); final GridEnvelope2D range = new GridEnvelope2D(rasterArea); gg.setValue(new GridGeometry2D(range, envelope)); GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { gg }); RenderedImage image = coverage.getRenderedImage(); assertEquals(image.getWidth(), 32); assertEquals(image.getHeight(), 32); final double delta = 0.00001; assertEquals(overviewResolutions[0][0], 10, delta); assertEquals(overviewResolutions[0][1], 10, delta); assertEquals(overviewResolutions[1][0], 20, delta); assertEquals(overviewResolutions[1][1], 20, delta); assertEquals(overviewResolutions[2][0], 40, delta); assertEquals(overviewResolutions[2][1], 40, delta); assertEquals(overviewResolutions[3][0], 80, delta); assertEquals(overviewResolutions[3][1], 80, delta); }