/** * @param filename * the image/raster file (including path and file extension) * @param options * set for this file. * @return a RasterReference * @throws IOException */ public static RasterGeoReference readWorldFile( File filename, RasterIOOptions options ) throws IOException { File worldFile = getWorldFile( filename ); if ( !worldFile.exists() ) { throw new IOException( "No world file for: " + filename ); } if ( log.isDebugEnabled() ) { log.debug( "read worldfile for " + filename ); } BufferedReader br = new BufferedReader( new FileReader( worldFile ) ); RasterGeoReference result = readRasterReference( br, worldFile.getAbsolutePath(), options ); br.close(); return result; }
/** * 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" ); }
throw new IOException( "Given reader may not be null" ); RasterGeoReference worldFile = WorldFileAccess.readWorldFile( readerOnInfoFile, options ); if ( worldFile != null ) {
/** * @param reader * to a world file. * @param options * set for this stream. * @return a RasterReference * @throws IOException */ public static RasterGeoReference readWorldFile( Reader reader, RasterIOOptions options ) throws IOException { if ( reader == null ) { throw new IOException( "Reader is null, no world file found." ); } BufferedReader br = ( reader instanceof BufferedReader ) ? (BufferedReader) reader : new BufferedReader( reader ); return readRasterReference( br, "from reader", options ); }
if ( nOpts != null && nOpts.readWorldFile() ) { try { RasterGeoReference geoRef = WorldFileAccess.readWorldFile( filename, nOpts ); nOpts.setRasterGeoReference( geoRef ); } catch ( IOException e ) {
/** * @param stream * the stream pointing to a world file. * @param options * set for this stream. * @return a RasterReference * @throws IOException */ public static RasterGeoReference readWorldFile( InputStream stream, RasterIOOptions options ) throws IOException { if ( stream == null ) { throw new IOException( "Stream is null, no world file found." ); } BufferedReader br = new BufferedReader( new InputStreamReader( stream ) ); return readRasterReference( br, "from stream", options ); }
/** * 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(); }
private AbstractRaster loadFromReader( JAIRasterDataReader reader, RasterIOOptions options ) { width = reader.getColumns(); height = reader.getRows(); setID( options ); reader.close(); OriginLocation definedRasterOrigLoc = options.getRasterOriginLocation(); // create a 1:1 mapping rasterReference = new RasterGeoReference( definedRasterOrigLoc, 1, -1, 0.5, height - 0.5 ); if ( options.hasRasterGeoReference() ) { rasterReference = options.getRasterGeoReference(); } else { if ( options.readWorldFile() ) { try { if ( file != null ) { rasterReference = WorldFileAccess.readWorldFile( file, options ); } } catch ( IOException e ) { // } } } Envelope envelope = rasterReference.getEnvelope( width, height, null ); // RasterDataContainer source = RasterDataContainerFactory.withDefaultLoadingPolicy( reader ); // RasterDataContainer source = RasterDataContainerFactory.withLoadingPolicy( reader, options.getLoadingPolicy() // ); RasterDataInfo rdi = reader.getRasterDataInfo(); return RasterFactory.createEmptyRaster( rdi, envelope, rasterReference, this, true, options ); }
/** * 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 ) ); }
try { if ( reader.file() != null ) { rasterReference = WorldFileAccess.readWorldFile( reader.file(), opts );
@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 ); }
@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 ); } }