ImagePyramidReader extends AbstractGridCoverage2DReader implements GridCoverageReader { public GridCoverage2D read(GeneralParameterValue[] params) throws IOException { GeneralEnvelope requestedEnvelope = null; Rectangle dim = null; OverviewPolicy overviewPolicy=null; if (params != null) { if (params != null) { for (int i = 0; i < params.length; i++) { @SuppressWarnings("rawtypes") final ParameterValue param = (ParameterValue) params[i]; if (param == null){ continue; } final String name = param.getDescriptor().getName().getCode(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString())) { final GridGeometry2D gg = (GridGeometry2D) param.getValue(); requestedEnvelope = new GeneralEnvelope((Envelope)gg.getEnvelope2D()); dim = gg.getGridRange2D().getBounds(); continue; } if (name.equals(AbstractGridFormat.OVERVIEW_POLICY.getName().toString())) { overviewPolicy = (OverviewPolicy) param.getValue(); continue; } } } } return loadTiles(requestedEnvelope, dim, params, overviewPolicy); } ImagePyramidReader(Object source, Hints uHints);  ImagePyramidReader(Object source); Format getFormat(); GridCoverage2D read(GeneralParameterValue[] params); @Override synchronized void dispose(); @Override int getGridCoverageCount(); @Override String getMetadataValue(String coverageName, String name); String getMetadataValue(final String name); String[] getMetadataNames(); ImageMosaicReader getImageMosaicReaderForLevel(Integer imageChoice);  }
@Test public void testDefaultParameterValue() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final URL testFile = TestData.getResource(this, "goodpyramid/"+TEST_FILE); assertNotNull(testFile); final AbstractGridFormat format = new ImagePyramidFormat(); assertTrue(format.accepts(testFile)); final ImagePyramidReader reader = (ImagePyramidReader) format .getReader(testFile); assertNotNull(reader); final GridCoverage2D coverage = (GridCoverage2D) reader.read(null); assertEquals("pyramid", coverage.getName().toString()); assertNotNull("Null value returned instead of a coverage", coverage); assertTrue("coverage dimensions different from what we expected", coverage.getGridGeometry().getGridRange().getSpan(0) == 250 && coverage.getGridGeometry().getGridRange().getSpan( 1) == 250); if (TestData.isInteractiveTest()) coverage.show("testDefaultParameterValue"); else PlanarImage.wrapRenderedImage(((GridCoverage2D) coverage).getRenderedImage()).getTiles(); }
@Test public void testDefaultParameterValueFile() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final File testFile = TestData.file(this, "goodpyramid/"+TEST_FILE); assertNotNull(testFile); final AbstractGridFormat format = new ImagePyramidFormat(); assertTrue(format.accepts(testFile)); final ImagePyramidReader reader = (ImagePyramidReader) format .getReader(testFile); assertNotNull(reader); final GridCoverage2D coverage = (GridCoverage2D) reader.read(null); assertNotNull("Null value returned instead of a coverage", coverage); assertTrue("coverage dimensions different from what we expected", coverage.getGridGeometry().getGridRange().getSpan(0) == 250 && coverage.getGridGeometry().getGridRange().getSpan( 1) == 250); if (TestData.isInteractiveTest()) coverage.show("testDefaultParameterValueFile"); else PlanarImage.wrapRenderedImage(((GridCoverage2D) coverage).getRenderedImage()).getTiles(); }
@Test public void testDefaultParameterValueString() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final String testFile = TestData.file(this, "goodpyramid/"+TEST_FILE) .getCanonicalPath(); assertNotNull(testFile); final AbstractGridFormat format = new ImagePyramidFormat(); assertTrue(format.accepts(testFile)); final ImagePyramidReader reader = (ImagePyramidReader) format .getReader(testFile); assertNotNull(reader); final GridCoverage2D coverage = (GridCoverage2D) reader.read(null); assertNotNull("Null value returned instead of a coverage", coverage); assertTrue("coverage dimensions different from what we expected", coverage.getGridGeometry().getGridRange().getSpan(0) == 250 && coverage.getGridGeometry().getGridRange().getSpan( 1) == 250); if (TestData.isInteractiveTest()) coverage.show("testDefaultParameterValueString"); else PlanarImage.wrapRenderedImage(((GridCoverage2D) coverage).getRenderedImage()).getTiles(); }
@Test public void testComplete() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final URL testFile = TestData.getResource(this, "goodpyramid/"+TEST_FILE); assertNotNull(testFile); final ImagePyramidReader reader = new ImagePyramidReader( testFile, new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE)); assertNotNull(reader); final ParameterValue<Color> transp = ImageMosaicFormat.INPUT_TRANSPARENT_COLOR.createValue(); transp.setValue(Color.black); GridCoverage2D coverage = (GridCoverage2D) reader.read(new GeneralParameterValue[] { transp }); assertNotNull(coverage); assertTrue("coverage dimensions different from what we expected",coverage.getGridGeometry().getGridRange().getSpan(0) == 250&& coverage.getGridGeometry().getGridRange().getSpan(1) == 250); if (TestData.isInteractiveTest()) coverage.show("testComplete"); else PlanarImage.wrapRenderedImage(((GridCoverage2D) coverage).getRenderedImage()).getTiles(); }
@Test public void testRequestOutsideBounds() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final URL testFile = TestData.getResource(this, "goodpyramid/"+TEST_FILE); assertNotNull(testFile); final ImagePyramidReader reader = new ImagePyramidReader(testFile, new Hints( Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE)); assertNotNull(reader); GeneralEnvelope ge = reader.getOriginalEnvelope(); ReferencedEnvelope requestedEnvelope = new ReferencedEnvelope(ge.getMinimum(0) - 5, ge.getMinimum(0), ge.getMinimum(1), ge.getMaximum(1), ge.getCoordinateReferenceSystem()); final Parameter<GridGeometry2D> readGG = new Parameter<GridGeometry2D>(AbstractGridFormat.READ_GRIDGEOMETRY2D); readGG.setValue(new GridGeometry2D(new GridEnvelope2D(0, 0, 400, 400), requestedEnvelope)); assertNull(reader.read(new GeneralParameterValue[] {readGG})); }
@Test public void testCropHighestLevel() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final URL testFile = TestData.getResource(this, "goodpyramid/"+TEST_FILE); final AbstractGridFormat format = new ImagePyramidFormat(); final ImagePyramidReader reader = (ImagePyramidReader) format.getReader(testFile); assertNotNull(reader); final ParameterValue<GridGeometry2D> gg = ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope(); final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] { oldEnvelop.getLowerCorner().getOrdinate(0), oldEnvelop.getLowerCorner().getOrdinate(1) }, new double[] { oldEnvelop.getLowerCorner().getOrdinate(0) + oldEnvelop.getSpan(0) / 2, oldEnvelop.getLowerCorner().getOrdinate(1) + oldEnvelop.getSpan(1) / 2 }); cropEnvelope.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0, 125, 125)), cropEnvelope)); GridCoverage2D coverage = ((GridCoverage2D) reader .read(new GeneralParameterValue[] { gg })); assertNotNull("Null value returned instead of a coverage", coverage); assertTrue("coverage dimensions different from what we expected", coverage.getGridGeometry().getGridRange().getSpan(0) == 127 && coverage.getGridGeometry().getGridRange().getSpan( 1) == 127); if (TestData.isInteractiveTest()) coverage.show("testCropHighestLevel"); else PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles(); }
@Test public void testCropLevel1() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final URL testFile = TestData.getResource(this, "goodpyramid/"+TEST_FILE); final AbstractGridFormat format = new ImagePyramidFormat(); final ImagePyramidReader reader = (ImagePyramidReader) format.getReader(testFile); assertNotNull(reader); final ParameterValue<GridGeometry2D> gg = ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope(); final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] { oldEnvelop.getLowerCorner().getOrdinate(0), oldEnvelop.getLowerCorner().getOrdinate(1) }, new double[] { oldEnvelop.getLowerCorner().getOrdinate(0) + oldEnvelop.getSpan(0) / 2, oldEnvelop.getLowerCorner().getOrdinate(1) + oldEnvelop.getSpan(1) / 2 }); cropEnvelope.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0, 125, 125)), cropEnvelope)); GridCoverage2D coverage = ((GridCoverage2D) reader .read(new GeneralParameterValue[] { gg })); assertNotNull("Null value returned instead of a coverage", coverage); if (TestData.isInteractiveTest()) coverage.show("testCropLevel1"); else PlanarImage.wrapRenderedImage(((GridCoverage2D) coverage).getRenderedImage()).getTiles(); }
@Test public void testCropLevel2() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final URL testFile = TestData.getResource(this, "goodpyramid/"+TEST_FILE); final AbstractGridFormat format = new ImagePyramidFormat(); final ImagePyramidReader reader = (ImagePyramidReader) format.getReader(testFile); assertNotNull(reader); final ParameterValue<GridGeometry2D> gg = ImageMosaicFormat.READ_GRIDGEOMETRY2D .createValue(); final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope(); final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] { oldEnvelop.getLowerCorner().getOrdinate(0), oldEnvelop.getLowerCorner().getOrdinate(1) }, new double[] { oldEnvelop.getLowerCorner().getOrdinate(0) + oldEnvelop.getSpan(0) / 2, oldEnvelop.getLowerCorner().getOrdinate(1) + oldEnvelop.getSpan(1) / 2 }); cropEnvelope.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0, 62, 62)), cropEnvelope)); GridCoverage2D coverage = ((GridCoverage2D) reader .read(new GeneralParameterValue[] { gg })); assertNotNull("Null value returned instead of a coverage", coverage); if (TestData.isInteractiveTest()) coverage.show("testCropLevel1"); else PlanarImage.wrapRenderedImage(((GridCoverage2D) coverage).getRenderedImage()).getTiles(); }
@Test public void testCropLevel3() throws IOException, MismatchedDimensionException, NoSuchAuthorityCodeException { final URL testFile = TestData.getResource(this, "goodpyramid/"+TEST_FILE); final AbstractGridFormat format = new ImagePyramidFormat(); final ImagePyramidReader reader = (ImagePyramidReader) format.getReader(testFile); assertNotNull(reader); final ParameterValue<GridGeometry2D> gg = ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope oldEnvelop = reader.getOriginalEnvelope(); final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] { oldEnvelop.getLowerCorner().getOrdinate(0), oldEnvelop.getLowerCorner().getOrdinate(1) }, new double[] { oldEnvelop.getLowerCorner().getOrdinate(0) + oldEnvelop.getSpan(0) / 2, oldEnvelop.getLowerCorner().getOrdinate(1) + oldEnvelop.getSpan(1) / 2 }); cropEnvelope.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0, 25, 25)), cropEnvelope)); GridCoverage2D coverage = ((GridCoverage2D) reader .read(new GeneralParameterValue[] { gg })); assertNotNull("Null value returned instead of a coverage", coverage); if (TestData.isInteractiveTest()) coverage.show("testCropLevel1"); else PlanarImage.wrapRenderedImage(((GridCoverage2D) coverage).getRenderedImage()).getTiles(); }