public final class LonLatFormat extends Object implements AutoCloseable
The EBNF for the pattern syntax is
pattern = lon, separator, lat | lat, separator, lon lon = "lon(", { "+" | "-" }, { axis | degrees | minutes | seconds }+, ")" lat = "lat(", { "+" | "-" }, { axis | degrees | minutes | seconds }+, ")" axis = "a" degrees = { "d" | "D" }+, { digit }* minutes = { "m" | "M" }+, { digit }* seconds = { "s" | "S" }+, { digit }* digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" separator = { ? any character ? }where "{ x }" means x is optional, "{ x }*" means x occurs zero or more times, and "{ x }+" means x occurs at least once.
The table below details the meaning of each pattern character.
Symbol | Meaning | Examples |
---|---|---|
d | Integer degrees.* | d: 12, ddd: 012 |
d<n> | Degrees with <n> fractional digits.* | d2: 12.34, ddd2: 012.34 |
D | Integer degrees with degrees symbol.* | D: 12°, DDD: 012° |
D<n> | Degrees with symbol and <n> fractional digits.* | D2: 12.34°, DDD2: 012.34° |
m | Integer minutes.* | m: 3, mm: 03 |
m<n> | Minutes with <n> fractional digits.* | m2: 3.45, mm2: 03.45 |
M | Integer minutes with degrees symbol.* | M: 3', MM: 03' |
M<n> | Minutes with symbol and <n> fractional digits.* | M2: 3.45', MM2: 03.45' |
s | Integer seconds.* | s: 7, ss: 07 |
s<n> | Seconds with <n> fractional digits.* | s2: 7.89, ss2: 07.89 |
S | Integer seconds with degrees symbol.* | S: 7", SS: 07" |
S<n> | Seconds with symbol and <n> fractional digits.* | S2: 7.89", SS2: 07.89" |
+ | Coordinate sign. Results in a + if the coordinate is positive, and a - if it is negative. |
+, - |
- | Coordinate sign. Results in a - if the coordinate is negative. |
- |
a | Hemisphere indicator | N, S, E, W |
As an example, the default formatting pattern is "lat(-DMS), lon(-DMS)". This results in a format that generates formatted coordinates like -12°34'56", 123°45'12".
Constructor and Description |
---|
LonLatFormat()
Creates a new LonLatFormat from the default format "lat(-DMS), lon(-DMS)".
|
LonLatFormat(String pattern)
Creates a new LonLatFormat from the given pattern.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
finalize() |
String |
format(Coordinate lonLatCoord)
Format the given LonLat
Coordinate according to this LonLatFormat. |
String |
format(Point lonLatPoint)
Format the given
Point according to this LonLatFormat. |
String |
formatLat(double lat)
Format the given latitude according to this LonLatFormat.
|
String |
formatLon(double lon)
Format the given longitude according to this LonLatFormat.
|
static boolean |
isValidFormatString(String format)
Returns if the given string is a valid LonLat format string.
|
String |
toPattern()
Get the pattern string used to create this format.
|
public LonLatFormat()
public LonLatFormat(@NotNull String pattern) throws IllegalArgumentException
pattern
- the pattern string.IllegalArgumentException
- if pattern is not a valid pattern.public void close()
close
in interface AutoCloseable
public static boolean isValidFormatString(@NotNull String format)
format
- the format string.@NotNull public String formatLon(double lon)
lon
- the longitude.@NotNull public String formatLat(double lat)
lat
- the latitude.@NotNull public String format(@NotNull Point lonLatPoint)
Point
according to this LonLatFormat.lonLatPoint
- the Point
.@NotNull public String format(@NotNull Coordinate lonLatCoord)
Coordinate
according to this LonLatFormat.lonLatCoord
- the Coordinate
.@NotNull public String toPattern()