org.geotoolkit.io.wkt
Class FormattableObject

Object
  extended by FormattableObject
All Implemented Interfaces:
Formattable
Direct Known Subclasses:
AbstractIdentifiedObject, AbstractMathTransform, AbstractParameter, BursaWolfParameters

public class FormattableObject
extends Object
implements Formattable

Base class for objects formattable as Well Known Text (WKT). Almost every Geotk implementations of referencing objects extend this class, except AffineTransform2D.


Strict and lenient WKT formatting
Strict WKT formatting is performed by various toWKT(...) methods. Those methods may fail to format a particular object, in which case a UnformattableObjectException is thrown. A formatting may fail because an object is too complex for the WKT format capability (for example an EngineeringCRS with different unit for each axis), or because only some specific implementations can be formatted as WKT.

The default implementation of toString() is like toWKT() except that no exception is thrown if the resulting WKT is not compliant with the specification. The toString() method does not provide control over indentation and other features. But if such control is desired, it can be obtained by using directly the Formatter class.


Syntax coloring
A convenience print() method is provided, which is roughly equivalent to System.out.println(this) except that syntax coloring is automatically applied if the terminal seems to support the X3.64 standard.

Since:
2.0
Version:
3.16
Author:
Martin Desruisseaux (IRD, Geomatys)
Module:
referencing/geotk-referencing (download)    View source code for this class

Field Summary
static Citation EPSG
          Frequently used authority for formatting WKT.
static Citation GEOTIFF
          Frequently used authority for formatting WKT.
static Citation INTERNAL
          A special citation for formatting objects as stored internally by Geotk.
static Citation OGC
          Frequently used authority for formatting WKT.
static int SINGLE_LINE
          The indentation value to give to toWKT(int) method for formatting the complete object on a single line.
 
Constructor Summary
protected FormattableObject()
          Default constructor.
 
Method Summary
 String formatWKT(Formatter formatter)
          Formats the inner part of a Well Known Text (WKT) element.
static int getDefaultIndentation()
          Returns the default indentation.
 void print()
          Prints a string representation of this object to the standard output stream.
static void setDefaultIndentation(int indentation)
          Sets the default value for indentation.
 String toString()
          Returns a string representation for this object.
 String toWKT()
          Returns a Well Known Text (WKT) using the default indentation.
 String toWKT(Citation authority, int indentation)
          Returns a Well Known Text (WKT) for this object using the specified indentation and authority.
 String toWKT(int indentation)
          Returns a Well Known Text (WKT) for this object using the specified indentation.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SINGLE_LINE

public static final int SINGLE_LINE
The indentation value to give to toWKT(int) method for formatting the complete object on a single line.

Since:
2.6
See Also:
Constant Field Values

OGC

public static final Citation OGC
Frequently used authority for formatting WKT. This is the same reference than the one declared in the Citations class, copied here for convenience.

Since:
3.00
See Also:
Citations.OGC

EPSG

public static final Citation EPSG
Frequently used authority for formatting WKT. This is the same reference than the one declared in the Citations class, copied here for convenience.

Since:
3.00
See Also:
Citations.EPSG

GEOTIFF

public static final Citation GEOTIFF
Frequently used authority for formatting WKT. This is the same reference than the one declared in the Citations class, copied here for convenience.

Since:
3.00
See Also:
Citations.GEOTIFF

INTERNAL

public static final Citation INTERNAL
A special citation for formatting objects as stored internally by Geotk. This citation can be given to the authority argument of the toWKT(Citation,int) method. In the majority of cases, the result will be identical to the one we would get using the OGC authority. However in the particular case of map projections, the result may be quite different because of the way Geotk separates the linear from the non-linear parameters.

This citation is used only for debugging purpose.

Since:
3.00
Constructor Detail

FormattableObject

protected FormattableObject()
Default constructor.

Method Detail

print

public void print()
Prints a string representation of this object to the standard output stream. If a console is attached to the running JVM (i.e. if the application is run from the command-line and the output is not redirected to a file) and if Geotk thinks that the console supports the X3.64 standard, then a syntax coloring will be applied.

This is a convenience method for debugging purpose and for console applications.

Note: We don't use the standard error stream (the stream used by the Java logging framework) because it is different than the stream used by the console.

Since:
3.00

toString

public String toString()
Returns a string representation for this object. The default implementation returns the same string than toWKT(), except that no exception is thrown if the string contains non-standard keywords. For example the WKT specification does not defines any keyword for coordinate system objects. If this object is an instance of DefaultCartesianCS, then the WKT will be formatted as CartesianCS[AXIS["..."], AXIS["..."], etc.].

Overrides:
toString in class Object

toWKT

public String toWKT()
             throws UnformattableObjectException
Returns a Well Known Text (WKT) using the default indentation.

Returns:
The Well Know Text for this object.
Throws:
UnformattableObjectException - If this object can't be formatted as WKT.

toWKT

public String toWKT(int indentation)
             throws UnformattableObjectException
Returns a Well Known Text (WKT) for this object using the specified indentation.

Parameters:
indentation - The amount of spaces to use in indentation for WKT formatting, or SINGLE_LINE for formatting the whole WKT on a single line.
Returns:
The Well Know Text for this object.
Throws:
UnformattableObjectException - If this object can't be formatted as WKT.

toWKT

public String toWKT(Citation authority,
                    int indentation)
             throws UnformattableObjectException
Returns a Well Known Text (WKT) for this object using the specified indentation and authority. The authority is usually OGC, but other common authorities are GEOTIFF and EPSG. The INTERNAL citation is a special value for debugging map projections.

Parameters:
authority - The authority to prefer when choosing WKT entities names.
indentation - The amount of spaces to use in indentation for WKT formatting, or SINGLE_LINE for formatting the whole WKT on a single line.
Returns:
The Well Know Text for this object.
Throws:
UnformattableObjectException - If this object can't be formatted as WKT.

formatWKT

public String formatWKT(Formatter formatter)
Formats the inner part of a Well Known Text (WKT) element. This method is automatically invoked by Formatter.append(Formattable). Element name and authority code must not be formatted here. For example for a GEOGCS element, the formatter will invoke this method for completing the WKT at the insertion point show below:
GEOGCS["WGS 84", AUTHORITY["EPSG","4326"]]
               ↑
       (insertion point)
The default implementation declares that this object produces an invalid WKT. Subclasses must override this method for proper WKT formatting and should not invoke super.formatWKT(formatter) if they can use a valid WKT syntax.

Specified by:
formatWKT in interface Formattable
Parameters:
formatter - The formatter to use.
Returns:
The name of the WKT element type (e.g. "GEOGCS").
See Also:
toWKT(), toString()

getDefaultIndentation

public static int getDefaultIndentation()
Returns the default indentation. The default value can be modified by a call to setDefaultIndentation(int).

Returns:
The default indentation.
Since:
3.00

setDefaultIndentation

@Configuration
public static void setDefaultIndentation(int indentation)
Sets the default value for indentation.

Parameters:
indentation - The new default value for indentation.
Since:
3.00


Copyright © 2009-2011 Geotoolkit.org. All Rights Reserved.