QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TileMath.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10#pragma once
11
12#include <QtCore/QDebug>
13#include <QtCore/QHashFunctions>
14#include <QtCore/QMetaType>
15#include <QtCore/QPointF>
16#include <QtPositioning/QGeoCoordinate>
17
26namespace TileMath {
27
28constexpr double kEarthRadius = 6378137.0;
29constexpr double kMaxLatitude = 85.05112878;
30constexpr int kMinZoom = 0;
31constexpr int kMaxZoom = 23;
32constexpr int kTilePixels = 256;
33
34struct TileKey
35{
36 int x = 0;
37 int y = 0;
38 int zoom = 0;
39
40 bool operator==(const TileKey& other) const { return (x == other.x) && (y == other.y) && (zoom == other.zoom); }
41};
42
43inline size_t qHash(const TileKey& key, size_t seed = 0)
44{
45 return ::qHashMulti(seed, key.x, key.y, key.zoom);
46}
47
49QDebug operator<<(QDebug debug, const TileKey& key);
50
51} // namespace TileMath
52
54
55namespace TileMath {
56
58double worldSize();
59
61bool isValidKey(const TileKey& key);
62
64QPointF geoToWorld(const QGeoCoordinate& coord);
65
67QGeoCoordinate worldToGeo(const QPointF& world);
68
73double mercatorScale(double latitude);
74
76double tileSpanAtZoom(int zoom);
77
79QPointF tileMinCorner(const TileKey& key);
80
82TileKey tileForWorld(const QPointF& world, int zoom);
83
85double metersPerPixelAtZoom(int zoom);
86
88int zoomForMetersPerPixel(double metersPerPixel);
89
90} // namespace TileMath
constexpr double kMaxLatitude
Mercator latitude clamp (deg)
Definition TileMath.h:29
size_t qHash(const TileKey &key, size_t seed=0)
Definition TileMath.h:43
constexpr int kTilePixels
Nominal tile edge used for meters-per-pixel.
Definition TileMath.h:32
double worldSize()
Full mercator world extent (2*pi*R) in world meters.
Definition TileMath.cc:18
constexpr double kEarthRadius
WGS84 equatorial radius (m)
Definition TileMath.h:28
QPointF geoToWorld(const QGeoCoordinate &coord)
Geo -> world meters. Latitude is clamped to +/-kMaxLatitude.
Definition TileMath.cc:23
QPointF tileMinCorner(const TileKey &key)
South-west (minimum x/y) corner of a tile in world meters.
Definition TileMath.cc:58
constexpr int kMaxZoom
Definition TileMath.h:31
bool isValidKey(const TileKey &key)
True if zoom is within [kMinZoom, kMaxZoom] and x/y address a tile at that zoom.
Definition TileMath.cc:44
QDebug operator<<(QDebug debug, const TileKey &key)
Streams as slippy "zoom/x/y" notation for logging.
Definition TileMath.cc:11
constexpr int kMinZoom
Definition TileMath.h:30
int zoomForMetersPerPixel(double metersPerPixel)
Smallest zoom whose resolution is at least as fine as metersPerPixel (clamped to valid range)
Definition TileMath.cc:89
double mercatorScale(double latitude)
Definition TileMath.cc:38
double metersPerPixelAtZoom(int zoom)
World meters spanned by one pixel of a kTilePixels tile at zoom (equator)
Definition TileMath.cc:84
QGeoCoordinate worldToGeo(const QPointF &world)
World meters -> geo (altitude 0)
Definition TileMath.cc:31
double tileSpanAtZoom(int zoom)
Edge length of one tile at zoom, in world meters.
Definition TileMath.cc:53
TileKey tileForWorld(const QPointF &world, int zoom)
Tile containing a world point. World coordinates are clamped to the world extent.
Definition TileMath.cc:67
Q_DECLARE_METATYPE(satellite_info_s)
bool operator==(const TileKey &other) const
Definition TileMath.h:40