Skip to content

Commit

Permalink
Add webmerc projection
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Apr 7, 2018
1 parent 65d294e commit 646cfa0
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/source/operations/projections/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Projections map the spherical 3D space to a flat 2D space.
wag5
wag6
wag7
webmerc
weren
wink1
wink2
Expand Down
4 changes: 3 additions & 1 deletion docs/source/operations/projections/merc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ The projection is conformal which makes it suitable for navigational purposes.
| | datum is ellipsoidal. |
| | |
| | * aux_sphere_type=0 will use the semi-major radius. |
| | This is the value to use for Google Web Mercator:: |
| | This is the value to use for Web Mercator:: |
| | |
| | proj=merc +datum=WGS84 +aux_sphere_type=0 |
| | |
| | You can also use the :ref:`webmerc` projection. |
| | * aux_sphere_type=1 will use the semi-minor radius. |
| | * aux_sphere_type=2 will calculate the authalic radius |
| | and use it. |
Expand Down
78 changes: 78 additions & 0 deletions docs/source/operations/projections/webmerc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
.. _webmerc:

********************************************************************************
Web Mercator / Pseudo Mercator
********************************************************************************

The Web Mercator / Pseudo Mercator projection is a cylindrical map projection.
This is a variant of the regular :ref:`merc` projection, except that the computation
is done on a sphere, using the semi-major axis of the ellipsoid.

From `Wikipedia <https://en.wikipedia.org/wiki/Web_Mercator>`_:

This projection is widely used by the Web Mercator, Google Web Mercator,
Spherical Mercator, WGS 84 Web Mercator[1] or WGS 84/Pseudo-Mercator is a
variant of the Mercator projection and is the de facto standard for Web
mapping applications. [...]
It is used by virtually all major online map providers [...]
Its official EPSG identifier is EPSG:3857, although others have been used
historically.


+---------------------+----------------------------------------------------------+
| **Classification** | Cylindrical (non conformant if used with ellipsoid) |
+---------------------+----------------------------------------------------------+
| **Version** | Added in proj 5.1.0 |
+---------------------+----------------------------------------------------------+
| **Available forms** | Forward and inverse, spherical projection |
+---------------------+----------------------------------------------------------+
| **Defined area** | Global, but best used near the equator |
+---------------------+----------------------------------------------------------+
| **Options** | Neither lat_0, lat_ts or k_0 should be used. |
+---------------------+----------------------------------------------------------+

Usage
########

Example::

$ echo 2 49 | proj +proj=webmerc +datum=WGS84
222638.98 6274861.39

Mathematical definition
#######################

The formulas describing the Mercator projection are all taken from G. Evenden's libproj manuals [Evenden2005]_.

Forward projection
==================

.. math::
x = \lambda
.. math::
y = \ln \left[ \tan \left(\frac{\pi}{4} + \frac{\phi}{2} \right) \right]
Inverse projection
==================

.. math::
\lambda = {x}
.. math::
\phi = \frac{\pi}{2} - 2 \arctan \left[ e^{-y} \right]
Further reading
###############

#. `Wikipedia <https://en.wikipedia.org/wiki/Web_Mercator>`_



19 changes: 19 additions & 0 deletions src/PJ_merc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "projects.h"

PROJ_HEAD(merc, "Mercator") "\n\tCyl, Sph&Ell\n\tlat_ts= aux_sphere_type=";
PROJ_HEAD(webmerc, "Web Mercator / Pseudo Mercator") "\n\tCyl, Sph\n\t";

#define EPS10 1.e-10

Expand Down Expand Up @@ -127,3 +128,21 @@ PJ *PROJECTION(merc) {
return P;
}

PJ *PROJECTION(webmerc) {

if( pj_param(P->ctx, P->params, "tk_0").i ) {
return pj_default_destructor(P, PJD_ERR_INVALID_ARG);
}

if( pj_param(P->ctx, P->params, "tlat_0").i ) {
return pj_default_destructor(P, PJD_ERR_INVALID_ARG);
}

P->b = P->a;
/* Clean up the ellipsoidal parameters to reflect the sphere */
P->es = P->e = P->f = 0;
pj_calc_ellipsoid_params (P, P->a, 0);
P->inv = s_inverse;
P->fwd = s_forward;
return P;
}
1 change: 1 addition & 0 deletions src/pj_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ PROJ_HEAD(wag4, "Wagner IV")
PROJ_HEAD(wag5, "Wagner V")
PROJ_HEAD(wag6, "Wagner VI")
PROJ_HEAD(wag7, "Wagner VII")
PROJ_HEAD(webmerc, "Web Mercator / Pseudo Mercator")
PROJ_HEAD(weren, "Werenskiold I")
PROJ_HEAD(wink1, "Winkel I")
PROJ_HEAD(wink2, "Winkel II")
Expand Down
13 changes: 13 additions & 0 deletions test/gie/4D-API_cs2cs-style.gie
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ accept 487147.594520173 4934316.46263998 0
expect -10359135.85 5546632.48 0
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
Test that Google's Web Mercator with +proj=webmerc
-------------------------------------------------------------------------------
operation proj=pipeline step init=epsg:26915 inv step proj=webmerc datum=WGS84
-------------------------------------------------------------------------------
tolerance 20 cm
accept 487147.594520173 4934316.46263998
expect -10370728.80 5552839.74

accept 487147.594520173 4934316.46263998 0
expect -10370728.80 5552839.74 0
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
Test that +datum parameters are handled correctly in pipelines.
See #872 for details.
Expand Down

0 comments on commit 646cfa0

Please sign in to comment.