Class ProductIO
- java.lang.Object
-
- org.esa.snap.core.dataio.ProductIO
-
public class ProductIO extends Object
TheProductIO
class provides several utility methods concerning data I/O for remote sensing data products.For example, a product can be read in using a single method call:
Product product = ProductIO.readProduct("test.prd");
and written out in a similar way:ProductIO.writeProduct(product, "HDF5", "test.h5", null);
- Version:
- $Revision$ $Date$
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_FORMAT_NAME
The name of the default product format.static boolean
DEFAULT_WRITE_RASTER_CONCURRENT
static String
SYSTEM_PROPERTY_CONCURRENT
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ProductReader
getProductReader(String formatName)
Gets a product reader for the given format name.static ProductReader
getProductReaderForInput(Object input)
Tries to find a product reader instance suitable for the given input.static ProductWriter
getProductWriter(String formatName)
Gets a product writer for the given format name.static String[]
getProductWriterExtensions(String formatName)
Gets an array of writer product file extensions for the given format name.static void
readLevelBandRasterData(AbstractProductReader reader, Band destBand, LevelImageSupport lvlSupport, Rectangle destRect, ProductData destBuffer)
This method is not part of the official API and might change in the future.static Product
readProduct(File file)
Reads the data product specified by the given file.static Product
readProduct(File file, String... formatNames)
Reads the data product specified by the given file.static Product
readProduct(File file, ProductSubsetDef subsetDef)
Reads the data product specified by the given file.static Product
readProduct(String filePath)
Reads the data product specified by the given file path.static void
writeProduct(Product product, File file, String formatName, boolean incremental)
Writes a product with the specified format to the given file.static void
writeProduct(Product product, File file, String formatName, boolean incremental, ProgressMonitor pm)
Writes a product with the specified format to the given file.static void
writeProduct(Product product, String filePath, String formatName)
Writes a product with the specified format to the given file path.static void
writeProduct(Product product, String filePath, String formatName, ProgressMonitor pm)
Writes a product with the specified format to the given file path.
-
-
-
Field Detail
-
DEFAULT_FORMAT_NAME
public static final String DEFAULT_FORMAT_NAME
The name of the default product format.- See Also:
- Constant Field Values
-
SYSTEM_PROPERTY_CONCURRENT
public static final String SYSTEM_PROPERTY_CONCURRENT
- See Also:
- Constant Field Values
-
DEFAULT_WRITE_RASTER_CONCURRENT
public static final boolean DEFAULT_WRITE_RASTER_CONCURRENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getProductReader
public static ProductReader getProductReader(String formatName)
Gets a product reader for the given format name.- Parameters:
formatName
- the product format name- Returns:
- a suitable product reader or
null
if none was found
-
getProductWriterExtensions
public static String[] getProductWriterExtensions(String formatName)
Gets an array of writer product file extensions for the given format name.- Parameters:
formatName
- the format name- Returns:
- an array of extensions or null if the format does not exist
-
getProductWriter
public static ProductWriter getProductWriter(String formatName)
Gets a product writer for the given format name.- Parameters:
formatName
- the product format name- Returns:
- a suitable product writer or
null
if none was found
-
readProduct
public static Product readProduct(File file, String... formatNames) throws IOException
Reads the data product specified by the given file.The returned product will be associated with a reader capable of decoding the file (also see
Product.productReader
). If more than one appropriate reader exists in the registry, the returned product will be associated with the reader which is the most preferred according to the product format names supplied as last argument. If no reader capable of decoding the file is capable of handling any of these product formats, the returned product will be associated with the first reader found in the registry which is capable of decoding the file.The method does not automatically load band raster data, so
Band.rasterData
will always be null for all bands in the product returned by this method.- Parameters:
file
- the data product fileformatNames
- a list of product format names defining the preference, if more than one reader found in the registry is capable of decoding the file.- Returns:
- a data model as an in-memory representation of the given product file or
null
, if no appropriate reader was found for the given product file - Throws:
IOException
- if an I/O error occurs- Since:
- 4.9
- See Also:
readProduct(String)
,readProduct(File)
-
readProduct
public static Product readProduct(String filePath) throws IOException
Reads the data product specified by the given file path.The product returned will be associated with the reader appropriate for the given file format (see also
Product.productReader
).The method does not automatically read band data, thus
Band.rasterData
will always be null for all bands in the product returned by this method.- Parameters:
filePath
- the data product file path- Returns:
- a data model as an in-memory representation of the given product file or
null
if no appropriate reader was found for the given product file - Throws:
IOException
- if an I/O error occurs- See Also:
readProduct(File)
-
readProduct
public static Product readProduct(File file) throws IOException
Reads the data product specified by the given file.The product returned will be associated with the reader appropriate for the given file format (see also
Product.productReader
).The method does not automatically read band data, thus
Band.rasterData
will always be null for all bands in the product returned by this method.- Parameters:
file
- the data product file- Returns:
- a data model as an in-memory representation of the given product file or
null
if no appropriate reader was found for the given product file - Throws:
IOException
- if an I/O error occurs- See Also:
readProduct(String)
-
readProduct
public static Product readProduct(File file, ProductSubsetDef subsetDef) throws IOException
Reads the data product specified by the given file.The product returned will be associated with the reader appropriate for the given file format (see also
Product.productReader
).The method does not automatically read band data, thus
Band.rasterData
will always be null for all bands in the product returned by this method.- Parameters:
file
- the data product filesubsetDef
- the subset of a product- Returns:
- a data model as an in-memory representation of the given product file or
null
if no appropriate reader was found for the given product file - Throws:
IOException
- if an I/O error occurs
-
getProductReaderForInput
public static ProductReader getProductReaderForInput(Object input)
Tries to find a product reader instance suitable for the given input. The method returnsnull
, if no registered product reader can handle the giveninput
value.The
input
may be of any type, but most likely it will be a file path given by aString
orFile
value. Some readers may also directly support anImageInputStream
object.- Parameters:
input
- the input object.- Returns:
- a product reader for the given
input
ornull
if no registered reader can handle the it. - See Also:
ProductReaderPlugIn.getDecodeQualification(Object)
,ProductReader.readProductNodes(Object, ProductSubsetDef)
-
writeProduct
public static void writeProduct(Product product, String filePath, String formatName) throws IOException
Writes a product with the specified format to the given file path.The method also writes all band data to the file. Therefore the band data must either
- be completely loaded (
Band.rasterData
is notnull
) - or the product must be associated with a product reader (
Product.productReader
is notnull
) so that unloaded data can be reloaded.
- Parameters:
product
- the product, must not benull
filePath
- the file pathformatName
- the name of a supported product format, e.g. "HDF5". Ifnull
, the default format "BEAM-DIMAP" will be used- Throws:
IOException
- if an IOException occurs
- be completely loaded (
-
writeProduct
public static void writeProduct(Product product, String filePath, String formatName, ProgressMonitor pm) throws IOException
Writes a product with the specified format to the given file path.The method also writes all band data to the file. Therefore the band data must either
- be completely loaded (
Band.rasterData
is notnull
) - or the product must be associated with a product reader (
Product.productReader
is notnull
) so that unloaded data can be reloaded.
- Parameters:
product
- the product, must not benull
filePath
- the file pathformatName
- the name of a supported product format, e.g. "HDF5". Ifnull
, the default format "BEAM-DIMAP" will be usedpm
- a monitor to inform the user about progress- Throws:
IOException
- if an IOException occurs
- be completely loaded (
-
writeProduct
public static void writeProduct(Product product, File file, String formatName, boolean incremental) throws IOException
Writes a product with the specified format to the given file.The method also writes all band data to the file. Therefore the band data must either
- be completely loaded (
Band.rasterData
is notnull
) - or the product must be associated with a product reader (
Product.productReader
is notnull
) so that unloaded data can be reloaded.
- Parameters:
product
- the product, must not benull
file
- the product file , must not benull
formatName
- the name of a supported product format, e.g. "HDF5". Ifnull
, the default format "BEAM-DIMAP" will be usedincremental
- switch the product writer in incremental mode or not.- Throws:
IOException
- if an IOException occurs
- be completely loaded (
-
writeProduct
public static void writeProduct(Product product, File file, String formatName, boolean incremental, ProgressMonitor pm) throws IOException
Writes a product with the specified format to the given file.The method also writes all band data to the file. Therefore the band data must either
- be completely loaded (
Band.rasterData
is notnull
) - or the product must be associated with a product reader (
Product.productReader
is notnull
) so that unloaded data can be reloaded.
- Parameters:
product
- the product, must not benull
file
- the product file , must not benull
formatName
- the name of a supported product format, e.g. "HDF5". Ifnull
, the default format "BEAM-DIMAP" will be usedincremental
- switch the product writer in incremental mode or not.pm
- a monitor to inform the user about progress- Throws:
IOException
- if an IOException occurs
- be completely loaded (
-
readLevelBandRasterData
public static void readLevelBandRasterData(AbstractProductReader reader, Band destBand, LevelImageSupport lvlSupport, Rectangle destRect, ProductData destBuffer) throws IOException
This method is not part of the official API and might change in the future.The method directly delegates to
AbstractProductReader.readProductNodesImpl()
which is not publicly available.This overcomes a short coming in the current API. A reader can be used with a SubsetDef but this can not be changed dynamically.
- Parameters:
reader
- the reader to read fromdestBand
- the band which shall be readlvlSupport
- defines the level (resolution) within the level image pyramid which shall be readdestRect
- the rectangular area which shall be filled with datadestBuffer
- the buffer where to put the data- Throws:
IOException
- in case an error occurs during reading
-
-