Class LocationFormat
java.lang.Object
java.text.Format
org.apache.sis.io.CompoundFormat<T>
org.apache.sis.io.TabularFormat<AbstractLocation>
org.apache.sis.referencing.gazetteer.LocationFormat
- All Implemented Interfaces:
Serializable
,Cloneable
,Localized
Formats
Location
instances in a tabular format.
This format assumes a monospaced font and an encoding supporting drawing box characters (e.g. UTF-8).
Example:
the location identified by "32TNL83" in the military grid reference system
can be represented by the following string formatted using
Locale.ENGLISH
:
Limitations
- The current implementation can only format features — parsing is not yet implemented.
LocationFormat
, like mostjava.text.Format
subclasses, is not thread-safe.
- Since:
- 0.8
- Version:
- 0.8
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final short[]
Vocabulary.Keys
constants for the east, west, south and north bounds, in that order.(package private) static final LocationFormat
Default instance forAbstractLocation.toString()
.private static final long
For cross-version compatibility.Fields inherited from class org.apache.sis.io.TabularFormat
beforeFill, columnSeparator, fillCharacter, lineSeparator, omitTrailingNulls
-
Constructor Summary
ConstructorsConstructorDescriptionLocationFormat
(Locale locale, TimeZone timezone) Creates a new format for the given locale. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
append
(TableAppender table, Vocabulary vocabulary, short key, String value) Appends the given value in the given table if it is not null.clone()
Returns a clone of this format.protected Format
createFormat
(Class<?> valueType) Creates the format to use for formatting a latitude, longitude or projected coordinate.void
format
(AbstractLocation location, Appendable toAppendTo) Writes a textual representation of the given location in the given stream or buffer.Returns the type of values formatted by thisFormat
instance.private void
nextColumn
(TableAppender table) Moves to the next column.private static org.opengis.referencing.crs.CoordinateReferenceSystem
normalize
(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Returns a CRS equivalent to the given one but with (longitude, latitude) or (easting, northing) axis order.parse
(CharSequence text, ParsePosition pos) Unsupported operation.private static org.opengis.geometry.DirectPosition
position
(org.opengis.geometry.coordinate.Position p) Returns the direct position for the given position, ornull
if none.private String
Returns a localized version of the given date, ornull
if none.private static String
Returns a localized version of the given international string, ornull
if none.private static org.opengis.geometry.DirectPosition
transform
(org.opengis.geometry.DirectPosition position, org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS) Transforms the given position from the given source to the given target CRS.Methods inherited from class org.apache.sis.io.TabularFormat
getColumnSeparatorMatcher, getColumnSeparatorPattern, getLineSeparator, setColumnSeparatorPattern, setLineSeparator
Methods inherited from class org.apache.sis.io.CompoundFormat
format, getFormat, getLocale, getLocale, getTimeZone, parseObject, parseObject
Methods inherited from class java.text.Format
format, formatToCharacterIterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
INSTANCE
Default instance forAbstractLocation.toString()
. Use of this instance must be synchronized onINSTANCE
. -
BOUND_KEY
private static final short[] BOUND_KEYVocabulary.Keys
constants for the east, west, south and north bounds, in that order.
-
-
Constructor Details
-
LocationFormat
Creates a new format for the given locale. The given locale can benull
orLocale.ROOT
if this format shall format "unlocalized" strings.- Parameters:
locale
- the locale for the newFormat
, ornull
forLocale.ROOT
.timezone
- the timezone, ornull
for UTC.
-
-
Method Details
-
getValueType
Returns the type of values formatted by thisFormat
instance.- Specified by:
getValueType
in classCompoundFormat<AbstractLocation>
- Returns:
- the type of values formatted by this
Format
instance.
-
normalize
private static org.opengis.referencing.crs.CoordinateReferenceSystem normalize(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Returns a CRS equivalent to the given one but with (longitude, latitude) or (easting, northing) axis order. This method does not change the units of measurement. If the given CRS is already normalized, then it is returned unchanged. -
transform
private static org.opengis.geometry.DirectPosition transform(org.opengis.geometry.DirectPosition position, org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException Transforms the given position from the given source to the given target CRS. If the source and target CRS are the same, then this method returns the position unchanged.- Throws:
org.opengis.util.FactoryException
org.opengis.referencing.operation.TransformException
-
position
private static org.opengis.geometry.DirectPosition position(org.opengis.geometry.coordinate.Position p) Returns the direct position for the given position, ornull
if none. -
toString
Returns a localized version of the given international string, ornull
if none. -
toString
Returns a localized version of the given date, ornull
if none. -
format
Writes a textual representation of the given location in the given stream or buffer.Upcoming API change — generalization
in a future SIS version, the type oflocation
parameter may be generalized to theorg.opengis.referencing.gazetteer.Location
interface. This change is pending GeoAPI revision.- Specified by:
format
in classCompoundFormat<AbstractLocation>
- Parameters:
location
- the location to format.toAppendTo
- where to format the location.- Throws:
IOException
- if an error occurred while writing to the given appendable.
-
createFormat
Creates the format to use for formatting a latitude, longitude or projected coordinate. This method is invoked byformat(Location, Appendable)
when first needed.- Overrides:
createFormat
in classCompoundFormat<AbstractLocation>
- Parameters:
valueType
-Angle.class
.Number.class
orUnit.class
.- Returns:
- a new
AngleFormat
,NumberFormat
orUnitFormat
instance depending on the argument value.
-
append
private void append(TableAppender table, Vocabulary vocabulary, short key, String value) throws IOException Appends the given value in the given table if it is not null.- Parameters:
table
- the table where to append the value.vocabulary
- localized resources for the labels.key
- key of the label to append.value
- value to append, ornull
if none.- Throws:
IOException
-
nextColumn
Moves to the next column. -
parse
Unsupported operation.- Specified by:
parse
in classCompoundFormat<AbstractLocation>
- Parameters:
text
- the character sequence for the location to parse.pos
- the position where to start the parsing.- Returns:
- the parsed location, or
null
if the text is not recognized. - Throws:
ParseException
- if an error occurred while parsing the location.
-
clone
Returns a clone of this format.- Overrides:
clone
in classTabularFormat<AbstractLocation>
- Returns:
- a clone of this format.
-