By example at:
http://svn.osgeo.org/geotools/trunk/modules/plugin/geotiff/src/test/java/org/geotools/gce/geotiff/GeoTiffWriterTest.java
the following test code I assume works. I've run similar in my code and the good news is that the file can be read as tested but unfortunately the contents of the file are a projection string instead of a world file. It's possible this is user error, but thought I'd post it anyways. Thanks for taking a look. Required work around for me was to create my own world file from the affinetransform I have. Using 11-SNAPSHOT via maven.
@Test // @Ignore public void testWriteTFW() throws Exception{
// // no crs geotiff // final File noCrs = TestData.file(GeoTiffReaderTest.class, "no_crs.tif"); final AbstractGridFormat format = new GeoTiffFormat(); assertTrue(format.accepts(noCrs));
// hint for CRS final CoordinateReferenceSystem crs = CRS.decode("EPSG:32632", true); final Hints hint = new Hints(); hint.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, crs);
// getting a reader GeoTiffReader reader = new GeoTiffReader(noCrs, hint);
// reading the coverage GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
// check coverage and crs assertNotNull(coverage); assertNotNull(coverage.getCoordinateReferenceSystem()); assertEquals(CRS.lookupIdentifier(coverage.getCoordinateReferenceSystem(), true), "EPSG:32632"); reader.dispose();
// get a writer 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());
}
|