@Test public void testWriteBigTiff() throws Exception { String files[] = new String[]{"geo.tiff", "no_crs_no_envelope.tif"}; int i=0; for (String file : files){ final File input = TestData.file(GeoTiffReaderTest.class, file); final AbstractGridFormat format = new GeoTiffFormat(); assertTrue(format.accepts(input)); GeoTiffReader reader = new GeoTiffReader(input); GridCoverage2D coverage = (GridCoverage2D) reader.read(null); assertNotNull(coverage); assertNotNull(coverage.getCoordinateReferenceSystem()); reader.dispose(); final File output = new File(TestData.file(GeoTiffReaderTest.class, "."), "bigtiff" + i + ".tif"); GeoTiffWriter writer = new GeoTiffWriter(output); GeoTiffWriteParams params = new GeoTiffWriteParams(); params.setForceToBigTIFF(true); ParameterValue<GeoToolsWriteParams> value = GeoTiffFormat.GEOTOOLS_WRITE_PARAMS.createValue(); value.setValue(params); writer.write(coverage, new GeneralParameterValue[]{value}); writer.dispose(); coverage.dispose(true); reader = new GeoTiffReader(output); RenderedImage ri = reader.read(null).getRenderedImage(); assertEquals(ri.getWidth(), i == 0 ? 120 : 12); assertEquals(ri.getHeight(), i == 0 ? 120 : 12); reader.dispose(); FileInputStream fis = null; try { fis = new FileInputStream(output); byte[] bytes = new byte[6]; fis.read(bytes); if (bytes[0] == 77 && bytes[1] == 77){ assertEquals(bytes[3], 43); } else { assertEquals(bytes[2], 43); } } finally { if (fis != null){ try { fis.close(); } catch (Throwable t){ } } } i++; } }
public void write(final GridCoverage gc, final GeneralParameterValue[] params) throws IllegalArgumentException, IOException, IndexOutOfBoundsException { GeoToolsWriteParams gtParams = null; boolean writeTfw = GeoTiffFormat.WRITE_TFW.getDefaultValue(); if (params != null) { if (params != null) { Parameter param; final int length = params.length; for (int i = 0; i < length; i++) { param = (Parameter) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName())) { gtParams = (GeoToolsWriteParams) param.getValue(); } if (name.equals(GeoTiffFormat.WRITE_TFW.getName())) { writeTfw = (Boolean) param.getValue(); } } } } if (gtParams == null) gtParams = new GeoTiffWriteParams(); final GridGeometry2D gg = (GridGeometry2D) gc.getGridGeometry(); GridEnvelope2D range = gg.getGridRange2D(); final Rectangle sourceRegion = gtParams.getSourceRegion(); if (sourceRegion != null) range = new GridEnvelope2D(sourceRegion); final AffineTransform tr = (AffineTransform) gg.getGridToCRS2D(); final CoordinateReferenceSystem crs = gg.getCoordinateReferenceSystem2D(); final double inNoData = getCandidateNoData(gc); if (crs instanceof ProjectedCRS || crs instanceof GeographicCRS) { final CRS2GeoTiffMetadataAdapter adapter = new CRS2GeoTiffMetadataAdapter(crs); final GeoTiffIIOMetadataEncoder metadata = adapter.parseCoordinateReferenceSystem(); if (!Double.isNaN(inNoData)) metadata.setNoData(inNoData); if (metadataKeyValue != null && !metadataKeyValue.isEmpty()) { metadata.setTiffTagsMetadata(metadataKeyValue); } setGeoReference(crs, metadata, tr, range); writeImage(((GridCoverage2D) gc).geophysics(true).getRenderedImage(), this.outStream, metadata, gtParams); if (writeTfw && (destination instanceof File)) { final File destFile = (File) this.destination; final File tfw = new File(destFile.getParentFile(), destFile.getName().replace( "tif", "tfw")); final BufferedWriter outW = new BufferedWriter(new FileWriter(tfw)); try { outW.write(gc.getCoordinateReferenceSystem().toWKT()); } finally { try { outW.close(); } catch (Exception e) { } } } } else { throw new GeoTiffException( null, "The supplied grid coverage uses an unsupported crs! You are allowed to" + " use only projected and geographic coordinate reference systems", null); } }
GeoTiffWriter extends AbstractGridCoverageWriter implements
		GridCoverageWriter { public void write(final GridCoverage gc, final GeneralParameterValue[] params) throws IllegalArgumentException, IOException, IndexOutOfBoundsException { GeoToolsWriteParams gtParams = null; boolean writeTfw = GeoTiffFormat.WRITE_TFW.getDefaultValue(); if (params != null) { if (params != null) { Parameter param; final int length = params.length; for (int i = 0; i < length; i++) { param = (Parameter) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName())) { gtParams = (GeoToolsWriteParams) param.getValue(); } if (name.equals(GeoTiffFormat.WRITE_TFW.getName())) { writeTfw = (Boolean) param.getValue(); } } } } if (gtParams == null) gtParams = new GeoTiffWriteParams(); final GridGeometry2D gg = (GridGeometry2D) gc.getGridGeometry(); GridEnvelope2D range = gg.getGridRange2D(); final Rectangle sourceRegion = gtParams.getSourceRegion(); if (sourceRegion != null) range = new GridEnvelope2D(sourceRegion); final AffineTransform tr = (AffineTransform) gg.getGridToCRS2D(); final CoordinateReferenceSystem crs = gg.getCoordinateReferenceSystem2D(); final double inNoData = getCandidateNoData(gc); if (crs instanceof ProjectedCRS || crs instanceof GeographicCRS) { final CRS2GeoTiffMetadataAdapter adapter = new CRS2GeoTiffMetadataAdapter(crs); final GeoTiffIIOMetadataEncoder metadata = adapter.parseCoordinateReferenceSystem(); if (!Double.isNaN(inNoData)) metadata.setNoData(inNoData); if (metadataKeyValue != null && !metadataKeyValue.isEmpty()) { metadata.setTiffTagsMetadata(metadataKeyValue); } setGeoReference(crs, metadata, tr, range); writeImage(((GridCoverage2D) gc).geophysics(true).getRenderedImage(), this.outStream, metadata, gtParams); if (writeTfw && (destination instanceof File)) { final File destFile = (File) this.destination; final File tfw = new File(destFile.getParentFile(), destFile.getName().replace( "tif", "tfw")); final BufferedWriter outW = new BufferedWriter(new FileWriter(tfw)); try { outW.write(gc.getCoordinateReferenceSystem().toWKT()); } finally { try { outW.close(); } catch (Exception e) { } } } } else { throw new GeoTiffException( null, "The supplied grid coverage uses an unsupported crs! You are allowed to" + " use only projected and geographic coordinate reference systems", null); } } }
GeoTiffWriter extends AbstractGridCoverageWriter implements
		GridCoverageWriter { public void write(final GridCoverage gc, final GeneralParameterValue[] params) throws IllegalArgumentException, IOException, IndexOutOfBoundsException { GeoToolsWriteParams gtParams = null; boolean writeTfw = GeoTiffFormat.WRITE_TFW.getDefaultValue(); if (params != null) { if (params != null) { Parameter param; final int length = params.length; for (int i = 0; i < length; i++) { param = (Parameter) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName())) { gtParams = (GeoToolsWriteParams) param.getValue(); } if (name.equals(GeoTiffFormat.WRITE_TFW.getName())) { writeTfw = (Boolean) param.getValue(); } } } } if (gtParams == null) gtParams = new GeoTiffWriteParams(); final GridGeometry2D gg = (GridGeometry2D) gc.getGridGeometry(); GridEnvelope2D range = gg.getGridRange2D(); final Rectangle sourceRegion = gtParams.getSourceRegion(); if (sourceRegion != null) range = new GridEnvelope2D(sourceRegion); final AffineTransform tr = (AffineTransform) gg.getGridToCRS2D(); final CoordinateReferenceSystem crs = gg.getCoordinateReferenceSystem2D(); final double inNoData = getCandidateNoData(gc); if (crs instanceof ProjectedCRS || crs instanceof GeographicCRS) { final CRS2GeoTiffMetadataAdapter adapter = new CRS2GeoTiffMetadataAdapter(crs); final GeoTiffIIOMetadataEncoder metadata = adapter.parseCoordinateReferenceSystem(); if (!Double.isNaN(inNoData)) metadata.setNoData(inNoData); if (metadataKeyValue != null && !metadataKeyValue.isEmpty()) { metadata.setTiffTagsMetadata(metadataKeyValue); } setGeoReference(crs, metadata, tr, range); writeImage(((GridCoverage2D) gc).geophysics(true).getRenderedImage(), this.outStream, metadata, gtParams); if (writeTfw && (destination instanceof File)) { final File destFile = (File) this.destination; final File tfw = new File(destFile.getParentFile(), destFile.getName().replace( "tif", "tfw")); final BufferedWriter outW = new BufferedWriter(new FileWriter(tfw)); try { outW.write(gc.getCoordinateReferenceSystem().toWKT()); } finally { try { outW.close(); } catch (Exception e) { } } } } else { throw new GeoTiffException( null, "The supplied grid coverage uses an unsupported crs! You are allowed to" + " use only projected and geographic coordinate reference systems", null); } } GeoTiffWriter(Object destination);  GeoTiffWriter(Object destination, Hints hints); }
GeoTiffWriter extends AbstractGridCoverageWriter implements
		GridCoverageWriter { public void write(final GridCoverage gc, final GeneralParameterValue[] params) throws IllegalArgumentException, IOException, IndexOutOfBoundsException { GeoToolsWriteParams gtParams = null; boolean writeTfw = GeoTiffFormat.WRITE_TFW.getDefaultValue(); if (params != null) { if (params != null) { Parameter param; final int length = params.length; for (int i = 0; i < length; i++) { param = (Parameter) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName())) { gtParams = (GeoToolsWriteParams) param.getValue(); } if (name.equals(GeoTiffFormat.WRITE_TFW.getName())) { writeTfw = (Boolean) param.getValue(); } } } } if (gtParams == null) gtParams = new GeoTiffWriteParams(); final GridGeometry2D gg = (GridGeometry2D) gc.getGridGeometry(); GridEnvelope2D range = gg.getGridRange2D(); final Rectangle sourceRegion = gtParams.getSourceRegion(); if (sourceRegion != null) range = new GridEnvelope2D(sourceRegion); final AffineTransform tr = (AffineTransform) gg.getGridToCRS2D(); final CoordinateReferenceSystem crs = gg.getCoordinateReferenceSystem2D(); final double inNoData = getCandidateNoData(gc); if (crs instanceof ProjectedCRS || crs instanceof GeographicCRS) { final CRS2GeoTiffMetadataAdapter adapter = new CRS2GeoTiffMetadataAdapter(crs); final GeoTiffIIOMetadataEncoder metadata = adapter.parseCoordinateReferenceSystem(); if (!Double.isNaN(inNoData)) metadata.setNoData(inNoData); if (metadataKeyValue != null && !metadataKeyValue.isEmpty()) { metadata.setTiffTagsMetadata(metadataKeyValue); } setGeoReference(crs, metadata, tr, range); writeImage(((GridCoverage2D) gc).geophysics(true).getRenderedImage(), this.outStream, metadata, gtParams); if (writeTfw && (destination instanceof File)) { final File destFile = (File) this.destination; final File tfw = new File(destFile.getParentFile(), destFile.getName().replace( "tif", "tfw")); final BufferedWriter outW = new BufferedWriter(new FileWriter(tfw)); try { outW.write(gc.getCoordinateReferenceSystem().toWKT()); } finally { try { outW.close(); } catch (Exception e) { } } } } else { throw new GeoTiffException( null, "The supplied grid coverage uses an unsupported crs! You are allowed to" + " use only projected and geographic coordinate reference systems", null); } } GeoTiffWriter(Object destination);  GeoTiffWriter(Object destination, Hints hints); @Override void setMetadataValue(String name, String value); Format getFormat(); void write(final GridCoverage gc, final GeneralParameterValue[] params); }
GeoTiffWriter extends AbstractGridCoverageWriter implements
		GridCoverageWriter { public void write(final GridCoverage gc, final GeneralParameterValue[] params) throws IllegalArgumentException, IOException, IndexOutOfBoundsException { GeoToolsWriteParams gtParams = null; boolean writeTfw = GeoTiffFormat.WRITE_TFW.getDefaultValue(); if (params != null) { if (params != null) { Parameter param; final int length = params.length; for (int i = 0; i < length; i++) { param = (Parameter) params[i]; final ReferenceIdentifier name = param.getDescriptor().getName(); if (name.equals(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName())) { gtParams = (GeoToolsWriteParams) param.getValue(); } if (name.equals(GeoTiffFormat.WRITE_TFW.getName())) { writeTfw = (Boolean) param.getValue(); } } } } if (gtParams == null) gtParams = new GeoTiffWriteParams(); final GridGeometry2D gg = (GridGeometry2D) gc.getGridGeometry(); GridEnvelope2D range = gg.getGridRange2D(); final Rectangle sourceRegion = gtParams.getSourceRegion(); if (sourceRegion != null) range = new GridEnvelope2D(sourceRegion); final AffineTransform tr = (AffineTransform) gg.getGridToCRS2D(); final CoordinateReferenceSystem crs = gg.getCoordinateReferenceSystem2D(); final double inNoData = getCandidateNoData(gc); if (crs instanceof ProjectedCRS || crs instanceof GeographicCRS) { final CRS2GeoTiffMetadataAdapter adapter = new CRS2GeoTiffMetadataAdapter(crs); final GeoTiffIIOMetadataEncoder metadata = adapter.parseCoordinateReferenceSystem(); if (!Double.isNaN(inNoData)) metadata.setNoData(inNoData); if (metadataKeyValue != null && !metadataKeyValue.isEmpty()) { metadata.setTiffTagsMetadata(metadataKeyValue); } setGeoReference(crs, metadata, tr, range); writeImage(((GridCoverage2D) gc).geophysics(true).getRenderedImage(), this.outStream, metadata, gtParams); if (writeTfw && (destination instanceof File)) { final File destFile = (File) this.destination; final File tfw = new File(destFile.getParentFile(), destFile.getName().replace( "tif", "tfw")); final BufferedWriter outW = new BufferedWriter(new FileWriter(tfw)); try { outW.write(gc.getCoordinateReferenceSystem().toWKT()); } finally { try { outW.close(); } catch (Exception e) { } } } } else { throw new GeoTiffException( null, "The supplied grid coverage uses an unsupported crs! You are allowed to" + " use only projected and geographic coordinate reference systems", null); } } GeoTiffWriter(Object destination);  GeoTiffWriter(Object destination, Hints hints); @Override void setMetadataValue(String name, String value); Format getFormat(); void write(final GridCoverage gc, final GeneralParameterValue[] params);  }