@Test public void testUoMDefault() throws Exception { final File file = TestData.file(GeoTiffReaderTest.class, "no_uom.tif"); assertNotNull(file); final AbstractGridFormat format = new GeoTiffFormat(); GridCoverage2D coverage = format.getReader(file).read(null); CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem(); String crsDef = crs.toWKT(); assertTrue(crsDef.contains("UNIT[\"m\", 1.0]")); }
public GridCoverage2D read(GeneralParameterValue[] params) throws IOException { GeneralEnvelope requestedEnvelope = null; Rectangle dim = null; Color inputTransparentColor = null; OverviewPolicy overviewPolicy = null; int[] suggestedTileSize = null; boolean rescalePixels = AbstractGridFormat.RESCALE_PIXELS.getDefaultValue(); if (params != null) { for (int i = 0; i < params.length; i++) { final ParameterValue param = (ParameterValue) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName())) { final GridGeometry2D gg = (GridGeometry2D) param.getValue(); requestedEnvelope = new GeneralEnvelope((Envelope) gg.getEnvelope2D()); dim = gg.getGridRange2D().getBounds(); continue; } if (name.equals(AbstractGridFormat.OVERVIEW_POLICY.getName())) { overviewPolicy = (OverviewPolicy) param.getValue(); continue; } if (name.equals(AbstractGridFormat.INPUT_TRANSPARENT_COLOR.getName())) { inputTransparentColor = (Color) param.getValue(); continue; } if (name.equals(AbstractGridFormat.SUGGESTED_TILE_SIZE.getName())) { String suggestedTileSize_ = (String) param.getValue(); if (suggestedTileSize_ != null && suggestedTileSize_.length() > 0) { suggestedTileSize_ = suggestedTileSize_.trim(); int commaPosition = suggestedTileSize_.indexOf(","); if (commaPosition < 0) { int tileDim = Integer.parseInt(suggestedTileSize_); suggestedTileSize = new int[] {tileDim, tileDim}; } else { int tileW = Integer.parseInt( suggestedTileSize_.substring(0, commaPosition)); int tileH = Integer.parseInt( suggestedTileSize_.substring(commaPosition + 1)); suggestedTileSize = new int[] {tileW, tileH}; } } continue; } if (name.equals(AbstractGridFormat.RESCALE_PIXELS.getName())) { rescalePixels = Boolean.TRUE.equals(param.getValue()); } } } Integer imageChoice = Integer.valueOf(0); final ImageReadParam readP = new ImageReadParam(); try { imageChoice = setReadParams(overviewPolicy, readP, requestedEnvelope, dim); } catch (TransformException e) { throw new DataSourceException(e); } Hints newHints = null; if (suggestedTileSize != null) { newHints = hints.clone(); final ImageLayout layout = new ImageLayout(); layout.setTileGridXOffset(0); layout.setTileGridYOffset(0); layout.setTileHeight(suggestedTileSize[1]); layout.setTileWidth(suggestedTileSize[0]); newHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); } final ParameterBlock pbjRead = new ParameterBlock(); if (maskOvrProvider != null) { if (maskOvrProvider.isExternalOverview(imageChoice)) { pbjRead.add( maskOvrProvider .getExternalOverviewInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getOvrURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } else { pbjRead.add( maskOvrProvider .getInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getFileURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } pbjRead.add(maskOvrProvider.getOverviewIndex(imageChoice)); } else { if (extOvrImgChoice >= 0 && imageChoice >= extOvrImgChoice) { pbjRead.add( ovrInStreamSPI.createInputStreamInstance( ovrSource, ImageIO.getUseCache(), ImageIO.getCacheDirectory())); pbjRead.add(imageChoice - extOvrImgChoice); } else { if (inStream instanceof ImageInputStream && !closeMe) { pbjRead.add(inStream); } else { pbjRead.add( inStreamSPI != null ? inStreamSPI.createInputStreamInstance( source, ImageIO.getUseCache(), ImageIO.getCacheDirectory()) : ImageIO.createImageInputStream(source)); } int overviewImageIndex = dtLayout.getInternalOverviewImageIndex(imageChoice); int index = overviewImageIndex >= 0 ? overviewImageIndex : 0; pbjRead.add(index); } } pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(null); pbjRead.add(null); pbjRead.add(readP); pbjRead.add(READER_SPI.createReaderInstance()); PlanarImage coverageRaster = JAI.create("ImageRead", pbjRead, newHints != null ? newHints : null); if (rescalePixels) { if (!Double.isNaN(noData)) { PlanarImage t = PlanarImage.wrapRenderedImage(coverageRaster); t.setProperty(NoDataContainer.GC_NODATA, new NoDataContainer(noData)); coverageRaster = t; } coverageRaster = PlanarImage.wrapRenderedImage( ImageUtilities.applyRescaling( scales, offsets, coverageRaster, newHints)); } if (inputTransparentColor != null) { coverageRaster = new ImageWorker(coverageRaster) .setRenderingHints(newHints) .makeColorTransparent(inputTransparentColor) .getRenderedOperation(); } ROI roi = null; if (hasMaskOvrProvider) { GridEnvelope ogr = getOriginalGridRange(); Rectangle sourceRegion; if (readP.getSourceRegion() != null) { sourceRegion = readP.getSourceRegion(); } else { sourceRegion = new Rectangle(ogr.getSpan(0), ogr.getSpan(1)); } MaskInfo info = maskOvrProvider.getMaskInfo(imageChoice, sourceRegion, readP); if (info != null) { RenderedOp roiRaster = readROIRaster( info.streamSpi, URLs.fileToUrl(info.file), info.index, newHints, info.readParameters); roi = MaskOverviewProvider.scaleROI(roiRaster, coverageRaster.getBounds()); } } AffineTransform rasterToModel = getRescaledRasterToModel(coverageRaster); try { return createCoverage(coverageRaster, ProjectiveTransform.create(rasterToModel), roi); } catch (Exception e) { ImageUtilities.disposePlanarImageChain(coverageRaster); if (e instanceof DataSourceException) { throw (DataSourceException) e; } throw new DataSourceException(e); } }
GeoTiffReader extends AbstractGridCoverage2DReader implements GridCoverage2DReader { public GridCoverage2D read(GeneralParameterValue[] params) throws IOException { GeneralEnvelope requestedEnvelope = null; Rectangle dim = null; Color inputTransparentColor = null; OverviewPolicy overviewPolicy = null; int[] suggestedTileSize = null; boolean rescalePixels = AbstractGridFormat.RESCALE_PIXELS.getDefaultValue(); if (params != null) { for (int i = 0; i < params.length; i++) { final ParameterValue param = (ParameterValue) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName())) { final GridGeometry2D gg = (GridGeometry2D) param.getValue(); requestedEnvelope = new GeneralEnvelope((Envelope) gg.getEnvelope2D()); dim = gg.getGridRange2D().getBounds(); continue; } if (name.equals(AbstractGridFormat.OVERVIEW_POLICY.getName())) { overviewPolicy = (OverviewPolicy) param.getValue(); continue; } if (name.equals(AbstractGridFormat.INPUT_TRANSPARENT_COLOR.getName())) { inputTransparentColor = (Color) param.getValue(); continue; } if (name.equals(AbstractGridFormat.SUGGESTED_TILE_SIZE.getName())) { String suggestedTileSize_ = (String) param.getValue(); if (suggestedTileSize_ != null && suggestedTileSize_.length() > 0) { suggestedTileSize_ = suggestedTileSize_.trim(); int commaPosition = suggestedTileSize_.indexOf(","); if (commaPosition < 0) { int tileDim = Integer.parseInt(suggestedTileSize_); suggestedTileSize = new int[] {tileDim, tileDim}; } else { int tileW = Integer.parseInt( suggestedTileSize_.substring(0, commaPosition)); int tileH = Integer.parseInt( suggestedTileSize_.substring(commaPosition + 1)); suggestedTileSize = new int[] {tileW, tileH}; } } continue; } if (name.equals(AbstractGridFormat.RESCALE_PIXELS.getName())) { rescalePixels = Boolean.TRUE.equals(param.getValue()); } } } Integer imageChoice = Integer.valueOf(0); final ImageReadParam readP = new ImageReadParam(); try { imageChoice = setReadParams(overviewPolicy, readP, requestedEnvelope, dim); } catch (TransformException e) { throw new DataSourceException(e); } Hints newHints = null; if (suggestedTileSize != null) { newHints = hints.clone(); final ImageLayout layout = new ImageLayout(); layout.setTileGridXOffset(0); layout.setTileGridYOffset(0); layout.setTileHeight(suggestedTileSize[1]); layout.setTileWidth(suggestedTileSize[0]); newHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); } final ParameterBlock pbjRead = new ParameterBlock(); if (maskOvrProvider != null) { if (maskOvrProvider.isExternalOverview(imageChoice)) { pbjRead.add( maskOvrProvider .getExternalOverviewInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getOvrURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } else { pbjRead.add( maskOvrProvider .getInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getFileURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } pbjRead.add(maskOvrProvider.getOverviewIndex(imageChoice)); } else { if (extOvrImgChoice >= 0 && imageChoice >= extOvrImgChoice) { pbjRead.add( ovrInStreamSPI.createInputStreamInstance( ovrSource, ImageIO.getUseCache(), ImageIO.getCacheDirectory())); pbjRead.add(imageChoice - extOvrImgChoice); } else { if (inStream instanceof ImageInputStream && !closeMe) { pbjRead.add(inStream); } else { pbjRead.add( inStreamSPI != null ? inStreamSPI.createInputStreamInstance( source, ImageIO.getUseCache(), ImageIO.getCacheDirectory()) : ImageIO.createImageInputStream(source)); } int overviewImageIndex = dtLayout.getInternalOverviewImageIndex(imageChoice); int index = overviewImageIndex >= 0 ? overviewImageIndex : 0; pbjRead.add(index); } } pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(null); pbjRead.add(null); pbjRead.add(readP); pbjRead.add(READER_SPI.createReaderInstance()); PlanarImage coverageRaster = JAI.create("ImageRead", pbjRead, newHints != null ? newHints : null); if (rescalePixels) { if (!Double.isNaN(noData)) { PlanarImage t = PlanarImage.wrapRenderedImage(coverageRaster); t.setProperty(NoDataContainer.GC_NODATA, new NoDataContainer(noData)); coverageRaster = t; } coverageRaster = PlanarImage.wrapRenderedImage( ImageUtilities.applyRescaling( scales, offsets, coverageRaster, newHints)); } if (inputTransparentColor != null) { coverageRaster = new ImageWorker(coverageRaster) .setRenderingHints(newHints) .makeColorTransparent(inputTransparentColor) .getRenderedOperation(); } ROI roi = null; if (hasMaskOvrProvider) { GridEnvelope ogr = getOriginalGridRange(); Rectangle sourceRegion; if (readP.getSourceRegion() != null) { sourceRegion = readP.getSourceRegion(); } else { sourceRegion = new Rectangle(ogr.getSpan(0), ogr.getSpan(1)); } MaskInfo info = maskOvrProvider.getMaskInfo(imageChoice, sourceRegion, readP); if (info != null) { RenderedOp roiRaster = readROIRaster( info.streamSpi, URLs.fileToUrl(info.file), info.index, newHints, info.readParameters); roi = MaskOverviewProvider.scaleROI(roiRaster, coverageRaster.getBounds()); } } AffineTransform rasterToModel = getRescaledRasterToModel(coverageRaster); try { return createCoverage(coverageRaster, ProjectiveTransform.create(rasterToModel), roi); } catch (Exception e) { ImageUtilities.disposePlanarImageChain(coverageRaster); if (e instanceof DataSourceException) { throw (DataSourceException) e; } throw new DataSourceException(e); } } }
GeoTiffReader extends AbstractGridCoverage2DReader implements GridCoverage2DReader { public GridCoverage2D read(GeneralParameterValue[] params) throws IOException { GeneralEnvelope requestedEnvelope = null; Rectangle dim = null; Color inputTransparentColor = null; OverviewPolicy overviewPolicy = null; int[] suggestedTileSize = null; boolean rescalePixels = AbstractGridFormat.RESCALE_PIXELS.getDefaultValue(); if (params != null) { for (int i = 0; i < params.length; i++) { final ParameterValue param = (ParameterValue) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName())) { final GridGeometry2D gg = (GridGeometry2D) param.getValue(); requestedEnvelope = new GeneralEnvelope((Envelope) gg.getEnvelope2D()); dim = gg.getGridRange2D().getBounds(); continue; } if (name.equals(AbstractGridFormat.OVERVIEW_POLICY.getName())) { overviewPolicy = (OverviewPolicy) param.getValue(); continue; } if (name.equals(AbstractGridFormat.INPUT_TRANSPARENT_COLOR.getName())) { inputTransparentColor = (Color) param.getValue(); continue; } if (name.equals(AbstractGridFormat.SUGGESTED_TILE_SIZE.getName())) { String suggestedTileSize_ = (String) param.getValue(); if (suggestedTileSize_ != null && suggestedTileSize_.length() > 0) { suggestedTileSize_ = suggestedTileSize_.trim(); int commaPosition = suggestedTileSize_.indexOf(","); if (commaPosition < 0) { int tileDim = Integer.parseInt(suggestedTileSize_); suggestedTileSize = new int[] {tileDim, tileDim}; } else { int tileW = Integer.parseInt( suggestedTileSize_.substring(0, commaPosition)); int tileH = Integer.parseInt( suggestedTileSize_.substring(commaPosition + 1)); suggestedTileSize = new int[] {tileW, tileH}; } } continue; } if (name.equals(AbstractGridFormat.RESCALE_PIXELS.getName())) { rescalePixels = Boolean.TRUE.equals(param.getValue()); } } } Integer imageChoice = Integer.valueOf(0); final ImageReadParam readP = new ImageReadParam(); try { imageChoice = setReadParams(overviewPolicy, readP, requestedEnvelope, dim); } catch (TransformException e) { throw new DataSourceException(e); } Hints newHints = null; if (suggestedTileSize != null) { newHints = hints.clone(); final ImageLayout layout = new ImageLayout(); layout.setTileGridXOffset(0); layout.setTileGridYOffset(0); layout.setTileHeight(suggestedTileSize[1]); layout.setTileWidth(suggestedTileSize[0]); newHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); } final ParameterBlock pbjRead = new ParameterBlock(); if (maskOvrProvider != null) { if (maskOvrProvider.isExternalOverview(imageChoice)) { pbjRead.add( maskOvrProvider .getExternalOverviewInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getOvrURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } else { pbjRead.add( maskOvrProvider .getInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getFileURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } pbjRead.add(maskOvrProvider.getOverviewIndex(imageChoice)); } else { if (extOvrImgChoice >= 0 && imageChoice >= extOvrImgChoice) { pbjRead.add( ovrInStreamSPI.createInputStreamInstance( ovrSource, ImageIO.getUseCache(), ImageIO.getCacheDirectory())); pbjRead.add(imageChoice - extOvrImgChoice); } else { if (inStream instanceof ImageInputStream && !closeMe) { pbjRead.add(inStream); } else { pbjRead.add( inStreamSPI != null ? inStreamSPI.createInputStreamInstance( source, ImageIO.getUseCache(), ImageIO.getCacheDirectory()) : ImageIO.createImageInputStream(source)); } int overviewImageIndex = dtLayout.getInternalOverviewImageIndex(imageChoice); int index = overviewImageIndex >= 0 ? overviewImageIndex : 0; pbjRead.add(index); } } pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(null); pbjRead.add(null); pbjRead.add(readP); pbjRead.add(READER_SPI.createReaderInstance()); PlanarImage coverageRaster = JAI.create("ImageRead", pbjRead, newHints != null ? newHints : null); if (rescalePixels) { if (!Double.isNaN(noData)) { PlanarImage t = PlanarImage.wrapRenderedImage(coverageRaster); t.setProperty(NoDataContainer.GC_NODATA, new NoDataContainer(noData)); coverageRaster = t; } coverageRaster = PlanarImage.wrapRenderedImage( ImageUtilities.applyRescaling( scales, offsets, coverageRaster, newHints)); } if (inputTransparentColor != null) { coverageRaster = new ImageWorker(coverageRaster) .setRenderingHints(newHints) .makeColorTransparent(inputTransparentColor) .getRenderedOperation(); } ROI roi = null; if (hasMaskOvrProvider) { GridEnvelope ogr = getOriginalGridRange(); Rectangle sourceRegion; if (readP.getSourceRegion() != null) { sourceRegion = readP.getSourceRegion(); } else { sourceRegion = new Rectangle(ogr.getSpan(0), ogr.getSpan(1)); } MaskInfo info = maskOvrProvider.getMaskInfo(imageChoice, sourceRegion, readP); if (info != null) { RenderedOp roiRaster = readROIRaster( info.streamSpi, URLs.fileToUrl(info.file), info.index, newHints, info.readParameters); roi = MaskOverviewProvider.scaleROI(roiRaster, coverageRaster.getBounds()); } } AffineTransform rasterToModel = getRescaledRasterToModel(coverageRaster); try { return createCoverage(coverageRaster, ProjectiveTransform.create(rasterToModel), roi); } catch (Exception e) { ImageUtilities.disposePlanarImageChain(coverageRaster); if (e instanceof DataSourceException) { throw (DataSourceException) e; } throw new DataSourceException(e); } } GeoTiffReader(Object input);  GeoTiffReader(Object input, Hints uHints); }
GeoTiffReader extends AbstractGridCoverage2DReader implements GridCoverage2DReader { public GridCoverage2D read(GeneralParameterValue[] params) throws IOException { GeneralEnvelope requestedEnvelope = null; Rectangle dim = null; Color inputTransparentColor = null; OverviewPolicy overviewPolicy = null; int[] suggestedTileSize = null; boolean rescalePixels = AbstractGridFormat.RESCALE_PIXELS.getDefaultValue(); if (params != null) { for (int i = 0; i < params.length; i++) { final ParameterValue param = (ParameterValue) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName())) { final GridGeometry2D gg = (GridGeometry2D) param.getValue(); requestedEnvelope = new GeneralEnvelope((Envelope) gg.getEnvelope2D()); dim = gg.getGridRange2D().getBounds(); continue; } if (name.equals(AbstractGridFormat.OVERVIEW_POLICY.getName())) { overviewPolicy = (OverviewPolicy) param.getValue(); continue; } if (name.equals(AbstractGridFormat.INPUT_TRANSPARENT_COLOR.getName())) { inputTransparentColor = (Color) param.getValue(); continue; } if (name.equals(AbstractGridFormat.SUGGESTED_TILE_SIZE.getName())) { String suggestedTileSize_ = (String) param.getValue(); if (suggestedTileSize_ != null && suggestedTileSize_.length() > 0) { suggestedTileSize_ = suggestedTileSize_.trim(); int commaPosition = suggestedTileSize_.indexOf(","); if (commaPosition < 0) { int tileDim = Integer.parseInt(suggestedTileSize_); suggestedTileSize = new int[] {tileDim, tileDim}; } else { int tileW = Integer.parseInt( suggestedTileSize_.substring(0, commaPosition)); int tileH = Integer.parseInt( suggestedTileSize_.substring(commaPosition + 1)); suggestedTileSize = new int[] {tileW, tileH}; } } continue; } if (name.equals(AbstractGridFormat.RESCALE_PIXELS.getName())) { rescalePixels = Boolean.TRUE.equals(param.getValue()); } } } Integer imageChoice = Integer.valueOf(0); final ImageReadParam readP = new ImageReadParam(); try { imageChoice = setReadParams(overviewPolicy, readP, requestedEnvelope, dim); } catch (TransformException e) { throw new DataSourceException(e); } Hints newHints = null; if (suggestedTileSize != null) { newHints = hints.clone(); final ImageLayout layout = new ImageLayout(); layout.setTileGridXOffset(0); layout.setTileGridYOffset(0); layout.setTileHeight(suggestedTileSize[1]); layout.setTileWidth(suggestedTileSize[0]); newHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); } final ParameterBlock pbjRead = new ParameterBlock(); if (maskOvrProvider != null) { if (maskOvrProvider.isExternalOverview(imageChoice)) { pbjRead.add( maskOvrProvider .getExternalOverviewInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getOvrURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } else { pbjRead.add( maskOvrProvider .getInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getFileURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } pbjRead.add(maskOvrProvider.getOverviewIndex(imageChoice)); } else { if (extOvrImgChoice >= 0 && imageChoice >= extOvrImgChoice) { pbjRead.add( ovrInStreamSPI.createInputStreamInstance( ovrSource, ImageIO.getUseCache(), ImageIO.getCacheDirectory())); pbjRead.add(imageChoice - extOvrImgChoice); } else { if (inStream instanceof ImageInputStream && !closeMe) { pbjRead.add(inStream); } else { pbjRead.add( inStreamSPI != null ? inStreamSPI.createInputStreamInstance( source, ImageIO.getUseCache(), ImageIO.getCacheDirectory()) : ImageIO.createImageInputStream(source)); } int overviewImageIndex = dtLayout.getInternalOverviewImageIndex(imageChoice); int index = overviewImageIndex >= 0 ? overviewImageIndex : 0; pbjRead.add(index); } } pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(null); pbjRead.add(null); pbjRead.add(readP); pbjRead.add(READER_SPI.createReaderInstance()); PlanarImage coverageRaster = JAI.create("ImageRead", pbjRead, newHints != null ? newHints : null); if (rescalePixels) { if (!Double.isNaN(noData)) { PlanarImage t = PlanarImage.wrapRenderedImage(coverageRaster); t.setProperty(NoDataContainer.GC_NODATA, new NoDataContainer(noData)); coverageRaster = t; } coverageRaster = PlanarImage.wrapRenderedImage( ImageUtilities.applyRescaling( scales, offsets, coverageRaster, newHints)); } if (inputTransparentColor != null) { coverageRaster = new ImageWorker(coverageRaster) .setRenderingHints(newHints) .makeColorTransparent(inputTransparentColor) .getRenderedOperation(); } ROI roi = null; if (hasMaskOvrProvider) { GridEnvelope ogr = getOriginalGridRange(); Rectangle sourceRegion; if (readP.getSourceRegion() != null) { sourceRegion = readP.getSourceRegion(); } else { sourceRegion = new Rectangle(ogr.getSpan(0), ogr.getSpan(1)); } MaskInfo info = maskOvrProvider.getMaskInfo(imageChoice, sourceRegion, readP); if (info != null) { RenderedOp roiRaster = readROIRaster( info.streamSpi, URLs.fileToUrl(info.file), info.index, newHints, info.readParameters); roi = MaskOverviewProvider.scaleROI(roiRaster, coverageRaster.getBounds()); } } AffineTransform rasterToModel = getRescaledRasterToModel(coverageRaster); try { return createCoverage(coverageRaster, ProjectiveTransform.create(rasterToModel), roi); } catch (Exception e) { ImageUtilities.disposePlanarImageChain(coverageRaster); if (e instanceof DataSourceException) { throw (DataSourceException) e; } throw new DataSourceException(e); } } GeoTiffReader(Object input);  GeoTiffReader(Object input, Hints uHints); Format getFormat(); GridCoverage2D read(GeneralParameterValue[] params); @SuppressWarnings("PMD.CloseResource") // conditional, might have to close the stream, or not GeoTiffIIOMetadataDecoder getMetadata(); @Override int getGridCoverageCount(); @Override GroundControlPoints getGroundControlPoints(); }
GeoTiffReader extends AbstractGridCoverage2DReader implements GridCoverage2DReader { public GridCoverage2D read(GeneralParameterValue[] params) throws IOException { GeneralEnvelope requestedEnvelope = null; Rectangle dim = null; Color inputTransparentColor = null; OverviewPolicy overviewPolicy = null; int[] suggestedTileSize = null; boolean rescalePixels = AbstractGridFormat.RESCALE_PIXELS.getDefaultValue(); if (params != null) { for (int i = 0; i < params.length; i++) { final ParameterValue param = (ParameterValue) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName())) { final GridGeometry2D gg = (GridGeometry2D) param.getValue(); requestedEnvelope = new GeneralEnvelope((Envelope) gg.getEnvelope2D()); dim = gg.getGridRange2D().getBounds(); continue; } if (name.equals(AbstractGridFormat.OVERVIEW_POLICY.getName())) { overviewPolicy = (OverviewPolicy) param.getValue(); continue; } if (name.equals(AbstractGridFormat.INPUT_TRANSPARENT_COLOR.getName())) { inputTransparentColor = (Color) param.getValue(); continue; } if (name.equals(AbstractGridFormat.SUGGESTED_TILE_SIZE.getName())) { String suggestedTileSize_ = (String) param.getValue(); if (suggestedTileSize_ != null && suggestedTileSize_.length() > 0) { suggestedTileSize_ = suggestedTileSize_.trim(); int commaPosition = suggestedTileSize_.indexOf(","); if (commaPosition < 0) { int tileDim = Integer.parseInt(suggestedTileSize_); suggestedTileSize = new int[] {tileDim, tileDim}; } else { int tileW = Integer.parseInt( suggestedTileSize_.substring(0, commaPosition)); int tileH = Integer.parseInt( suggestedTileSize_.substring(commaPosition + 1)); suggestedTileSize = new int[] {tileW, tileH}; } } continue; } if (name.equals(AbstractGridFormat.RESCALE_PIXELS.getName())) { rescalePixels = Boolean.TRUE.equals(param.getValue()); } } } Integer imageChoice = Integer.valueOf(0); final ImageReadParam readP = new ImageReadParam(); try { imageChoice = setReadParams(overviewPolicy, readP, requestedEnvelope, dim); } catch (TransformException e) { throw new DataSourceException(e); } Hints newHints = null; if (suggestedTileSize != null) { newHints = hints.clone(); final ImageLayout layout = new ImageLayout(); layout.setTileGridXOffset(0); layout.setTileGridYOffset(0); layout.setTileHeight(suggestedTileSize[1]); layout.setTileWidth(suggestedTileSize[0]); newHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); } final ParameterBlock pbjRead = new ParameterBlock(); if (maskOvrProvider != null) { if (maskOvrProvider.isExternalOverview(imageChoice)) { pbjRead.add( maskOvrProvider .getExternalOverviewInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getOvrURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } else { pbjRead.add( maskOvrProvider .getInputStreamSpi() .createInputStreamInstance( maskOvrProvider.getFileURL(), ImageIO.getUseCache(), ImageIO.getCacheDirectory())); } pbjRead.add(maskOvrProvider.getOverviewIndex(imageChoice)); } else { if (extOvrImgChoice >= 0 && imageChoice >= extOvrImgChoice) { pbjRead.add( ovrInStreamSPI.createInputStreamInstance( ovrSource, ImageIO.getUseCache(), ImageIO.getCacheDirectory())); pbjRead.add(imageChoice - extOvrImgChoice); } else { if (inStream instanceof ImageInputStream && !closeMe) { pbjRead.add(inStream); } else { pbjRead.add( inStreamSPI != null ? inStreamSPI.createInputStreamInstance( source, ImageIO.getUseCache(), ImageIO.getCacheDirectory()) : ImageIO.createImageInputStream(source)); } int overviewImageIndex = dtLayout.getInternalOverviewImageIndex(imageChoice); int index = overviewImageIndex >= 0 ? overviewImageIndex : 0; pbjRead.add(index); } } pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(Boolean.FALSE); pbjRead.add(null); pbjRead.add(null); pbjRead.add(readP); pbjRead.add(READER_SPI.createReaderInstance()); PlanarImage coverageRaster = JAI.create("ImageRead", pbjRead, newHints != null ? newHints : null); if (rescalePixels) { if (!Double.isNaN(noData)) { PlanarImage t = PlanarImage.wrapRenderedImage(coverageRaster); t.setProperty(NoDataContainer.GC_NODATA, new NoDataContainer(noData)); coverageRaster = t; } coverageRaster = PlanarImage.wrapRenderedImage( ImageUtilities.applyRescaling( scales, offsets, coverageRaster, newHints)); } if (inputTransparentColor != null) { coverageRaster = new ImageWorker(coverageRaster) .setRenderingHints(newHints) .makeColorTransparent(inputTransparentColor) .getRenderedOperation(); } ROI roi = null; if (hasMaskOvrProvider) { GridEnvelope ogr = getOriginalGridRange(); Rectangle sourceRegion; if (readP.getSourceRegion() != null) { sourceRegion = readP.getSourceRegion(); } else { sourceRegion = new Rectangle(ogr.getSpan(0), ogr.getSpan(1)); } MaskInfo info = maskOvrProvider.getMaskInfo(imageChoice, sourceRegion, readP); if (info != null) { RenderedOp roiRaster = readROIRaster( info.streamSpi, URLs.fileToUrl(info.file), info.index, newHints, info.readParameters); roi = MaskOverviewProvider.scaleROI(roiRaster, coverageRaster.getBounds()); } } AffineTransform rasterToModel = getRescaledRasterToModel(coverageRaster); try { return createCoverage(coverageRaster, ProjectiveTransform.create(rasterToModel), roi); } catch (Exception e) { ImageUtilities.disposePlanarImageChain(coverageRaster); if (e instanceof DataSourceException) { throw (DataSourceException) e; } throw new DataSourceException(e); } } GeoTiffReader(Object input);  GeoTiffReader(Object input, Hints uHints); Format getFormat(); GridCoverage2D read(GeneralParameterValue[] params); @SuppressWarnings("PMD.CloseResource") // conditional, might have to close the stream, or not GeoTiffIIOMetadataDecoder getMetadata(); @Override int getGridCoverageCount(); @Override GroundControlPoints getGroundControlPoints(); static final String OVERRIDE_CRS_SWITCH; }