@Test public void testWriteTFW() throws Exception{ final File noCrs = TestData.file(GeoTiffReaderTest.class, "no_crs.tif"); final AbstractGridFormat format = new GeoTiffFormat(); assertTrue(format.accepts(noCrs)); final CoordinateReferenceSystem crs = CRS.decode("EPSG:32632", true); final Hints hint = new Hints(); hint.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, crs); GeoTiffReader reader = new GeoTiffReader(noCrs, hint); GridCoverage2D coverage = (GridCoverage2D) reader.read(null); assertNotNull(coverage); assertNotNull(coverage.getCoordinateReferenceSystem()); assertEquals(CRS.lookupIdentifier(coverage.getCoordinateReferenceSystem(), true), "EPSG:32632"); reader.dispose(); final File noCrsTFW = new File(TestData.file(GeoTiffReaderTest.class, "."),"no_crs_tfw.tif"); GeoTiffWriter writer = new GeoTiffWriter(noCrsTFW); final ParameterValue<Boolean> tfw = GeoTiffFormat.WRITE_TFW.createValue(); tfw.setValue(true); writer.write(coverage,new GeneralParameterValue[]{tfw} ); writer.dispose(); coverage.dispose(true); final File finalTFW=new File(noCrsTFW.getParent(),noCrsTFW.getName().replace("tif", "tfw")); assertTrue(finalTFW.canRead()); }
@SuppressWarnings("unchecked") 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 { @SuppressWarnings("unchecked") 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 { @SuppressWarnings("unchecked") 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 { @SuppressWarnings("unchecked") 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(); @SuppressWarnings("unchecked") void write(final GridCoverage gc,
			final GeneralParameterValue[] params); final static IIOMetadata createGeoTiffIIOMetadata(
			ImageWriter writer, ImageTypeSpecifier type,
			GeoTiffIIOMetadataEncoder geoTIFFMetadata, ImageWriteParam params); }
GeoTiffWriter extends AbstractGridCoverageWriter implements
		GridCoverageWriter { @SuppressWarnings("unchecked") 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(); @SuppressWarnings("unchecked") void write(final GridCoverage gc,
			final GeneralParameterValue[] params); final static IIOMetadata createGeoTiffIIOMetadata(
			ImageWriter writer, ImageTypeSpecifier type,
			GeoTiffIIOMetadataEncoder geoTIFFMetadata, ImageWriteParam params);  }