org.geotools.image.io.netcdf
Class NetcdfMetadata

java.lang.Object
  extended by javax.imageio.metadata.IIOMetadata
      extended by org.geotools.image.io.metadata.GeographicMetadata
          extended by org.geotools.image.io.netcdf.NetcdfMetadata

public class NetcdfMetadata
extends GeographicMetadata

Metadata from NetCDF file. This implementation assumes that the NetCDF file follows the CF Metadata conventions.

Limitation: Current implementation retains only the first coordinate system found in the NetCDF file or for a given variable. The org.geotools.coverage.io package would not know what to do with the extra coordinate systems anyway.

Since:
2.4
Version:
$Id: NetcdfMetadata.java 30775 2008-06-20 15:50:30Z cedricbr $
Author:
Martin Desruisseaux

Field Summary
 
Fields inherited from class javax.imageio.metadata.IIOMetadata
controller, defaultController, extraMetadataFormatClassNames, extraMetadataFormatNames, nativeMetadataFormatClassName, nativeMetadataFormatName, standardFormatSupported
 
Constructor Summary
NetcdfMetadata(javax.imageio.ImageReader reader, ucar.nc2.dataset.NetcdfDataset file)
          Creates metadata from the specified file.
NetcdfMetadata(javax.imageio.ImageReader reader, ucar.nc2.dataset.VariableDS variable)
          Creates metadata from the specified file.
 
Method Summary
 void addCoordinateAxis(ucar.nc2.dataset.CoordinateAxis axis)
          Adds the specified coordinate axis.
 void addCoordinateSystem(ucar.nc2.dataset.CoordinateSystem cs)
          Adds the specified coordinate system.
 void addSampleDimension(ucar.nc2.dataset.VariableDS variable)
          Adds sample dimension information for the specified variable.
protected  boolean forcePacking(java.lang.String attribute)
          Returns true if an attribute (usually the valid range) should be converted from unpacked to packed units.
protected  java.text.Format getAxisFormat(ucar.nc2.constants.AxisType type, java.lang.String prototype)
          Returns a format to use for parsing values along the specified axis type.
 
Methods inherited from class org.geotools.image.io.metadata.GeographicMetadata
addBand, createLoggedFormat, getAsTree, getBand, getGeometry, getLocale, getNumBands, getReferencing, getSampleType, isReadOnly, mergeTree, mergeTree, reset, setSampleType, toString, warningOccurred
 
Methods inherited from class javax.imageio.metadata.IIOMetadata
activateController, getController, getDefaultController, getExtraMetadataFormatNames, getMetadataFormat, getMetadataFormatNames, getNativeMetadataFormatName, getStandardChromaNode, getStandardCompressionNode, getStandardDataNode, getStandardDimensionNode, getStandardDocumentNode, getStandardTextNode, getStandardTileNode, getStandardTransparencyNode, getStandardTree, hasController, isStandardMetadataFormatSupported, setController, setFromTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NetcdfMetadata

public NetcdfMetadata(javax.imageio.ImageReader reader,
                      ucar.nc2.dataset.NetcdfDataset file)
Creates metadata from the specified file. This constructor is typically invoked for creating stream metadata. Note that CoordSysBuilder.addCoordinateSystems(ucar.nc2.dataset.NetcdfDataset, ucar.nc2.util.CancelTask) should have been invoked (if needed) before this constructor.


NetcdfMetadata

public NetcdfMetadata(javax.imageio.ImageReader reader,
                      ucar.nc2.dataset.VariableDS variable)
Creates metadata from the specified file. This constructor is typically invoked for creating image metadata. Note that CoordSysBuilder.addCoordinateSystems(ucar.nc2.dataset.NetcdfDataset, ucar.nc2.util.CancelTask) should have been invoked (if needed) before this constructor.

Method Detail

addCoordinateSystem

public void addCoordinateSystem(ucar.nc2.dataset.CoordinateSystem cs)
Adds the specified coordinate system. Current implementation can adds at most one coordinate system, but this limitation may be revisited in a future Geotools version.

Parameters:
cs - The coordinate system to add.

addCoordinateAxis

public void addCoordinateAxis(ucar.nc2.dataset.CoordinateAxis axis)
Adds the specified coordinate axis. This method is invoked recursively by addCoordinateSystem(ucar.nc2.dataset.CoordinateSystem).

Parameters:
axis - The axis to add.

addSampleDimension

public void addSampleDimension(ucar.nc2.dataset.VariableDS variable)
Adds sample dimension information for the specified variable.

Parameters:
variable - The variable to add as a sample dimension.

getAxisFormat

protected java.text.Format getAxisFormat(ucar.nc2.constants.AxisType type,
                                         java.lang.String prototype)
Returns a format to use for parsing values along the specified axis type. This method is invoked when parsing the date part of axis units like "days since 1990-01-01 00:00:00". Subclasses should override this method if the date part is formatted in a different way. The default implementation returns the following formats:

The Canada locale is used by default for most formats because it is relatively close to ISO (for example regarding days and months order in dates) while using the English symbols.

Parameters:
type - The type of the axis.
prototype - An example of the values to be parsed. Implementations may parse this prototype when the axis type alone is not suffisient. For example the time axis type should uses the "yyyy-MM-dd" date pattern, but some files do not follow this convention and use the default local instead.
Returns:
The format for parsing values along the axis.

forcePacking

protected boolean forcePacking(java.lang.String attribute)
Returns true if an attribute (usually the valid range) should be converted from unpacked to packed units. The CF Metadata conventions states that valid ranges should be in packed units, but not every NetCDF files follow this advice in practice. The UCAR NetCDF library applies the following heuristic rules (quoting from EnhanceScaleMissing):
If valid_range is the same type as scale_factor (actually the wider of scale_factor and add_offset) and this is wider than the external data, then it will be interpreted as being in the units of the internal (unpacked) data. Otherwise it is in the units of the external (packed) data.
However some NetCDF files stores unpacked ranges using the same type than packed data. The above cited heuristic rule can not resolve those cases.

If this method returns true, then the attribute is assumed in unpacked units no matter what the CF convention and the heuristic rules said. If this method returns false, then UCAR's heuristic rules applies.

The default implementation returns false in all cases.

Parameters:
attribute - The attribute (usually "valid_range").
Returns:
true if the attribute should be converted from unpacked to packed units regardless CF convention and UCAR's heuristic rules.
See Also:
EnhanceScaleMissing


Copyright © 1996-2010 Geotools. All Rights Reserved.