Skip to content

Commit

Permalink
ENH: Support setting lat_ts for Mercator. (Fixes SciTools#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
dopplershift committed Oct 25, 2016
1 parent 959670b commit 2a5aaeb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ class Mercator(Projection):

def __init__(self, central_longitude=0.0,
min_latitude=-80.0, max_latitude=84.0,
globe=None):
globe=None, latitude_true_scale=0.0):
"""
Kwargs:
Expand All @@ -951,11 +951,13 @@ def __init__(self, central_longitude=0.0,
Defaults to 84 degrees.
* globe - A :class:`cartopy.crs.Globe`.
If omitted, a default globe is created.
* latitude_true_scale - the latitude where the scale is 1.
Defaults to 0 degrees.
"""
proj4_params = [('proj', 'merc'),
('lon_0', central_longitude),
('k', 1),
('lat_ts', latitude_true_scale),
('units', 'm')]
super(Mercator, self).__init__(proj4_params, globe=globe)

Expand Down
19 changes: 15 additions & 4 deletions lib/cartopy/tests/crs/test_mercator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
def test_default():
crs = ccrs.Mercator()

assert_equal(crs.proj4_init, ('+ellps=WGS84 +proj=merc +lon_0=0.0 +k=1 '
'+units=m +no_defs'))
assert_equal(crs.proj4_init, ('+ellps=WGS84 +proj=merc +lon_0=0.0 '
'+lat_ts=0.0 +units=m +no_defs'))
assert_almost_equal(crs.boundary.bounds,
[-20037508, -15496571, 20037508, 18764656], decimal=0)

Expand All @@ -39,7 +39,7 @@ def test_eccentric_globe():
ellipse=None)
crs = ccrs.Mercator(globe=globe, min_latitude=-40, max_latitude=40)
assert_equal(crs.proj4_init, ('+a=10000 +b=5000 +proj=merc +lon_0=0.0 '
'+k=1 +units=m +no_defs'))
'+lat_ts=0.0 +units=m +no_defs'))

assert_almost_equal(crs.boundary.bounds,
[-31415.93, -2190.5, 31415.93, 2190.5], decimal=2)
Expand All @@ -64,14 +64,25 @@ def test_equality():
def test_central_longitude():
cl = 10.0
crs = ccrs.Mercator(central_longitude=cl)
proj4_str = ('+ellps=WGS84 +proj=merc +lon_0={} +k=1 '
proj4_str = ('+ellps=WGS84 +proj=merc +lon_0={} +lat_ts=0.0 '
'+units=m +no_defs'.format(cl))
assert_equal(crs.proj4_init, proj4_str)

assert_almost_equal(crs.boundary.bounds,
[-20037508, -15496570, 20037508, 18764656], decimal=0)


def test_latitude_true_scale():
lat_ts = 20.0
crs = ccrs.Mercator(latitude_true_scale=lat_ts)
proj4_str = ('+ellps=WGS84 +proj=merc +lon_0=0.0 +lat_ts={} '
'+units=m +no_defs'.format(lat_ts))
assert_equal(crs.proj4_init, proj4_str)

assert_almost_equal(crs.boundary.bounds,
[-18836475, -14567718, 18836475, 17639917], decimal=0)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 comments on commit 2a5aaeb

Please sign in to comment.