/** * writes a RasterReference into a world file (with .wld extension). * * @param renv * the envelope * @param file * the raster file * @throws IOException */ public static void writeWorldFile( RasterGeoReference renv, File file ) throws IOException { writeWorldFile( renv, file, "wld" ); }
/** * writes a RasterReference into a world file. * * @param renv * the envelope * @param file * the raster file * @param extension * the file extension for the world file (eg. 'wld', 'tfw', etc) * @throws IOException */ public static void writeWorldFile( RasterGeoReference renv, File file, String extension ) throws IOException { File f = new File( FileUtils.getBasename( file ) + "." + extension ); FileWriter fw = new FileWriter( f ); PrintWriter pw = new PrintWriter( fw ); writeWorldFile( renv, pw ); pw.close(); fw.close(); }
/** * Write the grid info file which is basically a world file with supplement information. * * @param writer * to write to. * @param metaInfo * to write. * @param options * containing information about the crs, origin location etc. * @throws NumberFormatException * @throws IOException */ public static void write( PrintWriter writer, GridMetaInfoFile metaInfo, RasterIOOptions options ) throws IOException { if ( writer == null ) { throw new IOException( "The writer is null." ); } // begins with standard world file entries WorldFileAccess.writeWorldFile( metaInfo.getGeoReference(), writer ); // now infos on grid writer.println( metaInfo.rows ); writer.println( metaInfo.columns ); writer.println( metaInfo.tileRasterWidth ); writer.println( metaInfo.tileRasterHeight ); writer.println( metaInfo.dataInfo.bands ); writer.println( DataType.toDataBufferType( metaInfo.dataInfo.dataType ) ); }
@Override public void write( AbstractRaster raster, File file, RasterIOOptions options ) throws IOException { LOG.debug( "writing " + file + " with ImageIO" ); String format = options != null ? options.get( RasterIOOptions.OPT_FORMAT ) : null; if ( format == null ) { format = FileUtils.getFileExtension( file ); } LOG.debug( "Writing raster with width: {} height: {}", raster.getColumns(), raster.getRows() ); if ( "geotiff".equals( format ) ) { GeoTiffWriter.save( raster, file ); } else { IIORasterDataWriter.saveRasterDataToFile( raster.getAsSimpleRaster().getRasterData(), file, format ); RasterGeoReference rasterReference = raster.getRasterReference(); WorldFileAccess.writeWorldFile( rasterReference, file ); } }
@Override public void write( AbstractRaster raster, File file, RasterIOOptions options ) throws IOException { LOG.debug( "writing " + file + " with JAI" ); String ext = FileUtils.getFileExtension( file ); String format = JAIRasterIOProvider.getJAIFormat( ext ); if ( format != null ) { JAIRasterDataWriter.saveRasterDataToFile( raster.getAsSimpleRaster().getRasterData(), file.getAbsolutePath(), format ); } else { JAIRasterDataWriter.saveRasterDataToFile( raster.getAsSimpleRaster().getRasterData(), file.getAbsolutePath() ); } RasterGeoReference rasterReference = raster.getRasterReference(); WorldFileAccess.writeWorldFile( rasterReference, file ); }