Marble

GeoSceneEquirectTileProjection.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Friedrich W. H. Kossebau <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "GeoSceneEquirectTileProjection.h"
8 
9 #include <GeoDataLatLonBox.h>
10 
11 namespace Marble
12 {
13 
15 {
16 }
17 
18 
19 GeoSceneEquirectTileProjection::~GeoSceneEquirectTileProjection()
20 {
21 }
22 
23 GeoSceneAbstractTileProjection::Type GeoSceneEquirectTileProjection::type() const
24 {
25  return Equirectangular;
26 }
27 
28 
29 static inline
30 unsigned int lowerBoundTileIndex(qreal baseTileIndex)
31 {
32  const qreal floorBaseTileIndex = floor(baseTileIndex);
33  unsigned int tileIndex = static_cast<unsigned int>(floorBaseTileIndex);
34  return (baseTileIndex == floorBaseTileIndex) ? tileIndex-1 : tileIndex;
35 }
36 
37 static inline
38 unsigned int upperBoundTileIndex(qreal baseTileIndex)
39 {
40  return (unsigned int)floor(baseTileIndex);
41 }
42 
43 static inline
44 qreal baseTileXFromLon(qreal lon, unsigned int tileCount)
45 {
46  return 0.5 * (lon / M_PI + 1.0) * tileCount;
47 }
48 
49 static inline
50 qreal baseTileYFromLat(qreal lat, unsigned int tileCount)
51 {
52  return (0.5 - lat / M_PI) * tileCount;
53 }
54 
55 
56 // on tile borders selects the tile to the east
57 static inline
58 unsigned int eastBoundTileXFromLon(qreal lon, unsigned int tileCount)
59 {
60  // special casing tile-map end
61  if (lon == M_PI) {
62  return 0;
63  }
64  return upperBoundTileIndex(baseTileXFromLon(lon, tileCount));
65 }
66 
67 // on tile borders selects the tile to the west
68 static inline
69 unsigned int westBoundTileXFromLon(qreal lon, unsigned int tileCount)
70 {
71  // special casing tile-map end
72  if (lon == -M_PI) {
73  return tileCount-1;
74  }
75  return lowerBoundTileIndex(baseTileXFromLon(lon, tileCount));
76 }
77 
78 // on tile borders selects the tile to the south
79 static inline
80 unsigned int southBoundTileYFromLat(qreal lat, unsigned int tileCount)
81 {
82  // special casing tile-map end
83  if (lat == -M_PI*0.5) {
84  return 0;
85  }
86  return upperBoundTileIndex(baseTileYFromLat(lat, tileCount));
87 }
88 
89 // on tile borders selects the tile to the north
90 static inline
91 unsigned int northBoundTileYFromLat(qreal lat, unsigned int tileCount)
92 {
93  // special casing tile-map end
94  if (lat == M_PI*0.5) {
95  return tileCount-1;
96  }
97  return lowerBoundTileIndex(baseTileYFromLat(lat, tileCount));
98 }
99 
100 
102 {
103  const unsigned int xTileCount = (1 << zoomLevel) * levelZeroColumns();
104 
105  const int westX = eastBoundTileXFromLon(latLonBox.west(), xTileCount);
106  const int eastX = westBoundTileXFromLon(latLonBox.east(), xTileCount);
107 
108  const unsigned int yTileCount = (1 << zoomLevel) * levelZeroRows();
109 
110  const int northY = southBoundTileYFromLat(latLonBox.north(), yTileCount);
111  const int southY = northBoundTileYFromLat(latLonBox.south(), yTileCount);
112 
113  return QRect(QPoint(westX, northY), QPoint(eastX, southY));
114 }
115 
117 {
118  const qreal radiusX = (1 << zoomLevel) * levelZeroColumns() / 2.0;
119  const qreal radiusY = (1 << zoomLevel) * levelZeroRows() / 2.0;
120 
121  const qreal west = (x - radiusX) / radiusX * M_PI;
122  const qreal north = (radiusY - y) / radiusY * M_PI / 2.0;
123 
124  const qreal east = ((x + 1) - radiusX) / radiusX * M_PI;
125  const qreal south = (radiusY - (y + 1)) / radiusY * M_PI / 2.0;
126 
127  return GeoDataLatLonBox(north, south, east, west);
128 }
129 
130 }
Binds a QML item to a specific geodetic location in screen coordinates.
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
QRect tileIndexes(const GeoDataLatLonBox &latLonBox, int zoomLevel) const override
GeoDataLatLonBox geoCoordinates(int zoomLevel, int x, int y) const override
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
GeoSceneAbstractTileProjection::Type type() const override
A class that defines a 2D bounding box for geographic data.
GeoSceneEquirectTileProjection()
Construct a new GeoSceneEquirectTileProjection.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jan 22 2022 23:11:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.