1#ifndef OSMIUM_GEOM_MERCATOR_PROJECTION_HPP
2#define OSMIUM_GEOM_MERCATOR_PROJECTION_HPP
49 constexpr double earth_radius_for_epsg3857 = 6378137.0;
50 constexpr double max_coordinate_epsg3857 = 20037508.34;
52 constexpr inline double lon_to_x(
double lon)
noexcept {
53 return earth_radius_for_epsg3857 *
deg_to_rad(lon);
56 inline double lat_to_y_with_tan(
double lat) {
60#ifdef OSMIUM_USE_SLOW_MERCATOR_PROJECTION
61 inline double lat_to_y(
double lat) {
62 return lat_to_y_with_tan(lat);
69 inline double lat_to_y(
double lat) {
70 if (lat < -78.0 || lat > 78.0) {
71 return lat_to_y_with_tan(lat);
74 return earth_radius_for_epsg3857 *
75 ((((((((((-3.1112583378460085319e-23 * lat +
76 2.0465852743943268009e-19) * lat +
77 6.4905282018672673884e-18) * lat +
78 -1.9685447939983315591e-14) * lat +
79 -2.2022588158115104182e-13) * lat +
80 5.1617537365509453239e-10) * lat +
81 2.5380136069803016519e-9) * lat +
82 -5.1448323697228488745e-6) * lat +
83 -9.4888671473357768301e-6) * lat +
84 1.7453292518154191887e-2) * lat)
86 ((((((((((-1.9741136066814230637e-22 * lat +
87 -1.258514031244679556e-20) * lat +
88 4.8141483273572351796e-17) * lat +
89 8.6876090870176172185e-16) * lat +
90 -2.3298743439377541768e-12) * lat +
91 -1.9300094785736130185e-11) * lat +
92 4.3251609106864178231e-8) * lat +
93 1.7301944508516974048e-7) * lat +
94 -3.4554675198786337842e-4) * lat +
95 -5.4367203601085991108e-4) * lat + 1.0);
99 constexpr inline double x_to_lon(
double x) {
100 return rad_to_deg(x) / earth_radius_for_epsg3857;
103 inline double y_to_lat(
double y) {
124 return Coordinates{detail::lon_to_x(c.
x), detail::lat_to_y(c.
y)};
135 return Coordinates{detail::x_to_lon(c.
x), detail::y_to_lat(c.
y)};
161 return Coordinates{detail::lon_to_x(location.
lon()), detail::lat_to_y(location.
lat())};
169 return "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs";
Definition: location.hpp:271
double lon() const
Definition: location.hpp:400
double lat() const
Definition: location.hpp:419
Definition: mercator_projection.hpp:142
MercatorProjection()
Definition: mercator_projection.hpp:150
static int epsg() noexcept
Definition: mercator_projection.hpp:164
static std::string proj_string() noexcept
Definition: mercator_projection.hpp:168
Coordinates operator()(osmium::Location location) const
Definition: mercator_projection.hpp:160
Coordinates lonlat_to_mercator(const Coordinates &c)
Definition: mercator_projection.hpp:123
constexpr double deg_to_rad(double degree) noexcept
Convert angle from degrees to radians.
Definition: util.hpp:64
constexpr double rad_to_deg(double radians) noexcept
Convert angle from radians to degrees.
Definition: util.hpp:69
Coordinates mercator_to_lonlat(const Coordinates &c)
Definition: mercator_projection.hpp:134
constexpr double MERCATOR_MAX_LAT
Definition: mercator_projection.hpp:113
constexpr double PI
Definition: util.hpp:61
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
Definition: coordinates.hpp:48
double y
Definition: coordinates.hpp:51
double x
Definition: coordinates.hpp:50