Marble

GeoSceneEquirectTileProjection.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Friedrich W. H. Kossebau <kossebau@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "GeoSceneEquirectTileProjection.h"
8
9#include <GeoDataLatLonBox.h>
10
11namespace Marble
12{
13
17
18
19GeoSceneEquirectTileProjection::~GeoSceneEquirectTileProjection()
20{
21}
22
23GeoSceneAbstractTileProjection::Type GeoSceneEquirectTileProjection::type() const
24{
25 return Equirectangular;
26}
27
28
29static inline
30unsigned 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
37static inline
38unsigned int upperBoundTileIndex(qreal baseTileIndex)
39{
40 return (unsigned int)floor(baseTileIndex);
41}
42
43static inline
44qreal baseTileXFromLon(qreal lon, unsigned int tileCount)
45{
46 return 0.5 * (lon / M_PI + 1.0) * tileCount;
47}
48
49static inline
50qreal 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
57static inline
58unsigned 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
68static inline
69unsigned 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
79static inline
80unsigned 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
90static inline
91unsigned 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}
A class that defines a 2D bounding box for geographic data.
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.
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.
GeoSceneEquirectTileProjection()
Construct a new GeoSceneEquirectTileProjection.
GeoDataLatLonBox geoCoordinates(int zoomLevel, int x, int y) const override
QRect tileIndexes(const GeoDataLatLonBox &latLonBox, int zoomLevel) const override
GeoSceneAbstractTileProjection::Type type() const override
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.