|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.geotools.image.io.text.TextMetadataParser
public abstract class TextMetadataParser
Helper class for creating OpenGIS's object from a set of metadata. Metadata are
key-value pairs, for example "Units=meters"
. There is a wide
variety of ways to contruct OpenGIS's objects from key-value pairs, and
supporting them is not always straightforward. The MetadataReader
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.image.io.text.TextMetadataParser.Key, java.lang.String)
. For example,
one may want to parse the following informations:
Before to be used for parsing such informations, aXMinimum = 217904.31 YMaximum = 5663495.1 XResolution = 1000.0000 YResolution = 1000.0000 Unit = 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
MetadataReader
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...
Nested Class Summary | |
---|---|
static class |
TextMetadataParser.Key
A key for fetching metadata in a format independent way. |
Field Summary | |
---|---|
static TextMetadataParser.Key |
CENTRAL_MERIDIAN
Key for the "central_meridian" projection parameter. |
static TextMetadataParser.Key |
COORDINATE_REFERENCE_SYSTEM
Key for the coordinate reference system. |
static TextMetadataParser.Key |
COORDINATE_REFERENCE_SYSTEM_TYPE
Key for the coordinate reference system type. |
static TextMetadataParser.Key |
COORDINATE_SYSTEM
Key for the coordinate system. |
static TextMetadataParser.Key |
COORDINATE_SYSTEM_TYPE
Key for the coordinate system type. |
static TextMetadataParser.Key |
DATUM
Key for the coordinate reference system's datum. |
static TextMetadataParser.Key |
DATUM_TYPE
|
static TextMetadataParser.Key |
DEPTH
Key for the image's "depth" in pixels. |
static TextMetadataParser.Key |
ELLIPSOID
Key for the coordinate reference system ellipsoid. |
static TextMetadataParser.Key |
ELLIPSOID_UNIT
The unit of the ellipsoid. |
static TextMetadataParser.Key |
FALSE_EASTING
Key for the "false_easting" projection parameter. |
static TextMetadataParser.Key |
FALSE_NORTHING
Key for the "false_northing" projection parameter. |
static TextMetadataParser.Key |
GREENWICH_LONGITUDE
Key for the "greenwich_longitude" parameter. |
static TextMetadataParser.Key |
HEIGHT
Key for the image's height in pixels. |
static TextMetadataParser.Key |
INVERSE_FLATTENING
Key for the "inverse_flattening" ellipsoid parameter. |
static TextMetadataParser.Key |
LATITUDE_OF_ORIGIN
Key for the "latitude_of_origin" projection parameter. |
protected GeographicMetadata |
metadata
The geogrpahic metadata to consider. |
static TextMetadataParser.Key |
OPERATION_METHOD
Key for the operation method. |
static TextMetadataParser.Key |
PRIME_MERIDIAN
Key for the "prime_meridian" name parameter. |
static TextMetadataParser.Key |
PROJECTION
Key for the projection. |
static TextMetadataParser.Key |
SEMI_MAJOR
Key for the "semi_major" ellipsoid parameter. |
static TextMetadataParser.Key |
SEMI_MINOR
Key for the "semi_minor" ellipsoid parameter. |
static TextMetadataParser.Key |
UNIT
Key for the coordinate system axis units. |
static TextMetadataParser.Key |
WIDTH
Key for the image's width in pixels. |
static TextMetadataParser.Key |
X_DIRECTION
Key for the direction among the x axis. |
static TextMetadataParser.Key |
X_MAXIMUM
Key for the maximal x value (eastern limit). |
static TextMetadataParser.Key |
X_MINIMUM
Key for the minimal x value (western limit). |
static TextMetadataParser.Key |
X_RESOLUTION
Key for the resolution among the x axis. |
static TextMetadataParser.Key |
Y_DIRECTION
Key for the direction among the y axis. |
static TextMetadataParser.Key |
Y_MAXIMUM
Key for the maximal y value (northern limit). |
static TextMetadataParser.Key |
Y_MINIMUM
Key for the minimal y value (southern limit). |
static TextMetadataParser.Key |
Y_RESOLUTION
Key for the resolution among the y axis. |
static TextMetadataParser.Key |
Z_DIRECTION
Key for the direction among the z axis. |
static TextMetadataParser.Key |
Z_MAXIMUM
Key for the maximal z value. |
static TextMetadataParser.Key |
Z_MINIMUM
Key for the minimal z value. |
static TextMetadataParser.Key |
Z_RESOLUTION
Key for the resolution among the z axis. |
Constructor Summary | |
---|---|
TextMetadataParser()
Constructs a new MetadataReader using default factories. |
|
TextMetadataParser(ReferencingFactoryContainer factories)
Constructs a new MetadataReader using the specified factories. |
Method Summary | |
---|---|
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(TextMetadataParser.Key key,
java.lang.String alias)
Add an alias to a key. |
void |
clear()
Clears this metadata set. |
java.util.Set<java.lang.String> |
getAlias(TextMetadataParser.Key key)
Returns the list of alias for the specified key, or null
if the key has no alias. |
java.lang.String |
getFormatPattern(java.lang.Class<?> type)
Returns the pattern used for parsing and formatting values of the specified type. |
protected GeographicMetadata |
getGeographicMetadata()
|
java.util.Locale |
getLocale()
Returns the locale to use when parsing metadata values as numbers, angles or dates. |
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. |
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. |
protected abstract void |
put(TextMetadataParser.Key key,
java.lang.Object value)
Put the specified value in the right node of the metadata tree. |
protected abstract void |
putDone()
Should be launched after the put(Key, Object) method has been done. |
void |
setFormatPattern(java.lang.Class<?> type,
java.lang.String pattern)
Set the pattern to use for parsing and formatting values of the specified type. |
protected void |
setGeographicMetadata(GeographicMetadata metadata)
|
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 |
---|
protected GeographicMetadata metadata
public static final TextMetadataParser.Key COORDINATE_REFERENCE_SYSTEM
MetadataReader.getCoordinateReferenceSystem()
method looks for this
metadata.
UNIT
,
DATUM
,
PROJECTION
public static final TextMetadataParser.Key COORDINATE_REFERENCE_SYSTEM_TYPE
UNIT
,
DATUM
,
PROJECTION
public static final TextMetadataParser.Key COORDINATE_SYSTEM
MetadataReader.getCoordinateSystem()
method looks for this
metadata.
UNIT
,
DATUM
,
PROJECTION
public static final TextMetadataParser.Key COORDINATE_SYSTEM_TYPE
UNIT
,
DATUM
,
PROJECTION
public static final TextMetadataParser.Key UNIT
MetadataReader.getUnit(java.lang.String)
method looks for this metadata. The following
heuristic rule may be applied in order to infer the CRS from the units:
ELLIPSOID
,
DATUM
,
PROJECTION
,
COORDINATE_REFERENCE_SYSTEM
public static final TextMetadataParser.Key DATUM
MetadataReader.getDatum()
method looks for this metadata.
UNIT
,
ELLIPSOID
,
PROJECTION
,
COORDINATE_REFERENCE_SYSTEM
public static final TextMetadataParser.Key DATUM_TYPE
public static final TextMetadataParser.Key ELLIPSOID
MetadataReader.getEllipsoid()
method looks for this metadata.
UNIT
,
DATUM
,
PROJECTION
,
COORDINATE_REFERENCE_SYSTEM
public static final TextMetadataParser.Key ELLIPSOID_UNIT
public static final TextMetadataParser.Key OPERATION_METHOD
MetadataReader.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.
PROJECTION
,
COORDINATE_REFERENCE_SYSTEM
public static final TextMetadataParser.Key PROJECTION
MetadataReader.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.
SEMI_MAJOR
,
SEMI_MINOR
,
LATITUDE_OF_ORIGIN
,
CENTRAL_MERIDIAN
,
FALSE_EASTING
,
FALSE_NORTHING
public static final TextMetadataParser.Key PRIME_MERIDIAN
"prime_meridian"
name parameter.
public static final TextMetadataParser.Key GREENWICH_LONGITUDE
"greenwich_longitude"
parameter.
public static final TextMetadataParser.Key SEMI_MAJOR
"semi_major"
ellipsoid parameter. There is no specific method
for this key. However, this key may be queried indirectly by
MetadataReader.getEllipsoid()
.
SEMI_MINOR
,
INVERSE_FLATTENING
,
LATITUDE_OF_ORIGIN
,
CENTRAL_MERIDIAN
,
FALSE_EASTING
,
FALSE_NORTHING
,
PROJECTION
public static final TextMetadataParser.Key SEMI_MINOR
"semi_minor"
ellipsoid parameter. There is no specific method
for this key. However, this key may be queried indirectly by
MetadataReader.getEllipsoid()
.
INVERSE_FLATTENING
,
SEMI_MAJOR
,
LATITUDE_OF_ORIGIN
,
CENTRAL_MERIDIAN
,
FALSE_EASTING
,
FALSE_NORTHING
,
PROJECTION
public static final TextMetadataParser.Key INVERSE_FLATTENING
"inverse_flattening"
ellipsoid parameter. There is no specific
method for this key. However, this key may be queried indirectly by
MetadataReader.getEllipsoid()
.
SEMI_MINOR
,
SEMI_MAJOR
,
LATITUDE_OF_ORIGIN
,
CENTRAL_MERIDIAN
,
FALSE_EASTING
,
FALSE_NORTHING
,
PROJECTION
public static final TextMetadataParser.Key LATITUDE_OF_ORIGIN
"latitude_of_origin"
projection parameter. There is no specific
method for this key. However, this key may be queried indirectly by
MetadataReader.getProjection()
.
SEMI_MAJOR
,
SEMI_MINOR
,
CENTRAL_MERIDIAN
,
FALSE_EASTING
,
FALSE_NORTHING
,
PROJECTION
public static final TextMetadataParser.Key CENTRAL_MERIDIAN
"central_meridian"
projection parameter. There is no specific
method for this key. However, this key may be queried indirectly by
MetadataReader.getProjection()
.
SEMI_MAJOR
,
SEMI_MINOR
,
LATITUDE_OF_ORIGIN
,
FALSE_EASTING
,
FALSE_NORTHING
,
PROJECTION
public static final TextMetadataParser.Key FALSE_EASTING
"false_easting"
projection parameter. There is no specific
method for this key. However, this key may be queried indirectly by
MetadataReader.getProjection()
.
SEMI_MAJOR
,
SEMI_MINOR
,
LATITUDE_OF_ORIGIN
,
CENTRAL_MERIDIAN
,
FALSE_NORTHING
,
PROJECTION
public static final TextMetadataParser.Key FALSE_NORTHING
"false_northing"
projection parameter. There is no specific
method for this key. However, this key may be queried indirectly by
MetadataReader.getProjection()
.
SEMI_MAJOR
,
SEMI_MINOR
,
LATITUDE_OF_ORIGIN
,
CENTRAL_MERIDIAN
,
FALSE_EASTING
,
PROJECTION
public static final TextMetadataParser.Key X_MINIMUM
MetadataReader.getEnvelope()
method looks for this metadata in order
to set the minimal coordinate for dimension
0.
X_MAXIMUM
,
Y_MINIMUM
,
Y_MAXIMUM
,
X_RESOLUTION
,
Y_RESOLUTION
public static final TextMetadataParser.Key Y_MINIMUM
MetadataReader.getEnvelope()
method looks for this metadata. in order
to set the minimal coordinate for dimension
1.
X_MINIMUM
,
X_MAXIMUM
,
Y_MAXIMUM
,
X_RESOLUTION
,
Y_RESOLUTION
public static final TextMetadataParser.Key Z_MINIMUM
MetadataReader.getEnvelope()
method looks for this metadata in order
to set the minimal coordinate for dimension
2.
Z_MAXIMUM
,
Z_RESOLUTION
,
DEPTH
public static final TextMetadataParser.Key X_MAXIMUM
MetadataReader.getEnvelope()
method looks for this metadata in order
to set the maximal coordinate for dimension
0.
X_MINIMUM
,
Y_MINIMUM
,
Y_MAXIMUM
,
X_RESOLUTION
,
Y_RESOLUTION
public static final TextMetadataParser.Key Y_MAXIMUM
MetadataReader.getEnvelope()
method looks for this metadata in order
to set the maximal coordinate for dimension
1.
X_MINIMUM
,
X_MAXIMUM
,
Y_MINIMUM
,
X_RESOLUTION
,
Y_RESOLUTION
public static final TextMetadataParser.Key Z_MAXIMUM
MetadataReader.getEnvelope()
method looks for this metadata in order
to set the maximal coordinate for dimension
2.
Z_MINIMUM
,
Z_RESOLUTION
,
DEPTH
public static final TextMetadataParser.Key X_RESOLUTION
MetadataReader.getEnvelope()
method looks for this metadata in order
to infer the coordinates for dimension 0.
X_MINIMUM
,
X_MAXIMUM
,
Y_MINIMUM
,
Y_MAXIMUM
,
Y_RESOLUTION
public static final TextMetadataParser.Key Y_RESOLUTION
MetadataReader.getEnvelope()
method looks for this metadata in order
to infer the coordinates for dimension 1.
X_MINIMUM
,
X_MAXIMUM
,
Y_MINIMUM
,
Y_MAXIMUM
,
X_RESOLUTION
,
WIDTH
,
HEIGHT
public static final TextMetadataParser.Key Z_RESOLUTION
MetadataReader.getEnvelope()
method looks for this metadata in order to
infer the coordinates for dimension 2.
Z_MINIMUM
,
Z_MAXIMUM
,
DEPTH
public static final TextMetadataParser.Key X_DIRECTION
MetadataReader.getAxis(int)
method looks for this metadata in order to
set its direction.
public static final TextMetadataParser.Key Y_DIRECTION
MetadataReader.getAxis(int)
method looks for this metadata in order to
set its direction.
public static final TextMetadataParser.Key Z_DIRECTION
MetadataReader.getAxis(int)
method looks for this metadata in order to
set its direction.
public static final TextMetadataParser.Key WIDTH
MetadataReader.getGridRange()
method looks for this metadata in order to infer the
grid size along the dimension 0.
HEIGHT
,
X_RESOLUTION
,
Y_RESOLUTION
public static final TextMetadataParser.Key HEIGHT
MetadataReader.getGridRange()
method looks for this metadata in order to infer the
grid size along the dimension 1.
WIDTH
,
X_RESOLUTION
,
Y_RESOLUTION
public static final TextMetadataParser.Key DEPTH
MetadataReader.getGridRange()
method looks for this metadata in order
to infer the grid size along the dimension
2.
Z_MINIMUM
,
Z_MAXIMUM
,
Z_RESOLUTION
Constructor Detail |
---|
public TextMetadataParser()
MetadataReader
using default factories.
public TextMetadataParser(ReferencingFactoryContainer factories)
MetadataReader
using the specified factories.
Method Detail |
---|
public java.lang.String getSeparator()
#listMetadata
,
but will be ignored when parsing with parseLine(java.lang.String)
. The default value
is " = "
.
public void setSeparator(java.lang.String separator)
public java.lang.String getFormatPattern(java.lang.Class<?> type)
Number.class
or Date.class
.
type
is assignable to Number.class
, then this method
returns the number pattern as specified by DecimalFormat
.type
is assignable to Date.class
, then
this method returns the date pattern as specified by
SimpleDateFormat
.
In any case, this method returns null
if this object should use the
default pattern for the data locale.
type
- The data type (Number.class
or Date.class
).
null
for
the default locale-dependent pattern.
java.lang.IllegalArgumentException
- if type
is not valid.public void setFormatPattern(java.lang.Class<?> type, java.lang.String pattern)
Number.class
or Date.class
.
type
is assignable to Number.class
,
then pattern
should be a DecimalFormat
pattern (example:
"#0.###"
).type
is assignable to Date.class
,
then pattern
should be a SimpleDateFormat
pattern
(example: "yyyy/MM/dd HH:mm"
).
type
- The data type (Number.class
or Date.class
).pattern
- The format pattern for the specified data type, or null
for the default locale-dependent pattern.
java.lang.IllegalArgumentException
- if type
is not valid.public void clear()
MetadataReader
object is used
for parsing many files, then clear()
should be invoked prior any
load(...)
method.
Note that clear()
do not remove any alias, so this MetadataReader
can be immediately reused for parsing new files of the same kind.
public void load(java.io.File header) throws java.io.IOException
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.
header
- The file to read until EOF.
java.io.IOException
- if an error occurs during loading.clear()
,
load(URL)
,
parseLine(java.lang.String)
,
getSource()
public void load(java.net.URL header) throws java.io.IOException
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.
header
- The URL to read until EOF.
java.io.IOException
- if an error occurs during loading.clear()
,
load(File)
,
parseLine(java.lang.String)
,
getSource()
protected void load(java.io.BufferedReader in) throws java.io.IOException
parseLine(java.lang.String)
for each non-empty line found in the stream. Notes:
source
metadata.clear()
prior the loading.
in
- The stream to read until EOF. The stream will not be closed.
java.io.IOException
- if an error occurs during loading.clear()
,
load(File)
,
load(URL)
,
parseLine(java.lang.String)
protected boolean parseLine(java.lang.String line) throws javax.imageio.IIOException
line
has the following value:
Then, the default implementation will translate this line in the following call:Ellipsoid = WGS 1984
This method returnsadd
("Ellipsoid", "WGS 1984");
true
if it has consumed the line, or false
otherwise.
A line is "consumed" if parseLine(...)
has either added the key-value
pair (using add(java.awt.image.RenderedImage)
), or determined that the line must be ignored (for
example because parseLine(...)
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 false
) if
parseLine(...)
don't know what to do with it. Non-consumed line will
typically go up in a chain of parseLine(...)
methods (if
MetadataReader
has been subclassed) until someone consume it.
line
- The line to parse.
true
if this method has consumed the line.
javax.imageio.IIOException
- if the line is badly formatted.
AmbiguousMetadataException
- if a different value was already defined
for the same metadata name.load(File)
,
load(URL)
,
add(String,Object)
public void add(java.awt.image.RenderedImage image) throws AmbiguousMetadataException
image
- The image with metadata to add to this MetadataReader
.
AmbiguousMetadataException
- if a metadata is defined twice.#add(GridCoverage)
,
add(PropertySource,String)
,
add(String,Object)
public void add(javax.media.jai.PropertySource properties, java.lang.String prefix) throws AmbiguousMetadataException
properties
- The properties source.prefix
- The prefix for properties to add, of null
to add
all properties. If non-null, only properties begining with this prefix
will be added.
AmbiguousMetadataException
- if a metadata is defined twice.#add(GridCoverage)
,
add(RenderedImage)
,
add(String,Object)
public void add(java.lang.String alias, java.lang.Object value) throws AmbiguousMetadataException
'_'
character.
alias
- The key for the metadata to add. This is usually the name found
in the file to be parsed (this is different from TextMetadataParser.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.image.io.text.TextMetadataParser.Key, java.lang.String)
.value
- The value for the metadata to add. If null
or
Image.UndefinedProperty
, then this method do nothing.
AmbiguousMetadataException
- if a different value already exists for the
specified alias, or for an other alias bound to the same TextMetadataParser.Key
.#add(GridCoverage)
,
add(RenderedImage)
,
add(PropertySource,String)
,
parseLine(java.lang.String)
public void addAlias(TextMetadataParser.Key key, java.lang.String alias) throws AmbiguousMetadataException
get
(key)
will really looks for metadata named
alias
. Alias are mandatory in order to get various getXXX()
methods to work for a particular file format.
For example if the file to be parsed uses the names "ULX"
and
"ULY"
for the coordinate of the upper left corner, then the
#getEnvelope
method will not work unless the following alias are set:
An arbitrary number of alias can be set for the same key. For example,addAlias(X_MINIMUM, "ULX"); addAlias(Y_MAXIMUM, "ULY");
addAlias(Y_MAXIMUM, ...)
could be invoked twice with
"ULY"
and "Limit North"
alias. The getXXX()
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");
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.
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.getAlias(org.geotools.image.io.text.TextMetadataParser.Key)
,
#contains
,
#get
public java.util.Set<java.lang.String> getAlias(TextMetadataParser.Key key)
null
if the key has no alias. Alias are the names used in the underlying
metadata file, and are format dependent.
key
- The format neutral key.
null
if none.addAlias(org.geotools.image.io.text.TextMetadataParser.Key, java.lang.String)
public java.lang.String getSource() throws MetadataException
load(...)
method.
MetadataException
- if this information can't be fetched.public java.util.Locale getLocale()
Locale.US
, since it is the format used
in most data file.
MetadataException
- if this information can't be fetched.#getAsDouble
,
#getAsInt
,
#getAsDate
protected GeographicMetadata getGeographicMetadata()
protected void setGeographicMetadata(GeographicMetadata metadata)
protected abstract void put(TextMetadataParser.Key key, java.lang.Object value)
key
- The alias of the key to add.value
- The value to add in the metadata tree.protected abstract void putDone()
put(Key, Object)
method has been done. It will
add axes according to the dimension defined, and sets grid range and offset vectors
for all dimensions defined.
public java.lang.String toString()
#getGeographicBoundingBox
. Then, it append the list of all metadata as
formatted by #listMetadata
.
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |