|
11 | 11 | from typing import NamedTuple |
12 | 12 |
|
13 | 13 | import numpy as np |
| 14 | +import pyproj |
14 | 15 | import pytest |
15 | 16 |
|
16 | 17 | import cartopy.crs as ccrs |
@@ -199,3 +200,40 @@ def test_nan(oblique_mercator, plate_carree, reverse_coord): |
199 | 200 | coord = tuple(reversed(coord)) |
200 | 201 | res = oblique_mercator.transform_point(*coord, src_crs=plate_carree) |
201 | 202 | assert np.all(np.isnan(res)) |
| 203 | + |
| 204 | + |
| 205 | +@pytest.mark.parametrize("azimuth, expected", |
| 206 | + [(90.0, 89.999), (-90.0, -90.001), (270.0, 269.999), |
| 207 | + (450.0, 449.999), (-270.0, -270.001)]) |
| 208 | +def test_singular_azimuth_nudged(azimuth, expected): |
| 209 | + """Azimuths PROJ cannot build are nudged; see ObliqueMercator.__init__.""" |
| 210 | + crs = ccrs.ObliqueMercator(azimuth=azimuth) |
| 211 | + assert float(crs.proj4_params["alpha"]) == pytest.approx(expected) |
| 212 | + |
| 213 | + |
| 214 | +def test_gamma_matches_epsg_3375(): |
| 215 | + """GDM2000 / Peninsular Malaysia RSO quotes alpha and gamma 0.1 deg apart. |
| 216 | +
|
| 217 | + EPSG:3375 puts its false origin at the projection centre where cartopy |
| 218 | + puts it at the natural origin, so a correct definition differs from EPSG |
| 219 | + by one constant offset; the spread of those offsets is the real error. |
| 220 | + """ |
| 221 | + wgs84 = pyproj.CRS("EPSG:4326") |
| 222 | + points = [(101.7, 3.1), (103.0, 5.5), (100.5, 6.5), (104.0, 1.5)] |
| 223 | + reference = pyproj.Transformer.from_crs( |
| 224 | + wgs84, pyproj.CRS("EPSG:3375"), always_xy=True) |
| 225 | + |
| 226 | + def spread(**kwargs): |
| 227 | + crs = ccrs.ObliqueMercator( |
| 228 | + central_longitude=102.25, central_latitude=4.0, |
| 229 | + scale_factor=0.99984, azimuth=323.0257964666667, |
| 230 | + globe=ccrs.Globe(ellipse="GRS80"), **kwargs) |
| 231 | + ours = pyproj.Transformer.from_crs( |
| 232 | + wgs84, pyproj.CRS(crs.proj4_init), always_xy=True) |
| 233 | + offsets = (np.array([reference.transform(*p) for p in points]) |
| 234 | + - np.array([ours.transform(*p) for p in points])) |
| 235 | + return np.abs(offsets - offsets.mean(axis=0)).max() |
| 236 | + |
| 237 | + assert spread(gamma=323.1301023611111) < 1e-6 |
| 238 | + # Without gamma, PROJ defaults it to alpha and the map comes out turned. |
| 239 | + assert spread() > 100.0 |
0 commit comments