GeoDesk for C++
Fast and storage-efficient spatial database engine for OpenStreetMap features
Loading...
Searching...
No Matches
geodesk::Mercator Class Reference

Methods for working with Mercator-projected coordinates. More...

#include <Mercator.h>

Static Public Member Functions

static int32_t xFromLon (double lon) noexcept
 Converts longitude (in WGS-84 degrees) to a Mercator X-coordinate.
 
static int32_t xFromLon100nd (int lon) noexcept
 Converts WGS-84 longitude (in 100-nanodegree increments) to a Mercator X-coordinate.
 
static int32_t yFromLat (double lat) noexcept
 Converts latitude (in WGS-84 degrees) to a Mercator Y-coordinate.
 
static int32_t yFromLat100nd (int lat) noexcept
 Converts WGS-84 latitude (in 100-nanodegree increments) to a Mercator Y-coordinate.
 
static double roundTo100nd (double deg) noexcept
 
static double lonFromX (double x) noexcept
 Converts a Mercator X-coordinate to longitude (in WGS-84 degrees).
 
static double roundedLonFromX (double x) noexcept
 Converts a Mercator X-coordinate to longitude (in WGS-84 degrees, rounded to 7 digits of precision).
 
static double latFromY (double y) noexcept
 Converts a Mercator Y-coordinate to latitude (in WGS-84 degrees).
 
static double roundedLatFromY (double y) noexcept
 Converts a Mercator Y-coordinate to latitude (in WGS-84 degrees, rounded to 7 digits of precision).
 
static double scale (double y) noexcept
 Calculates the scaling factor for the given Y-coordinate.
 
static double metersPerUnitAtY (double y) noexcept
 Calculates the number of meters each Mercator unit represents at the given Y-coordinate.
 
static double unitsFromMeters (double meters, double atY) noexcept
 Calculates the number of Mercator units represented by the given distance (in meters), at the given Y-coordinate.
 

Static Public Attributes

static constexpr double MAP_WIDTH = 4'294'967'294.9999
 
static constexpr double EARTH_CIRCUMFERENCE = 40'075'016.68558
 
static constexpr double MIN_LAT = -85.0511288
 
static constexpr double MAX_LAT = 85.0511287
 
static constexpr int32_t MIN_LAT_100ND = -850511288
 
static constexpr int32_t MAX_LAT_100ND = 850511287
 
static constexpr int32_t MIN_Y = INT_MIN
 
static constexpr int32_t MAX_Y = INT_MAX - 1
 

Detailed Description

Methods for working with Mercator-projected coordinates.

GeoDesk uses a Pseudo-Mercator projection that projects coordinates onto a square Cartesian plane 2^32 units wide/tall (in essence, the value range fully uses a 32-bit signed int). This projection is compatible with Web Mercator EPSG:3857, except that instead of meters at the Equator, it uses a made-up unit called "imp" ("integer, Mercator-projected").

Member Function Documentation

◆ latFromY()

static double geodesk::Mercator::latFromY ( double y)
inlinestaticnoexcept

Converts a Mercator Y-coordinate to latitude (in WGS-84 degrees).

◆ lonFromX()

static double geodesk::Mercator::lonFromX ( double x)
inlinestaticnoexcept

Converts a Mercator X-coordinate to longitude (in WGS-84 degrees).

◆ metersPerUnitAtY()

static double geodesk::Mercator::metersPerUnitAtY ( double y)
inlinestaticnoexcept

Calculates the number of meters each Mercator unit represents at the given Y-coordinate.

The Y-coordinate must be between INT_MIN and INT_MAX (inclusive), or the result will be undefined.

Parameters
yvalid Y-coordinate

◆ roundedLatFromY()

static double geodesk::Mercator::roundedLatFromY ( double y)
inlinestaticnoexcept

Converts a Mercator Y-coordinate to latitude (in WGS-84 degrees, rounded to 7 digits of precision).

◆ roundedLonFromX()

static double geodesk::Mercator::roundedLonFromX ( double x)
inlinestaticnoexcept

Converts a Mercator X-coordinate to longitude (in WGS-84 degrees, rounded to 7 digits of precision).

◆ roundTo100nd()

static double geodesk::Mercator::roundTo100nd ( double deg)
inlinestaticnoexcept

◆ scale()

static double geodesk::Mercator::scale ( double y)
inlinestaticnoexcept

Calculates the scaling factor for the given Y-coordinate.

This factor is 1 at the equator and progressively increases towards the polar regions, and is used to compensate for the distortion introduced by the Mercator projection.

◆ unitsFromMeters()

static double geodesk::Mercator::unitsFromMeters ( double meters,
double atY )
inlinestaticnoexcept

Calculates the number of Mercator units represented by the given distance (in meters), at the given Y-coordinate.

The Y-coordinate must be between INT_MIN and INT_MAX (inclusive), or the result will be undefined.

Parameters
metersdistance in meters
atYvalid Y-coordinate

◆ xFromLon()

static int32_t geodesk::Mercator::xFromLon ( double lon)
inlinestaticnoexcept

Converts longitude (in WGS-84 degrees) to a Mercator X-coordinate.

◆ xFromLon100nd()

static int32_t geodesk::Mercator::xFromLon100nd ( int lon)
inlinestaticnoexcept

Converts WGS-84 longitude (in 100-nanodegree increments) to a Mercator X-coordinate.

◆ yFromLat()

static int32_t geodesk::Mercator::yFromLat ( double lat)
inlinestaticnoexcept

Converts latitude (in WGS-84 degrees) to a Mercator Y-coordinate.

◆ yFromLat100nd()

static int32_t geodesk::Mercator::yFromLat100nd ( int lat)
inlinestaticnoexcept

Converts WGS-84 latitude (in 100-nanodegree increments) to a Mercator Y-coordinate.

Member Data Documentation

◆ EARTH_CIRCUMFERENCE

double geodesk::Mercator::EARTH_CIRCUMFERENCE = 40'075'016.68558
staticconstexpr

◆ MAP_WIDTH

double geodesk::Mercator::MAP_WIDTH = 4'294'967'294.9999
staticconstexpr

◆ MAX_LAT

double geodesk::Mercator::MAX_LAT = 85.0511287
staticconstexpr

◆ MAX_LAT_100ND

int32_t geodesk::Mercator::MAX_LAT_100ND = 850511287
staticconstexpr

◆ MAX_Y

int32_t geodesk::Mercator::MAX_Y = INT_MAX - 1
staticconstexpr

◆ MIN_LAT

double geodesk::Mercator::MIN_LAT = -85.0511288
staticconstexpr

◆ MIN_LAT_100ND

int32_t geodesk::Mercator::MIN_LAT_100ND = -850511288
staticconstexpr

◆ MIN_Y

int32_t geodesk::Mercator::MIN_Y = INT_MIN
staticconstexpr

The documentation for this class was generated from the following file: