Marble

Coordinate.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2011 Dennis Nienhüser <[email protected]>
4 // SPDX-FileCopyrightText: 2021 Torsten Rahn
5 //
6 
7 #include "Coordinate.h"
8 
9 #include "MarbleGlobal.h"
10 
12 using Marble::EARTH_RADIUS;
13 using Marble::DEG2RAD;
14 
15 Coordinate::Coordinate( qreal lon, qreal lat, qreal alt, QObject *parent ) :
16  QObject( parent )
17 {
18  setLongitude( lon );
19  setLatitude( lat );
20  setAltitude( alt );
21 }
22 
24 {
26 }
27 
28 qreal Coordinate::longitude() const
29 {
30  return m_coordinate.longitude( GeoDataCoordinates::Degree );
31 }
32 
33 void Coordinate::setLongitude( qreal lon )
34 {
35  m_coordinate.setLongitude( lon, GeoDataCoordinates::Degree );
36  emit longitudeChanged();
37 }
38 
39 qreal Coordinate::latitude() const
40 {
41  return m_coordinate.latitude( GeoDataCoordinates::Degree );
42 }
43 
44 void Coordinate::setLatitude( qreal lat )
45 {
46  m_coordinate.setLatitude( lat, GeoDataCoordinates::Degree );
47  emit latitudeChanged();
48 }
49 
50 qreal Coordinate::altitude() const
51 {
52  return m_coordinate.altitude();
53 }
54 
55 void Coordinate::setAltitude( qreal alt )
56 {
57  m_coordinate.setAltitude( alt );
58  emit altitudeChanged();
59 }
60 
62 {
63  return m_coordinate;
64 }
65 
67 {
68  m_coordinate = coordinates;
69 }
70 
71 QString Coordinate::toGeoString(Coordinate::Notation notation, int precision) const
72 {
73  return m_coordinate.toString(static_cast<GeoDataCoordinates::Notation>(notation), precision);
74 }
75 
76 qreal Coordinate::distance( qreal longitude, qreal latitude ) const
77 {
78  GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree;
79  GeoDataCoordinates other( longitude, latitude, 0, deg );
80  return EARTH_RADIUS * coordinates().sphericalDistanceTo(other);
81 }
82 
83 qreal Coordinate::bearing( qreal longitude, qreal latitude ) const
84 {
85  qreal deltaLon = longitude * DEG2RAD - m_coordinate.longitude();
86  qreal y = sin( deltaLon ) * cos( latitude * DEG2RAD );
87  qreal x = cos( m_coordinate.latitude() ) * sin( latitude * DEG2RAD ) -
88  sin( m_coordinate.latitude() ) * cos( latitude * DEG2RAD ) * cos( deltaLon );
89  return Marble::RAD2DEG * atan2( y, x );
90 }
91 
92 bool Coordinate::operator == ( const Coordinate &other ) const
93 {
94  return m_coordinate == other.m_coordinate;
95 }
96 
97 bool Coordinate::operator != ( const Coordinate &other ) const
98 {
99  return !operator == ( other );
100 }
101 
102 Coordinate::Notation Coordinate::defaultNotation()
103 {
104  return static_cast<Coordinate::Notation>(GeoDataCoordinates::defaultNotation());
105 }
106 
107 void Coordinate::setDefaultNotation(Coordinate::Notation defaultNotation)
108 {
109  if (GeoDataCoordinates::defaultNotation() == static_cast<GeoDataCoordinates::Notation>(defaultNotation))
110  return;
111  GeoDataCoordinates::setDefaultNotation(static_cast<GeoDataCoordinates::Notation>(defaultNotation));
112  emit defaultNotationChanged(defaultNotation);
113 }
114 
115 #include "moc_Coordinate.cpp"
QString toString() const
return a string representation of the coordinate this is a convenience function which uses the defaul...
A 3d point representation.
Q_INVOKABLE qreal bearing(qreal longitude, qreal latitude) const
Bearing (in degree) to the given coordinate.
Definition: Coordinate.cpp:83
void setLongitude(qreal lon, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
void setAltitude(qreal alt)
Change the altitude of the coordinate.
Definition: Coordinate.cpp:55
qreal longitude(GeoDataCoordinates::Unit unit) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
void setLatitude(qreal lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
qreal altitude() const
return the altitude of the Point in meters
Marble::GeoDataCoordinates coordinates() const
Change the altitude of the coordinate.
Definition: Coordinate.cpp:61
qreal latitude(GeoDataCoordinates::Unit unit) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Coordinate(qreal lon=0.0, qreal lat=0.0, qreal altitude=0.0, QObject *parent=nullptr)
Constructor.
Definition: Coordinate.cpp:15
Q_INVOKABLE qreal distance(qreal longitude, qreal latitude) const
Distance (in meter) to the given coordinate.
Definition: Coordinate.cpp:76
qreal sphericalDistanceTo(const GeoDataCoordinates &other) const
This method calculates the shortest distance between two points on a sphere.
void setLongitude(qreal lon)
Change the longitude of the coordinate.
Definition: Coordinate.cpp:33
void setLatitude(qreal lat)
Change the latitude of the coordinate.
Definition: Coordinate.cpp:44
void setAltitude(const qreal altitude)
set the altitude of the Point in meters
void setCoordinates(const Marble::GeoDataCoordinates &coordinates)
Change all coordinates at once.
Definition: Coordinate.cpp:66
Represents a coordinate with the properties of a name and coordinates.
Definition: Coordinate.h:18
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:51:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.