QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TileMath Namespace Reference

Classes

struct  TileKey
 

Functions

QDebug operator<< (QDebug debug, const TileKey &key)
 Streams as slippy "zoom/x/y" notation for logging.
 
double worldSize ()
 Full mercator world extent (2*pi*R) in world meters.
 
QPointF geoToWorld (const QGeoCoordinate &coord)
 Geo -> world meters. Latitude is clamped to +/-kMaxLatitude.
 
QGeoCoordinate worldToGeo (const QPointF &world)
 World meters -> geo (altitude 0)
 
double mercatorScale (double latitude)
 
bool isValidKey (const TileKey &key)
 True if zoom is within [kMinZoom, kMaxZoom] and x/y address a tile at that zoom.
 
double tileSpanAtZoom (int zoom)
 Edge length of one tile at zoom, in world meters.
 
QPointF tileMinCorner (const TileKey &key)
 South-west (minimum x/y) corner of a tile in world meters.
 
TileKey tileForWorld (const QPointF &world, int zoom)
 Tile containing a world point. World coordinates are clamped to the world extent.
 
double metersPerPixelAtZoom (int zoom)
 World meters spanned by one pixel of a kTilePixels tile at zoom (equator)
 
int zoomForMetersPerPixel (double metersPerPixel)
 Smallest zoom whose resolution is at least as fine as metersPerPixel (clamped to valid range)
 
size_t qHash (const TileKey &key, size_t seed=0)
 

Variables

constexpr double kEarthRadius = 6378137.0
 WGS84 equatorial radius (m)
 
constexpr double kMaxLatitude = 85.05112878
 Mercator latitude clamp (deg)
 
constexpr int kMinZoom = 0
 
constexpr int kMaxZoom = 23
 
constexpr int kTilePixels = 256
 Nominal tile edge used for meters-per-pixel.
 

Detailed Description

Web Mercator (EPSG:3857) projection and slippy-tile math for the GeoMap engine.

World space: mercator meters, origin at (lon 0, equator), x east, y north, z up. Note mercator meters are true meters only at the equator (scale grows with 1/cos(lat)); the rendered scene is self-consistent but distances are not geodesic.

Tile addressing: standard slippy scheme — tile (0,0) is the north-west corner, x grows east, y grows south.

Function Documentation

◆ geoToWorld()

QPointF TileMath::geoToWorld ( const QGeoCoordinate &  coord)

Geo -> world meters. Latitude is clamped to +/-kMaxLatitude.

Definition at line 23 of file TileMath.cc.

References kEarthRadius, and kMaxLatitude.

Referenced by GeoMapCamera::centerForCoordinateAtScreenPoint(), GeoScene::scenePositionFor(), GeoScene::screenPositionFor(), GeoMapCamera::setCenter(), and SurfacePatchModel::terrainHeightAt().

◆ isValidKey()

◆ mercatorScale()

double TileMath::mercatorScale ( double  latitude)

Mercator scale factor 1/cos(lat): how many mercator meters one true ground meter spans at the given latitude (clamped to +/-kMaxLatitude). Used to convert true-meter heights/altitudes into mercator scene units so vertical and horizontal geometry stay consistent away from the equator.

Definition at line 38 of file TileMath.cc.

References kMaxLatitude.

Referenced by GeoScene::verticalScale().

◆ metersPerPixelAtZoom()

double TileMath::metersPerPixelAtZoom ( int  zoom)

World meters spanned by one pixel of a kTilePixels tile at zoom (equator)

Definition at line 84 of file TileMath.cc.

References kTilePixels, and tileSpanAtZoom().

Referenced by zoomForMetersPerPixel().

◆ operator<<()

QDebug TileMath::operator<< ( QDebug  debug,
const TileKey key 
)

Streams as slippy "zoom/x/y" notation for logging.

Definition at line 11 of file TileMath.cc.

References TileMath::TileKey::x, TileMath::TileKey::y, and TileMath::TileKey::zoom.

◆ qHash()

size_t TileMath::qHash ( const TileKey key,
size_t  seed = 0 
)
inline

Definition at line 43 of file TileMath.h.

References TileMath::TileKey::x, TileMath::TileKey::y, and TileMath::TileKey::zoom.

◆ tileForWorld()

TileKey TileMath::tileForWorld ( const QPointF &  world,
int  zoom 
)

Tile containing a world point. World coordinates are clamped to the world extent.

Definition at line 67 of file TileMath.cc.

References kMaxZoom, kMinZoom, tileSpanAtZoom(), worldSize(), TileMath::TileKey::x, TileMath::TileKey::y, and TileMath::TileKey::zoom.

Referenced by HeightField::heightAt().

◆ tileMinCorner()

QPointF TileMath::tileMinCorner ( const TileKey key)

◆ tileSpanAtZoom()

double TileMath::tileSpanAtZoom ( int  zoom)

◆ worldSize()

double TileMath::worldSize ( )

Full mercator world extent (2*pi*R) in world meters.

Definition at line 18 of file TileMath.cc.

References kEarthRadius.

Referenced by GeoMapCamera::distanceForZoomLevel(), tileForWorld(), tileMinCorner(), and tileSpanAtZoom().

◆ worldToGeo()

QGeoCoordinate TileMath::worldToGeo ( const QPointF &  world)

World meters -> geo (altitude 0)

Definition at line 31 of file TileMath.cc.

References kEarthRadius.

Referenced by SurfaceAnalysis::analyze(), GeoMapCamera::center(), GeoMapCamera::centerForCoordinateAtScreenPoint(), and GeoScene::verticalScale().

◆ zoomForMetersPerPixel()

int TileMath::zoomForMetersPerPixel ( double  metersPerPixel)

Smallest zoom whose resolution is at least as fine as metersPerPixel (clamped to valid range)

Definition at line 89 of file TileMath.cc.

References kMaxZoom, kMinZoom, and metersPerPixelAtZoom().

Variable Documentation

◆ kEarthRadius

constexpr double TileMath::kEarthRadius = 6378137.0
constexpr

WGS84 equatorial radius (m)

Definition at line 28 of file TileMath.h.

Referenced by geoToWorld(), worldSize(), and worldToGeo().

◆ kMaxLatitude

constexpr double TileMath::kMaxLatitude = 85.05112878
constexpr

Mercator latitude clamp (deg)

Definition at line 29 of file TileMath.h.

Referenced by geoToWorld(), and mercatorScale().

◆ kMaxZoom

constexpr int TileMath::kMaxZoom = 23
constexpr

◆ kMinZoom

constexpr int TileMath::kMinZoom = 0
constexpr

◆ kTilePixels

constexpr int TileMath::kTilePixels = 256
constexpr

Nominal tile edge used for meters-per-pixel.

Definition at line 32 of file TileMath.h.

Referenced by GeoMapCamera::distanceForZoomLevel(), and metersPerPixelAtZoom().