org.geotools.coverage.io
Class MetadataBuilder

java.lang.Object
  extended byorg.geotools.coverage.io.MetadataBuilder

public class MetadataBuilder
extends java.lang.Object

Helper class for creating OpenGIS's object from a set of metadata. Metadata are key-value pairs, for example . There is a wide variety of ways to contruct OpenGIS's objects from key-value pairs, and supporting them is not always straightforward. The class tries to make the work easier. It defines a set of format-neutral keys (i.e. keys not related to any specific file format). Before parsing a file, the mapping between format-neutral keys and "real" keys used in a particuler file format must be specified. This mapping is constructed with calls to addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String). For example, one may want to parse the following informations:

 XMinimum           = 217904.31
 YMaximum           = 5663495.1
 XResolution        = 1000.0000
 YResolution        = 1000.0000
 Units              = meters
 Projection         = Mercator_1SP
 Central meridian   = -15.2167
 Latitude of origin =  28.0667
 False easting      = 0.00000000
 False northing     = 0.00000000
 Ellipsoid          = Clarke 1866
 Datum              = Clarke 1866
 
Before to be used for parsing such informations, a object must be setup using the following code:
 addAlias(X_MINIMUM,    "XMinimum");
 addAlias(Y_MAXIMUM,    "YMaximum");
 addAlias(X_RESOLUTION, "XResolution");
 addAlias(Y_RESOLUTION, "YResolution");
 // etc...
 
Once the mapping is etablished, provides a set of methods for constructing various objects from those informations. For example, the getCoordinateReferenceSystem() method constructs a CoordinateReferenceSystem object using available informations.

Since:
2.2
Version:
$Id: MetadataBuilder.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Nested Class Summary
static class MetadataBuilder.Key
          A key for fetching metadata in a format independent way.
 
Field Summary
static MetadataBuilder.Key CENTRAL_MERIDIAN
          Key for the projection parameter.
static MetadataBuilder.Key COORDINATE_REFERENCE_SYSTEM
          Key for the coordinate reference system.
static MetadataBuilder.Key DATUM
          Key for the coordinate reference system's datum.
static MetadataBuilder.Key DEPTH
          Key for the image's "depth" in pixels.
static MetadataBuilder.Key ELLIPSOID
          Key for the coordinate reference system ellipsoid.
static MetadataBuilder.Key FALSE_EASTING
          Key for the projection parameter.
static MetadataBuilder.Key FALSE_NORTHING
          Key for the projection parameter.
static MetadataBuilder.Key HEIGHT
          Key for the image's height in pixels.
static MetadataBuilder.Key LATITUDE_OF_ORIGIN
          Key for the projection parameter.
static MetadataBuilder.Key OPERATION_METHOD
          Key for the operation method.
static MetadataBuilder.Key PROJECTION
          Key for the projection.
static MetadataBuilder.Key SEMI_MAJOR
          Key for the projection parameter.
static MetadataBuilder.Key SEMI_MINOR
          Key for the projection parameter.
static MetadataBuilder.Key UNITS
          Key for the coordinate system axis units.
static MetadataBuilder.Key WIDTH
          Key for the image's width in pixels.
static MetadataBuilder.Key X_MAXIMUM
          Key for the maximal x value (eastern limit).
static MetadataBuilder.Key X_MINIMUM
          Key for the minimal x value (western limit).
static MetadataBuilder.Key X_RESOLUTION
          Key for the resolution among the x axis.
static MetadataBuilder.Key Y_MAXIMUM
          Key for the maximal y value (northern limit).
static MetadataBuilder.Key Y_MINIMUM
          Key for the minimal y value (southern limit).
static MetadataBuilder.Key Y_RESOLUTION
          Key for the resolution among the y axis.
static MetadataBuilder.Key Z_MAXIMUM
          Key for the maximal z value.
static MetadataBuilder.Key Z_MINIMUM
          Key for the minimal z value.
static MetadataBuilder.Key Z_RESOLUTION
          Key for the resolution among the z axis.
 
Constructor Summary
MetadataBuilder()
          Constructs a new using default factories.
MetadataBuilder(FactoryGroup factories)
          Constructs a new using the specified factories.
 
Method Summary
 void add(org.opengis.coverage.grid.GridCoverage coverage)
          Add all metadata from the specified grid coverage.
 void add(javax.media.jai.PropertySource properties, java.lang.String prefix)
          Add metadata from the specified property source.
 void add(java.awt.image.RenderedImage image)
          Add all metadata from the specified image.
 void add(java.lang.String alias, java.lang.Object value)
          Add a metadata for the specified key.
 void addAlias(MetadataBuilder.Key key, java.lang.String alias)
          Add an alias to a key.
 void clear()
          Clears this metadata set.
 boolean contains(MetadataBuilder.Key key)
          Checks if this contains a value for the specified key.
 java.lang.Object get(MetadataBuilder.Key key)
          Returns the metadata for the specified key.
 java.lang.String[] getAlias(MetadataBuilder.Key key)
          Returns the list of alias for the specified key, or if the key has no alias.
 java.util.Date getAsDate(MetadataBuilder.Key key)
          Returns a metadata as a Date value.
 double getAsDouble(MetadataBuilder.Key key)
          Returns a metadata as a value.
 int getAsInt(MetadataBuilder.Key key)
          Returns a metadata as a value.
 org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()
          Returns the coordinate reference system.
 org.opengis.referencing.datum.Ellipsoid getEllipsoid()
          Returns the ellipsoid.
 org.opengis.spatialschema.geometry.Envelope getEnvelope()
          Returns the envelope.
 java.lang.String getFormatPattern(java.lang.Class type)
          Returns the pattern used for parsing and formatting values of the specified type.
 org.opengis.referencing.datum.GeodeticDatum getGeodeticDatum()
          Returns the geodetic datum.
 org.opengis.metadata.extent.GeographicBoundingBox getGeographicBoundingBox()
          Convenience method returning the envelope in geographic coordinate system using WGS 1984 datum.
 org.opengis.coverage.grid.GridRange getGridRange()
          Returns the grid range.
 java.util.Locale getLocale()
          Returns the locale to use when parsing metadata values as numbers, angles or dates.
 org.opengis.referencing.operation.Conversion getProjection()
          Returns the projection.
 org.opengis.coverage.SampleDimension[] getSampleDimensions()
          Returns the sample dimensions for each band of the GridCoverage to be read.
 java.lang.String getSeparator()
          Returns the characters to use as separator between keys and values.
 java.lang.String getSource()
          Returns the source file name or URL.
 javax.units.Unit getUnit()
          Returns the units.
 void listMetadata(java.io.Writer out)
          List all metadata to the specified stream.
protected  void load(java.io.BufferedReader in)
          Reads all metadata from a stream.
 void load(java.io.File header)
          Reads all metadata from a text file.
 void load(java.net.URL header)
          Reads all metadata from an URL.
protected  boolean parseLine(java.lang.String line)
          Parses a line and add the key-value pair to this metadata set.
 void setFormatPattern(java.lang.Class type, java.lang.String pattern)
          Set the pattern to use for parsing and formatting values of the specified type.
 void setSeparator(java.lang.String separator)
          Set the characters to use as separator between keys and values.
 java.lang.String toString()
          Returns a string representation of this metadata set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COORDINATE_REFERENCE_SYSTEM

public static final MetadataBuilder.Key COORDINATE_REFERENCE_SYSTEM
Key for the coordinate reference system. The getCoordinateReferenceSystem() method looks for this metadata.

See Also:
UNITS, DATUM, PROJECTION

UNITS

public static final MetadataBuilder.Key UNITS
Key for the coordinate system axis units. The getUnit() method looks for this metadata. The following heuristic rule may be applied in order to infer the CRS from the units:

See Also:
ELLIPSOID, DATUM, PROJECTION, COORDINATE_REFERENCE_SYSTEM

DATUM

public static final MetadataBuilder.Key DATUM
Key for the coordinate reference system's datum. The getGeodeticDatum() method looks for this metadata.

See Also:
UNITS, ELLIPSOID, PROJECTION, COORDINATE_REFERENCE_SYSTEM

ELLIPSOID

public static final MetadataBuilder.Key ELLIPSOID
Key for the coordinate reference system ellipsoid. The getEllipsoid() method looks for this metadata.

See Also:
UNITS, DATUM, PROJECTION, COORDINATE_REFERENCE_SYSTEM

OPERATION_METHOD

public static final MetadataBuilder.Key OPERATION_METHOD
Key for the operation method. The getProjection() method looks for this metadata. The operation method name determines the math transform implementation and its list of parameters. This name is the projection classification.

If this metadata is not defined, then the operation name is inferred from the projection name.

See Also:
PROJECTION, COORDINATE_REFERENCE_SYSTEM

PROJECTION

public static final MetadataBuilder.Key PROJECTION
Key for the projection. The getProjection() method looks for this metadata. If the metadata is not defined, then the projection name is assumed the same than the operation method name.

See Also:
SEMI_MAJOR, SEMI_MINOR, LATITUDE_OF_ORIGIN, CENTRAL_MERIDIAN, FALSE_EASTING, FALSE_NORTHING

SEMI_MAJOR

public static final MetadataBuilder.Key SEMI_MAJOR
Key for the projection parameter. There is no specific method for this key. However, this key may be queried indirectly by getProjection().

See Also:
SEMI_MINOR, LATITUDE_OF_ORIGIN, CENTRAL_MERIDIAN, FALSE_EASTING, FALSE_NORTHING, PROJECTION

SEMI_MINOR

public static final MetadataBuilder.Key SEMI_MINOR
Key for the projection parameter. There is no specific method for this key. However, this key may be queried indirectly by getProjection().

See Also:
SEMI_MAJOR, LATITUDE_OF_ORIGIN, CENTRAL_MERIDIAN, FALSE_EASTING, FALSE_NORTHING, PROJECTION

LATITUDE_OF_ORIGIN

public static final MetadataBuilder.Key LATITUDE_OF_ORIGIN
Key for the projection parameter. There is no specific method for this key. However, this key may be queried indirectly by getProjection().

See Also:
SEMI_MAJOR, SEMI_MINOR, CENTRAL_MERIDIAN, FALSE_EASTING, FALSE_NORTHING, PROJECTION

CENTRAL_MERIDIAN

public static final MetadataBuilder.Key CENTRAL_MERIDIAN
Key for the projection parameter. There is no specific method for this key. However, this key may be queried indirectly by getProjection().

See Also:
SEMI_MAJOR, SEMI_MINOR, LATITUDE_OF_ORIGIN, FALSE_EASTING, FALSE_NORTHING, PROJECTION

FALSE_EASTING

public static final MetadataBuilder.Key FALSE_EASTING
Key for the projection parameter. There is no specific method for this key. However, this key may be queried indirectly by getProjection().

See Also:
SEMI_MAJOR, SEMI_MINOR, LATITUDE_OF_ORIGIN, CENTRAL_MERIDIAN, FALSE_NORTHING, PROJECTION

FALSE_NORTHING

public static final MetadataBuilder.Key FALSE_NORTHING
Key for the projection parameter. There is no specific method for this key. However, this key may be queried indirectly by getProjection().

See Also:
SEMI_MAJOR, SEMI_MINOR, LATITUDE_OF_ORIGIN, CENTRAL_MERIDIAN, FALSE_EASTING, PROJECTION

X_MINIMUM

public static final MetadataBuilder.Key X_MINIMUM
Key for the minimal x value (western limit). This is usually the longitude coordinate of the upper left corner. The getEnvelope() method looks for this metadata in order to set the minimal coordinate for dimension 0.

See Also:
X_MAXIMUM, Y_MINIMUM, Y_MAXIMUM, X_RESOLUTION, Y_RESOLUTION

Y_MINIMUM

public static final MetadataBuilder.Key Y_MINIMUM
Key for the minimal y value (southern limit). This is usually the latitude coordinate of the bottom right corner. The getEnvelope() method looks for this metadata. in order to set the minimal coordinate for dimension 1.

See Also:
X_MINIMUM, X_MAXIMUM, Y_MAXIMUM, X_RESOLUTION, Y_RESOLUTION

Z_MINIMUM

public static final MetadataBuilder.Key Z_MINIMUM
Key for the minimal z value. This is usually the minimal altitude. The getEnvelope() method looks for this metadata in order to set the minimal coordinate for dimension 2.

See Also:
Z_MAXIMUM, Z_RESOLUTION, DEPTH

X_MAXIMUM

public static final MetadataBuilder.Key X_MAXIMUM
Key for the maximal x value (eastern limit). This is usually the longitude coordinate of the bottom right corner. The getEnvelope() method looks for this metadata in order to set the maximal coordinate for dimension 0.

See Also:
X_MINIMUM, Y_MINIMUM, Y_MAXIMUM, X_RESOLUTION, Y_RESOLUTION

Y_MAXIMUM

public static final MetadataBuilder.Key Y_MAXIMUM
Key for the maximal y value (northern limit). This is usually the latitude coordinate of the upper left corner. The getEnvelope() method looks for this metadata in order to set the maximal coordinate for dimension 1.

See Also:
X_MINIMUM, X_MAXIMUM, Y_MINIMUM, X_RESOLUTION, Y_RESOLUTION

Z_MAXIMUM

public static final MetadataBuilder.Key Z_MAXIMUM
Key for the maximal z value. This is usually the maximal altitude. The getEnvelope() method looks for this metadata in order to set the maximal coordinate for dimension 2.

See Also:
Z_MINIMUM, Z_RESOLUTION, DEPTH

X_RESOLUTION

public static final MetadataBuilder.Key X_RESOLUTION
Key for the resolution among the x axis. The getEnvelope() method looks for this metadata in order to infer the coordinates for dimension 0.

See Also:
X_MINIMUM, X_MAXIMUM, Y_MINIMUM, Y_MAXIMUM, Y_RESOLUTION

Y_RESOLUTION

public static final MetadataBuilder.Key Y_RESOLUTION
Key for the resolution among the y axis. The getEnvelope() method looks for this metadata in order to infer the coordinates for dimension 1.

See Also:
X_MINIMUM, X_MAXIMUM, Y_MINIMUM, Y_MAXIMUM, X_RESOLUTION, WIDTH, HEIGHT

Z_RESOLUTION

public static final MetadataBuilder.Key Z_RESOLUTION
Key for the resolution among the z axis. The getEnvelope() method looks for this metadata in order to infer the coordinates for dimension 2.

See Also:
Z_MINIMUM, Z_MAXIMUM, DEPTH

WIDTH

public static final MetadataBuilder.Key WIDTH
Key for the image's width in pixels. The getGridRange() method looks for this metadata in order to infer the grid size along the dimension 0.

See Also:
HEIGHT, X_RESOLUTION, Y_RESOLUTION

HEIGHT

public static final MetadataBuilder.Key HEIGHT
Key for the image's height in pixels. The getGridRange() method looks for this metadata in order to infer the grid size along the dimension 1.

See Also:
WIDTH, X_RESOLUTION, Y_RESOLUTION

DEPTH

public static final MetadataBuilder.Key DEPTH
Key for the image's "depth" in pixels. This metadata may exists for 3D images, but some implementations accept at most 1 pixel depth among the third dimension. The getGridRange() method looks for this metadata in order to infer the grid size along the dimension 2.

See Also:
Z_MINIMUM, Z_MAXIMUM, Z_RESOLUTION
Constructor Detail

MetadataBuilder

public MetadataBuilder()
Constructs a new using default factories.


MetadataBuilder

public MetadataBuilder(FactoryGroup factories)
Constructs a new using the specified factories.

Method Detail

getSeparator

public java.lang.String getSeparator()
Returns the characters to use as separator between keys and values. Leading and trailing spaces will be keept when formatting with listMetadata(java.io.Writer), but will be ignored when parsing with parseLine(java.lang.String). The default value is " = ".


setSeparator

public void setSeparator(java.lang.String separator)
Set the characters to use as separator between keys and values.


getFormatPattern

public java.lang.String getFormatPattern(java.lang.Class type)
Returns the pattern used for parsing and formatting values of the specified type. The type should be either or .

In any case, this method returns if this object should use the default pattern for the data locale.

Parameters:
type - The data type ( or ).
Returns:
The format pattern for the specified data type, or for the default locale-dependent pattern.
Throws:
IllegalArgumentException - if is not valid.

setFormatPattern

public void setFormatPattern(java.lang.Class type,
                             java.lang.String pattern)
Set the pattern to use for parsing and formatting values of the specified type. The type should be either or .

Parameters:
type - The data type ( or ).
pattern - The format pattern for the specified data type, or for the default locale-dependent pattern.
Throws:
IllegalArgumentException - if is not valid.

clear

public void clear()
Clears this metadata set. If the same object is used for parsing many files, then should be invoked prior any method. Note that do not remove any alias, so this can been immediately reused for parsing new files of the same kind.


load

public void load(java.io.File header)
          throws java.io.IOException
Reads all metadata from a text file. The default implementation invokes load(BufferedReader). Note that this method do not invokes clear() prior the loading. Consequently, the loaded metadata will be added to the set of existing metadata.

Parameters:
header - The file to read until EOF.
Throws:
IOException - if an error occurs during loading.
See Also:
clear(), load(URL), parseLine(java.lang.String), getSource()

load

public void load(java.net.URL header)
          throws java.io.IOException
Reads all metadata from an URL. The default implementation invokes load(BufferedReader). Note that this method do not invokes clear() prior the loading. Consequently, the loaded metadata will be added to the set of existing metadata.

Parameters:
header - The URL to read until EOF.
Throws:
IOException - if an error occurs during loading.
See Also:
clear(), load(File), parseLine(java.lang.String), getSource()

load

protected void load(java.io.BufferedReader in)
             throws java.io.IOException
Reads all metadata from a stream. The default implementation invokes parseLine(java.lang.String) for each non-empty line found in the stream. Notes:

Parameters:
in - The stream to read until EOF. The stream will not be closed.
Throws:
IOException - if an error occurs during loading.
See Also:
clear(), load(File), load(URL), parseLine(java.lang.String)

parseLine

protected boolean parseLine(java.lang.String line)
                     throws javax.imageio.IIOException
Parses a line and add the key-value pair to this metadata set. The default implementation takes the substring on the left side of the first occurence of the separator (usually the '=' character) as the key, and the substring on the right side of the separator as the value. For example, if has the following value:
 Ellipsoid = WGS 1984
 
Then, the default implementation will translate this line in the following call:
 add("Ellipsoid", "WGS 1984");
 
This method returns if it has consumed the line, or otherwise. A line is "consumed" if has either added the key-value pair (using add(org.opengis.coverage.grid.GridCoverage)), or determined that the line must be ignored (for example because detected a character announcing a comment line). A "consumed" line will not receive any further treatment. The line is not consumed (i.e. this method returns ) if don't know what to do with it. Non-consumed line will typically go up in a chain of methods (if has been subclassed) until someone consume it.

Parameters:
line - The line to parse.
Returns:
if this method has consumed the line.
Throws:
IIOException - if the line is badly formatted.
AmbiguousMetadataException - if a different value was already defined for the same metadata name.
See Also:
load(File), load(URL), add(String,Object)

add

public void add(org.opengis.coverage.grid.GridCoverage coverage)
         throws AmbiguousMetadataException
Add all metadata from the specified grid coverage. This method can be used together with listMetadata(java.io.Writer) as a way to format the metadata for an arbitrary grid coverage. The default implementation performs the following step:


add

public void add(java.awt.image.RenderedImage image)
         throws AmbiguousMetadataException
Add all metadata from the specified image.

Parameters:
image - The image with metadata to add to this .
Throws:
AmbiguousMetadataException - if a metadata is defined twice.
See Also:
add(GridCoverage), add(PropertySource,String), add(String,Object)

add

public void add(javax.media.jai.PropertySource properties,
                java.lang.String prefix)
         throws AmbiguousMetadataException
Add metadata from the specified property source.

Parameters:
properties - The properties source.
prefix - The prefix for properties to add, of to add all properties. If non-null, only properties begining with this prefix will be added.
Throws:
AmbiguousMetadataException - if a metadata is defined twice.
See Also:
add(GridCoverage), add(RenderedImage), add(String,Object)

add

public void add(java.lang.String alias,
                java.lang.Object value)
         throws AmbiguousMetadataException
Add a metadata for the specified key. Keys are case-insensitive, ignore leading and trailing whitespaces and consider any other whitespace sequences as equal to a single character.

Parameters:
alias - The key for the metadata to add. This is usually the name found in the file to be parsed (this is different from MetadataBuilder.Key objects, which are keys in a format neutral way). This key is usually, but not always, one of the alias defined with addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String).
value - The value for the metadata to add. If or Image#UndefinedProperty, then this method do nothing.
Throws:
AmbiguousMetadataException - if a different value already exists for the specified alias, or for an other alias bound to the same MetadataBuilder.Key.
See Also:
add(GridCoverage), add(RenderedImage), add(PropertySource,String), parseLine(java.lang.String)

addAlias

public void addAlias(MetadataBuilder.Key key,
                     java.lang.String alias)
              throws AmbiguousMetadataException
Add an alias to a key. After this method has been invoked, calls to get(key) will really looks for metadata named . Alias are mandatory in order to get various methods to work for a particular file format.

For example if the file to be parsed uses the names and for the coordinate of the upper left corner, then the getEnvelope() method will not work unless the following alias are set:

 addAlias(X_MINIMUM, "ULX");
 addAlias(Y_MAXIMUM, "ULY");
 
An arbitrary number of alias can be set for the same key. For example, addAlias(Y_MAXIMUM, ...) could be invoked twice with and alias. The methods will try alias in the order they were added and use the first value found.

The same alias can also be set to more than one key. For example, the following code is legal. It means that pixel are square with the same horizontal and vertical resolution:

 addAlias(X_RESOLUTION, "Resolution");
 addAlias(Y_RESOLUTION, "Resolution");
 

Parameters:
key - The key to add an alias. This key is format neutral.
alias - The alias to add. This is the name actually used in the file to be parsed. Alias are case insensitive and ignore multiple whitespace, like keys. If this alias is already bound to the specified key, then this method do nothing.
Throws:
AmbiguousMetadataException - if the addition of the supplied alias would introduce an ambiguity in the current set of metadata. This occurs if the key has already an alias mapping to a different value.
See Also:
getAlias(org.geotools.coverage.io.MetadataBuilder.Key), contains(org.geotools.coverage.io.MetadataBuilder.Key), get(org.geotools.coverage.io.MetadataBuilder.Key)

contains

public boolean contains(MetadataBuilder.Key key)
Checks if this contains a value for the specified key. Invoking get(org.geotools.coverage.io.MetadataBuilder.Key) will thrown a MissingMetadataException if and only if contains(org.geotools.coverage.io.MetadataBuilder.Key) returns for the same key.

Parameters:
key - The key to test for inclusion in this .
Returns:
if the given key was found.
See Also:
get(org.geotools.coverage.io.MetadataBuilder.Key), addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String)

get

public java.lang.Object get(MetadataBuilder.Key key)
                     throws MissingMetadataException
Returns the metadata for the specified key. This method expect a format neutral, case insensitive MetadataBuilder.Key argument. In order to maps the key to the actual name used in the underlying metadata file, the method addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String) must have been invoked prior to any method.

Parameters:
key - The key of the desired metadata. Keys are case insensitive and format neutral.
Returns:
Value for the specified key (never ).
Throws:
MissingMetadataException - if no value exists for the specified key.
See Also:
getAsDouble(org.geotools.coverage.io.MetadataBuilder.Key), getAsInt(org.geotools.coverage.io.MetadataBuilder.Key), contains(org.geotools.coverage.io.MetadataBuilder.Key), addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String)

getAsDouble

public double getAsDouble(MetadataBuilder.Key key)
                   throws MetadataException
Returns a metadata as a value. The default implementation invokes get(key) and parse the resulting value with NumberFormat#parse(String) for the current locale.

Parameters:
key - The key of the desired metadata. Keys are case-insensitive.
Returns:
Value for the specified key as a .
Throws:
MissingMetadataException - if no value exists for the specified key.
MetadataException - if the value can't be parsed as a .
See Also:
getAsInt(org.geotools.coverage.io.MetadataBuilder.Key), get(org.geotools.coverage.io.MetadataBuilder.Key), contains(org.geotools.coverage.io.MetadataBuilder.Key), addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String)

getAsInt

public int getAsInt(MetadataBuilder.Key key)
             throws MetadataException
Returns a metadata as a value. The default implementation invokes getAsDouble(key) and make sure that the resulting value is an integer.

Parameters:
key - The key of the desired metadata. Keys are case-insensitive.
Returns:
Value for the specified key as an .
Throws:
MissingMetadataException - if no value exists for the specified key.
MetadataException - if the value can't be parsed as an .
See Also:
getAsDouble(org.geotools.coverage.io.MetadataBuilder.Key), get(org.geotools.coverage.io.MetadataBuilder.Key), contains(org.geotools.coverage.io.MetadataBuilder.Key), addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String)

getAsDate

public java.util.Date getAsDate(MetadataBuilder.Key key)
                         throws MetadataException
Returns a metadata as a Date value. The default implementation invokes get(key) and parse the resulting value with DateFormat#parse(String) for the current locale.

Parameters:
key - The key of the desired metadata. Keys are case-insensitive.
Returns:
Value for the specified key as a Date.
Throws:
MissingMetadataException - if no value exists for the specified key.
MetadataException - if the value can't be parsed as a date.

getAlias

public java.lang.String[] getAlias(MetadataBuilder.Key key)
Returns the list of alias for the specified key, or if the key has no alias. Alias are the names used in the underlying metadata file, and are format dependent.

Parameters:
key - The format neutral key.
Returns:
The alias for the specified key, or if none.
See Also:
addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String)

getSource

public java.lang.String getSource()
                           throws MetadataException
Returns the source file name or URL. This is the path specified during the last call to a method.

Returns:
The source file name or URL.
Throws:
MetadataException - if this information can't be fetched.

getLocale

public java.util.Locale getLocale()
                           throws MetadataException
Returns the locale to use when parsing metadata values as numbers, angles or dates. This is not the locale used for formatting error messages, if any. The default implementation returns Locale#US, since it is the format used in most data file.

Returns:
The locale to use for parsing metadata values.
Throws:
MetadataException - if this information can't be fetched.
See Also:
getAsDouble(org.geotools.coverage.io.MetadataBuilder.Key), getAsInt(org.geotools.coverage.io.MetadataBuilder.Key), getAsDate(org.geotools.coverage.io.MetadataBuilder.Key)

getUnit

public javax.units.Unit getUnit()
                         throws MetadataException
Returns the units. The default implementation invokes get(UNITS) and transform the resulting string into an Unit object.

Throws:
MissingMetadataException - if no value exists for the UNITS key.
MetadataException - if the operation failed for some other reason.
See Also:
getCoordinateReferenceSystem()

getGeodeticDatum

public org.opengis.referencing.datum.GeodeticDatum getGeodeticDatum()
                                                             throws MetadataException
Returns the geodetic datum. The default implementation invokes get(DATUM) and transform the resulting string into a GeodeticDatum object.

Throws:
MissingMetadataException - if no value exists for the DATUM key.
MetadataException - if the operation failed for some other reason.
See Also:
getCoordinateReferenceSystem(), getEllipsoid()

getEllipsoid

public org.opengis.referencing.datum.Ellipsoid getEllipsoid()
                                                     throws MetadataException
Returns the ellipsoid. The default implementation invokes get(ELLIPSOID) and transform the resulting string into an Ellipsoid object.

Throws:
MissingMetadataException - if no value exists for the ELLIPSOID key.
MetadataException - if the operation failed for some other reason.
See Also:
getCoordinateReferenceSystem(), getGeodeticDatum()

getProjection

public org.opengis.referencing.operation.Conversion getProjection()
                                                           throws MetadataException
Returns the projection. The default implementation performs the following steps:

Returns:
The projection.
Throws:
MissingMetadataException - if no value exists for the PROJECTION or the OPERATION_METHOD keys.
MetadataException - if the operation failed for some other reason (for example if a parameter value can't be parsed as a ).
See Also:
getCoordinateReferenceSystem(), SEMI_MAJOR, SEMI_MINOR, LATITUDE_OF_ORIGIN, CENTRAL_MERIDIAN, FALSE_EASTING, FALSE_NORTHING

getCoordinateReferenceSystem

public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()
                                                                                   throws MetadataException
Returns the coordinate reference system. The default implementation constructs a CRS from the information provided by getUnit(), getGeodeticDatum() and getProjection(). The coordinate system name (optional) will be fetch from metadata COORDINATE_REFERENCE_SYSTEM, if presents as a string.

Throws:
MissingMetadataException - if a required value is missing (e.g. PROJECTION, DATUM, UNITS, etc.).
MetadataException - if the operation failed for some other reason.
See Also:
getUnit(), getGeodeticDatum(), getProjection()

getGeographicBoundingBox

public org.opengis.metadata.extent.GeographicBoundingBox getGeographicBoundingBox()
                                                                           throws MetadataException
Convenience method returning the envelope in geographic coordinate system using WGS 1984 datum.

Throws:
MetadataException - if the operation failed. This exception may contains a TransformException as its cause.
See Also:
getEnvelope(), getGridRange()

getEnvelope

public org.opengis.spatialschema.geometry.Envelope getEnvelope()
                                                        throws MetadataException
Returns the envelope. The default implementation constructs an envelope using the values from the following keys:

Throws:
MissingMetadataException - if a required value is missing.
MetadataException - if the operation failed for some other reason.
See Also:
getGridRange(), getGeographicBoundingBox()

getGridRange

public org.opengis.coverage.grid.GridRange getGridRange()
                                                 throws MetadataException
Returns the grid range. Default implementation fetchs the metadata values for keys WIDTH and HEIGHT, and transform the resulting strings into a GridRange object.

Throws:
MissingMetadataException - if a required value is missing.
MetadataException - if the operation failed for some other reason.
See Also:
getEnvelope(), getGeographicBoundingBox()

getSampleDimensions

public org.opengis.coverage.SampleDimension[] getSampleDimensions()
                                                           throws MetadataException
Returns the sample dimensions for each band of the GridCoverage to be read. If sample dimensions are not know, then this method returns . The default implementation always returns .

Throws:
MetadataException - if the operation failed.

listMetadata

public void listMetadata(java.io.Writer out)
                  throws java.io.IOException
List all metadata to the specified stream. The default implementation list the metadata as key = value pairs. Each pair is formatted on its own line, and the caracter '=' is inserted between keys and values. A question mark ('?') is put in front of any unknow name (i.e. any name not specified with addAlias(org.geotools.coverage.io.MetadataBuilder.Key, java.lang.String)).

Parameters:
out - Stream to write metadata to.
Throws:
IOException - if an error occured while listing metadata.
See Also:
add(GridCoverage), toString()

toString

public java.lang.String toString()
Returns a string representation of this metadata set. The default implementation write the class name and the envelope in geographic coordinates, as returned by getGeographicBoundingBox(). Then, it append the list of all metadata as formatted by listMetadata(java.io.Writer).



Copyright © GeoTools. All Rights Reserved.