KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
GeoCoordinate Class Reference

A WGS-84 geographic coordinate (latitude, longitude, altitude). More...

#include <geocoordinate.h>

Public Types

enum  CoordinateFormat { Degrees , Parsable }
 Output format for toString(). More...
 

Public Member Functions

 GeoCoordinate ()
 Default constructor — creates an invalid coordinate at (0, 0, 0).
 
 GeoCoordinate (double latitude, double longitude, double altitude=0)
 Construct a coordinate from decimal latitude, longitude, and optional altitude.
 
 GeoCoordinate (const QString &value)
 Construct a coordinate by parsing a string.
 
bool operator== (const GeoCoordinate &other) const
 Equality comparison at the configured precision.
 
bool operator!= (const GeoCoordinate &other) const
 Inequality comparison.
 
double latitude () const
 Return the latitude in decimal degrees.
 
void setLatitude (double value)
 Set the latitude in decimal degrees.
 
double longitude () const
 Return the longitude in decimal degrees.
 
void setLongitude (double value)
 Set the longitude in decimal degrees.
 
double altitude () const
 Return the altitude in metres.
 
void setAltitude (double value)
 Set the altitude in metres.
 
int precision () const
 Return the decimal precision used for coordinate comparisons.
 
void setPrecision (int value)
 Set the decimal precision used for coordinate comparisons.
 
double distanceTo (const GeoCoordinate &other) const
 Compute the great-circle distance to another coordinate in metres.
 
double azimuthTo (const GeoCoordinate &other) const
 Compute the azimuth (bearing) to another coordinate in degrees.
 
GeoCoordinate atDistanceAndAzimuth (double distance, double azimuth)
 Return the coordinate reached by travelling a given distance and azimuth from this point.
 
bool isNorthOfOrEqualTo (const GeoCoordinate &other) const
 Test whether this coordinate is north of or at the same latitude as another.
 
bool isNorthOf (const GeoCoordinate &other) const
 Test whether this coordinate is strictly north of another.
 
bool isSouthOfOrEqualTo (const GeoCoordinate &other) const
 Test whether this coordinate is south of or at the same latitude as another.
 
bool isSouthOf (const GeoCoordinate &other) const
 Test whether this coordinate is strictly south of another.
 
bool isWestOfOrEqualTo (const GeoCoordinate &other) const
 Test whether this coordinate is west of or at the same longitude as another.
 
bool isWestOf (const GeoCoordinate &other) const
 Test whether this coordinate is strictly west of another.
 
bool isEastOfOrEqualTo (const GeoCoordinate &other) const
 Test whether this coordinate is east of or at the same longitude as another.
 
bool isEastOf (const GeoCoordinate &other) const
 Test whether this coordinate is strictly east of another.
 
bool isEmpty () const
 Test whether this coordinate equals the default-constructed (empty) value.
 
bool isValid () const
 Test whether this coordinate represents a valid position.
 
QString toString (CoordinateFormat format=Degrees, int precision=0) const
 Format this coordinate as a string.
 

Static Public Member Functions

static GeoCoordinate fromString (const QString &value)
 Parse a GeoCoordinate from a string representation.
 
static GeoCoordinate fromDMS (Geo::CardinalDirection latitudeCardinalDirection, double latitudeDegrees, double latitudeMinutes, double latitudeSeconds, Geo::CardinalDirection longitudeCardinalDirection, double longitudeDegrees, double longitudeMinutes, double longitudeSeconds)
 Construct a coordinate from degrees-minutes-seconds components.
 
static bool tryParse (const QString &stringValue, GeoCoordinate &point)
 Attempt to parse a coordinate string, reporting success.
 
static GeoCoordinate empty ()
 Return a default-constructed (empty) coordinate.
 
static double getDistance (const GeoCoordinate &pt1, const GeoCoordinate &pt2)
 Compute the great-circle distance between two coordinates in metres.
 
static double getAzimuth (const GeoCoordinate &pt1, const GeoCoordinate &pt2)
 Compute the azimuth from one coordinate to another in degrees.
 
static GeoCoordinate getPointAtDistanceAndAzimuth (const GeoCoordinate &origin, double distance, double azimuth)
 Compute the coordinate reached by travelling from an origin at a given distance and azimuth.
 

Detailed Description

A WGS-84 geographic coordinate (latitude, longitude, altitude).

Represents a geographic position as WGS-84 latitude, longitude, and altitude.

Provides distance, azimuth, and point-at-distance-and-azimuth calculations using the Haversine formula, as well as cardinal direction comparisons.

Definition at line 19 of file geocoordinate.h.

Member Enumeration Documentation

◆ CoordinateFormat

Output format for toString().

Enumerator
Degrees 

Decimal degrees (e.g. "37.7749, -122.4194")

Parsable 

Format suitable for round-trip parsing by fromString()

Definition at line 84 of file geocoordinate.h.

Constructor & Destructor Documentation

◆ GeoCoordinate() [1/3]

GeoCoordinate::GeoCoordinate ( )
inline

Default constructor — creates an invalid coordinate at (0, 0, 0).

Definition at line 23 of file geocoordinate.h.

◆ GeoCoordinate() [2/3]

GeoCoordinate::GeoCoordinate ( double  latitude,
double  longitude,
double  altitude = 0 
)
inline

Construct a coordinate from decimal latitude, longitude, and optional altitude.

Parameters
latitudeLatitude in decimal degrees (negative = south)
longitudeLongitude in decimal degrees (negative = west)
altitudeAltitude in metres above the WGS-84 ellipsoid (default 0)

Definition at line 38 of file geocoordinate.h.

◆ GeoCoordinate() [3/3]

GeoCoordinate::GeoCoordinate ( const QString &  value)

Construct a coordinate by parsing a string.

Parameters
valueCoordinate string (see fromString())

Member Function Documentation

◆ altitude()

double GeoCoordinate::altitude ( ) const
inline

Return the altitude in metres.

Returns
Altitude above the WGS-84 ellipsoid

Definition at line 127 of file geocoordinate.h.

◆ atDistanceAndAzimuth()

GeoCoordinate GeoCoordinate::atDistanceAndAzimuth ( double  distance,
double  azimuth 
)
inline

Return the coordinate reached by travelling a given distance and azimuth from this point.

Parameters
distanceDistance in metres
azimuthBearing in degrees clockwise from North
Returns
Resulting GeoCoordinate

Definition at line 167 of file geocoordinate.h.

◆ azimuthTo()

double GeoCoordinate::azimuthTo ( const GeoCoordinate other) const
inline

Compute the azimuth (bearing) to another coordinate in degrees.

Parameters
otherDestination coordinate
Returns
Azimuth in degrees clockwise from North

Definition at line 159 of file geocoordinate.h.

◆ distanceTo()

double GeoCoordinate::distanceTo ( const GeoCoordinate other) const
inline

Compute the great-circle distance to another coordinate in metres.

Parameters
otherDestination coordinate
Returns
Distance in metres

Definition at line 152 of file geocoordinate.h.

◆ empty()

static GeoCoordinate GeoCoordinate::empty ( )
inlinestatic

Return a default-constructed (empty) coordinate.

Returns
Empty GeoCoordinate

Definition at line 269 of file geocoordinate.h.

◆ fromDMS()

static GeoCoordinate GeoCoordinate::fromDMS ( Geo::CardinalDirection  latitudeCardinalDirection,
double  latitudeDegrees,
double  latitudeMinutes,
double  latitudeSeconds,
Geo::CardinalDirection  longitudeCardinalDirection,
double  longitudeDegrees,
double  longitudeMinutes,
double  longitudeSeconds 
)
static

Construct a coordinate from degrees-minutes-seconds components.

Parameters
latitudeCardinalDirectionNorth or South
latitudeDegreesWhole degrees of latitude
latitudeMinutesMinutes of latitude
latitudeSecondsSeconds of latitude
longitudeCardinalDirectionEast or West
longitudeDegreesWhole degrees of longitude
longitudeMinutesMinutes of longitude
longitudeSecondsSeconds of longitude
Returns
Constructed GeoCoordinate

◆ fromString()

static GeoCoordinate GeoCoordinate::fromString ( const QString &  value)
inlinestatic

Parse a GeoCoordinate from a string representation.

Parameters
valueCoordinate string in decimal or DMS format
Returns
Parsed GeoCoordinate, or an invalid one on failure

Definition at line 61 of file geocoordinate.h.

◆ getAzimuth()

static double GeoCoordinate::getAzimuth ( const GeoCoordinate pt1,
const GeoCoordinate pt2 
)
static

Compute the azimuth from one coordinate to another in degrees.

Parameters
pt1Origin coordinate
pt2Destination coordinate
Returns
Azimuth in degrees clockwise from North

◆ getDistance()

static double GeoCoordinate::getDistance ( const GeoCoordinate pt1,
const GeoCoordinate pt2 
)
static

Compute the great-circle distance between two coordinates in metres.

Parameters
pt1First coordinate
pt2Second coordinate
Returns
Distance in metres

◆ getPointAtDistanceAndAzimuth()

static GeoCoordinate GeoCoordinate::getPointAtDistanceAndAzimuth ( const GeoCoordinate origin,
double  distance,
double  azimuth 
)
static

Compute the coordinate reached by travelling from an origin at a given distance and azimuth.

Parameters
originStarting coordinate
distanceDistance in metres
azimuthBearing in degrees clockwise from North
Returns
Resulting GeoCoordinate

◆ isEastOf()

bool GeoCoordinate::isEastOf ( const GeoCoordinate other) const
inline

Test whether this coordinate is strictly east of another.

Parameters
otherCoordinate to compare against
Returns
true if this longitude > other's longitude

Definition at line 235 of file geocoordinate.h.

◆ isEastOfOrEqualTo()

bool GeoCoordinate::isEastOfOrEqualTo ( const GeoCoordinate other) const
inline

Test whether this coordinate is east of or at the same longitude as another.

Parameters
otherCoordinate to compare against
Returns
true if this longitude ≥ other's longitude (at configured precision)

Definition at line 225 of file geocoordinate.h.

◆ isEmpty()

bool GeoCoordinate::isEmpty ( ) const
inline

Test whether this coordinate equals the default-constructed (empty) value.

Returns
true if this coordinate is at (0, 0, 0) with no cardinal directions set

Definition at line 241 of file geocoordinate.h.

◆ isNorthOf()

bool GeoCoordinate::isNorthOf ( const GeoCoordinate other) const

Test whether this coordinate is strictly north of another.

Parameters
otherCoordinate to compare against
Returns
true if this latitude > other's latitude

◆ isNorthOfOrEqualTo()

bool GeoCoordinate::isNorthOfOrEqualTo ( const GeoCoordinate other) const
inline

Test whether this coordinate is north of or at the same latitude as another.

Parameters
otherCoordinate to compare against
Returns
true if this latitude ≥ other's latitude (at configured precision)

Definition at line 174 of file geocoordinate.h.

◆ isSouthOf()

bool GeoCoordinate::isSouthOf ( const GeoCoordinate other) const
inline

Test whether this coordinate is strictly south of another.

Parameters
otherCoordinate to compare against
Returns
true if this latitude < other's latitude

Definition at line 201 of file geocoordinate.h.

◆ isSouthOfOrEqualTo()

bool GeoCoordinate::isSouthOfOrEqualTo ( const GeoCoordinate other) const
inline

Test whether this coordinate is south of or at the same latitude as another.

Parameters
otherCoordinate to compare against
Returns
true if this latitude ≤ other's latitude (at configured precision)

Definition at line 191 of file geocoordinate.h.

◆ isValid()

bool GeoCoordinate::isValid ( ) const
inline

Test whether this coordinate represents a valid position.

Returns
true if the coordinate is not empty

Definition at line 247 of file geocoordinate.h.

◆ isWestOf()

bool GeoCoordinate::isWestOf ( const GeoCoordinate other) const

Test whether this coordinate is strictly west of another.

Parameters
otherCoordinate to compare against
Returns
true if this longitude < other's longitude

◆ isWestOfOrEqualTo()

bool GeoCoordinate::isWestOfOrEqualTo ( const GeoCoordinate other) const
inline

Test whether this coordinate is west of or at the same longitude as another.

Parameters
otherCoordinate to compare against
Returns
true if this longitude ≤ other's longitude (at configured precision)

Definition at line 208 of file geocoordinate.h.

◆ latitude()

double GeoCoordinate::latitude ( ) const
inline

Return the latitude in decimal degrees.

Returns
Latitude (negative = south)

Definition at line 103 of file geocoordinate.h.

◆ longitude()

double GeoCoordinate::longitude ( ) const
inline

Return the longitude in decimal degrees.

Returns
Longitude (negative = west)

Definition at line 115 of file geocoordinate.h.

◆ operator!=()

bool GeoCoordinate::operator!= ( const GeoCoordinate other) const
inline

Inequality comparison.

Parameters
otherCoordinate to compare against
Returns
true if coordinates are not equal

Definition at line 97 of file geocoordinate.h.

◆ operator==()

bool GeoCoordinate::operator== ( const GeoCoordinate other) const

Equality comparison at the configured precision.

Parameters
otherCoordinate to compare against
Returns
true if coordinates are equal within the configured precision

◆ precision()

int GeoCoordinate::precision ( ) const
inline

Return the decimal precision used for coordinate comparisons.

Returns
Number of decimal places

Definition at line 139 of file geocoordinate.h.

◆ setAltitude()

void GeoCoordinate::setAltitude ( double  value)
inline

Set the altitude in metres.

Parameters
valueNew altitude value

Definition at line 133 of file geocoordinate.h.

◆ setLatitude()

void GeoCoordinate::setLatitude ( double  value)
inline

Set the latitude in decimal degrees.

Parameters
valueNew latitude value

Definition at line 109 of file geocoordinate.h.

◆ setLongitude()

void GeoCoordinate::setLongitude ( double  value)
inline

Set the longitude in decimal degrees.

Parameters
valueNew longitude value

Definition at line 121 of file geocoordinate.h.

◆ setPrecision()

void GeoCoordinate::setPrecision ( int  value)
inline

Set the decimal precision used for coordinate comparisons.

Parameters
valueNumber of decimal places

Definition at line 145 of file geocoordinate.h.

◆ toString()

QString GeoCoordinate::toString ( CoordinateFormat  format = Degrees,
int  precision = 0 
) const

Format this coordinate as a string.

Parameters
formatOutput format (Degrees or Parsable)
precisionDecimal places for coordinate values (0 = use instance precision)
Returns
Formatted coordinate string

◆ tryParse()

static bool GeoCoordinate::tryParse ( const QString &  stringValue,
GeoCoordinate point 
)
static

Attempt to parse a coordinate string, reporting success.

Parameters
stringValueString to parse
pointOutput receiving the parsed coordinate
Returns
true if parsing succeeded

The documentation for this class was generated from the following file: