LuciadCPillar 2023.1.04
luciad::LonLatFormat Class Referencefinal

Class to format points as LonLat coordinates. More...

#include <luciad/grids/lonlat/LonLatFormat.h>

Public Member Functions

 LonLatFormat ()
 Creates a new LonLatFormat from the default format "lat(-DMS), lon(-DMS)". More...
 
 LonLatFormat (const std::string &pattern)
 Creates a new LonLatFormat from the given pattern. More...
 
std::string format (const Point &lonLatPoint) const
 Format the given Point according to this LonLatFormat. More...
 
std::string format (Coordinate lonLatCoord) const
 Format the given LonLat Coordinate according to this LonLatFormat. More...
 
std::string formatLat (double lat) const
 Format the given latitude according to this LonLatFormat. More...
 
std::string formatLon (double lon) const
 Format the given longitude according to this LonLatFormat. More...
 
std::string toPattern () const
 Get the pattern string used to create this format. More...
 

Static Public Member Functions

static bool isValidFormatString (const std::string &format)
 Returns if the given string is a valid LonLat format string. More...
 

Detailed Description

Class to format points as LonLat coordinates.

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.

SymbolMeaning

Examples

dInteger degrees.*d: 12, ddd: 012
d<n>Degrees with <n> fractional digits.*

d2: 12.34, ddd2: 012.34

DInteger degrees with degrees symbol.*D: 12°, DDD: 012°
D<n>Degrees with symbol and <n> fractional digits.*

D2: 12.34°, DDD2: 012.34°

mInteger minutes.*m: 3, mm: 03
m<n>Minutes with <n> fractional digits.*

m2: 3.45, mm2: 03.45

MInteger minutes with degrees symbol.*M: 3', MM: 03'
M<n>Minutes with symbol and <n> fractional digits.*

M2: 3.45', MM2: 03.45'

sInteger seconds.*s: 7, ss: 07
s<n>Seconds with <n> fractional digits.*

s2: 7.89, ss2: 07.89

SInteger 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.

-

aHemisphere indicatorN, S, E, W

*Repeating this character pads the number with leading zeros.

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".

Since
2023.1

Constructor & Destructor Documentation

◆ LonLatFormat() [1/2]

luciad::LonLatFormat::LonLatFormat ( )

Creates a new LonLatFormat from the default format "lat(-DMS), lon(-DMS)".

◆ LonLatFormat() [2/2]

luciad::LonLatFormat::LonLatFormat ( const std::string &  pattern)
explicit

Creates a new LonLatFormat from the given pattern.

Parameters
patternthe pattern string.
Exceptions
luciad::InvalidArgumentExceptionif pattern is not a valid pattern.

Member Function Documentation

◆ format() [1/2]

std::string luciad::LonLatFormat::format ( const Point lonLatPoint) const

Format the given Point according to this LonLatFormat.

Parameters
lonLatPointthe Point.
Returns
the formatted string.

◆ format() [2/2]

std::string luciad::LonLatFormat::format ( Coordinate  lonLatCoord) const

Format the given LonLat Coordinate according to this LonLatFormat.

Parameters
lonLatCoordthe Coordinate.
Returns
the formatted string.

◆ formatLat()

std::string luciad::LonLatFormat::formatLat ( double  lat) const

Format the given latitude according to this LonLatFormat.

Parameters
latthe latitude.
Returns
the formatted string.

◆ formatLon()

std::string luciad::LonLatFormat::formatLon ( double  lon) const

Format the given longitude according to this LonLatFormat.

Parameters
lonthe longitude.
Returns
the formatted string.

◆ isValidFormatString()

static bool luciad::LonLatFormat::isValidFormatString ( const std::string &  format)
static

Returns if the given string is a valid LonLat format string.

Parameters
formatthe format string.
Returns
true if the string is a valid LonLat format string.

◆ toPattern()

std::string luciad::LonLatFormat::toPattern ( ) const

Get the pattern string used to create this format.

Returns
the pattern string.