• Skip to content
  • Skip to link menu
Brand

API Documentation

  1. KDE API Reference
  2. Marble
  • KDE Home
  • Contact Us

Quick Links

Skip menu "Marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Related Pages

Class Picker

About

Marble framework, a library for maps, virtual globes and world atlases

Maintainers
Torsten Rahn,
Dennis Nienhüser
Supported platforms
Android, Linux, MacOSX, Windows
Community
IRC: #marble on Freenode
Mailing list: marble-devel
Use with CMake
find_package(Marble)
target_link_libraries(yourapp Marble)
Use with QMake
QT += Marble 
Clone
git clone git://anongit.kde.org/marble.git
Browse source
Marble on cgit.kde.org

Marble

  • kde
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • projections
LambertAzimuthalProjection.cpp
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2014 Torsten Rahn <[email protected]>
9 //
10 
11 // Local
12 #include "LambertAzimuthalProjection.h"
13 #include "AbstractProjection_p.h"
14 
15 #include "MarbleDebug.h"
16 
17 // Marble
18 #include "ViewportParams.h"
19 #include "GeoDataPoint.h"
20 #include "GeoDataLineString.h"
21 #include "GeoDataCoordinates.h"
22 #include "MarbleGlobal.h"
23 #include "AzimuthalProjection_p.h"
24 
25 #include <QIcon>
26 #include <qmath.h>
27 
28 #define SAFE_DISTANCE
29 
30 namespace Marble
31 {
32 
33 class LambertAzimuthalProjectionPrivate : public AzimuthalProjectionPrivate
34 {
35  public:
36  explicit LambertAzimuthalProjectionPrivate( LambertAzimuthalProjection * parent );
37 
38  Q_DECLARE_PUBLIC( LambertAzimuthalProjection )
39 };
40 
41 LambertAzimuthalProjection::LambertAzimuthalProjection()
42  : AzimuthalProjection( new LambertAzimuthalProjectionPrivate( this ) )
43 {
44  setMinLat( minValidLat() );
45  setMaxLat( maxValidLat() );
46 }
47 
48 LambertAzimuthalProjection::LambertAzimuthalProjection( LambertAzimuthalProjectionPrivate *dd )
49  : AzimuthalProjection( dd )
50 {
51  setMinLat( minValidLat() );
52  setMaxLat( maxValidLat() );
53 }
54 
55 LambertAzimuthalProjection::~LambertAzimuthalProjection()
56 {
57 }
58 
59 
60 LambertAzimuthalProjectionPrivate::LambertAzimuthalProjectionPrivate( LambertAzimuthalProjection * parent )
61  : AzimuthalProjectionPrivate( parent )
62 {
63 }
64 
65 QString LambertAzimuthalProjection::name() const
66 {
67  return QObject::tr( "Lambert Azimuthal Equal-Area" );
68 }
69 
70 QString LambertAzimuthalProjection::description() const
71 {
72  return QObject::tr( "<p><b>Lambert Azimuthal Equal-Area Projection</b></p><p>Applications: Used in structural geology to plot directional data.</p>" );
73 }
74 
75 QIcon LambertAzimuthalProjection::icon() const
76 {
77  return QIcon(QStringLiteral(":/icons/map-globe.png"));
78 }
79 
80 qreal LambertAzimuthalProjection::clippingRadius() const
81 {
82  return 1;
83 }
84 
85 bool LambertAzimuthalProjection::screenCoordinates( const GeoDataCoordinates &coordinates,
86  const ViewportParams *viewport,
87  qreal &x, qreal &y, bool &globeHidesPoint ) const
88 {
89  const qreal lambda = coordinates.longitude();
90  const qreal phi = coordinates.latitude();
91  const qreal lambdaPrime = viewport->centerLongitude();
92  const qreal phi1 = viewport->centerLatitude();
93 
94  qreal cosC = qSin( phi1 ) * qSin( phi ) + qCos( phi1 ) * qCos( phi ) * qCos( lambda - lambdaPrime );
95  // Prevent division by zero
96  if (cosC <= 0) {
97  globeHidesPoint = true;
98  return false;
99  }
100 
101  qreal k = qSqrt(2 / (1 + cosC));
102 
103  // Let (x, y) be the position on the screen of the placemark..
104  x = ( qCos( phi ) * qSin( lambda - lambdaPrime ) ) * k;
105  y = ( qCos( phi1 ) * qSin( phi ) - qSin( phi1 ) * qCos( phi ) * qCos( lambda - lambdaPrime ) ) * k;
106 
107  x *= viewport->radius() / qSqrt(2);
108  y *= viewport->radius() / qSqrt(2);
109 
110  const qint64 radius = clippingRadius() * viewport->radius();
111 
112  if (x*x + y*y > radius * radius) {
113  globeHidesPoint = true;
114  return false;
115  }
116 
117  globeHidesPoint = false;
118 
119  x += viewport->width() / 2;
120  y = viewport->height() / 2 - y;
121 
122  // Skip placemarks that are outside the screen area
123  return !(x < 0 || x >= viewport->width() || y < 0 || y >= viewport->height());
124 }
125 
126 bool LambertAzimuthalProjection::screenCoordinates( const GeoDataCoordinates &coordinates,
127  const ViewportParams *viewport,
128  qreal *x, qreal &y,
129  int &pointRepeatNum,
130  const QSizeF& size,
131  bool &globeHidesPoint ) const
132 {
133  pointRepeatNum = 0;
134  globeHidesPoint = false;
135 
136  bool visible = screenCoordinates( coordinates, viewport, *x, y, globeHidesPoint );
137 
138  // Skip placemarks that are outside the screen area
139  if ( *x + size.width() / 2.0 < 0.0 || *x >= viewport->width() + size.width() / 2.0
140  || y + size.height() / 2.0 < 0.0 || y >= viewport->height() + size.height() / 2.0 )
141  {
142  return false;
143  }
144 
145  // This projection doesn't have any repetitions,
146  // so the number of screen points referring to the geopoint is one.
147  pointRepeatNum = 1;
148  return visible;
149 }
150 
151 
152 bool LambertAzimuthalProjection::geoCoordinates( const int x, const int y,
153  const ViewportParams *viewport,
154  qreal& lon, qreal& lat,
155  GeoDataCoordinates::Unit unit ) const
156 {
157  const qint64 radius = viewport->radius();
158  // Calculate how many degrees are being represented per pixel.
159  const qreal centerLon = viewport->centerLongitude();
160  const qreal centerLat = viewport->centerLatitude();
161  const qreal rx = ( - viewport->width() / 2 + x );
162  const qreal ry = ( viewport->height() / 2 - y );
163  const qreal p = qMax( qSqrt( rx*rx + ry*ry ), qreal(0.0001) ); // ensure we don't divide by zero
164  const qreal c = 2 * qAsin( p / (qSqrt(2) * radius) );
165  const qreal sinc = qSin(c);
166 
167  lon = centerLon + qAtan2( rx*sinc , ( p*qCos( centerLat )*qCos( c ) - ry*qSin( centerLat )*sinc ) );
168 
169  while ( lon < -M_PI ) lon += 2 * M_PI;
170  while ( lon > M_PI ) lon -= 2 * M_PI;
171 
172  lat = qAsin( qCos(c)*qSin(centerLat) + (ry*sinc*qCos(centerLat))/p );
173 
174  if ( unit == GeoDataCoordinates::Degree ) {
175  lon *= RAD2DEG;
176  lat *= RAD2DEG;
177  }
178 
179  return true;
180 }
181 
182 }
Marble::GeoDataCoordinates::Unit
Unit
enum used constructor to specify the units used
Definition: GeoDataCoordinates.h:57
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:45
Marble
Binds a QML item to a specific geodetic location in screen coordinates.
Definition: AbstractDataPlugin.cpp:27
Marble::AbstractProjection::minValidLat
virtual qreal minValidLat() const
Returns the minimum (southern) latitude that is mathematically defined and reasonable.
Definition: AbstractProjection.cpp:101
Marble::AzimuthalProjection
A base class for the Gnomonic and Orthographic (Globe) projections in Marble.
Definition: AzimuthalProjection.h:30
Marble::LambertAzimuthalProjection
A class to implement the spherical projection used by the "Globe" view.
Definition: LambertAzimuthalProjection.h:28
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::LambertAzimuthalProjection::LambertAzimuthalProjection
LambertAzimuthalProjection()
Construct a new LambertAzimuthalProjection.
Definition: LambertAzimuthalProjection.cpp:41
Marble::LambertAzimuthalProjection::screenCoordinates
bool screenCoordinates(const GeoDataCoordinates &coordinates, const ViewportParams *params, qreal &x, qreal &y, bool &globeHidesPoint) const override
Get the screen coordinates corresponding to geographical coordinates in the map.
Definition: LambertAzimuthalProjection.cpp:85
Marble::LambertAzimuthalProjection::description
QString description() const override
Returns a short user description of the projection that can be used in tooltips or dialogs...
Definition: LambertAzimuthalProjection.cpp:70
Marble::LambertAzimuthalProjection::geoCoordinates
bool geoCoordinates(const int x, const int y, const ViewportParams *params, qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Degree) const override
Get the earth coordinates corresponding to a pixel in the map.
Definition: LambertAzimuthalProjection.cpp:152
QString
Marble::AbstractProjection::maxValidLat
virtual qreal maxValidLat() const
Returns the maximum (northern) latitude that is mathematically defined and reasonable.
Definition: AbstractProjection.cpp:79
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:46
Marble::LambertAzimuthalProjection::icon
QIcon icon() const override
Returns an icon for the projection.
Definition: LambertAzimuthalProjection.cpp:75
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::LambertAzimuthalProjection::name
QString name() const override
Returns the user-visible name of the projection.
Definition: LambertAzimuthalProjection.cpp:65
QSizeF
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:204
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:221
QSizeF::height
qreal height() const
QSizeF::width
qreal width() const
QIcon
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Thu Dec 5 2019 04:18:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal