Skip to content

Commit 9405668

Browse files
committed
BUG: Add datum ensemble support to GeographicCRS
1 parent f82cae5 commit 9405668

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

docs/history.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Latest
1313
- REF: Raise error when :meth:`.CRS.to_wkt`, :meth:`.CRS.to_json`, or :meth:`.CRS.to_proj4` returns None (issue #1036)
1414
- CLN: Remove `AzumuthalEquidistantConversion` & :class:`LambertAzumuthalEqualAreaConversion`. :class:`AzimuthalEquidistantConversion` & :class:`LambertAzimuthalEqualAreaConversion` should be used instead (pull #1219)
1515
- BUG: Fix Derived Projected CRS support (issue #1182)
16-
- BUG: Add horizontal_datum_name for geographic CRS in :meth:`.CRS.to_cf`` (issue #1251)
16+
- BUG: Add horizontal_datum_name for geographic CRS in :meth:`.CRS.to_cf` (issue #1251)
17+
- BUG: Add datum ensemble support to :class:`.GeographicCRS` (pull #1255)
1718

1819
3.4.1
1920
-----

pyproj/crs/_cf1x8.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434

3535

3636
def _horizontal_datum_from_params(cf_params):
37+
datum_name = cf_params.get("horizontal_datum_name")
38+
if datum_name and datum_name not in ("undefined", "unknown"):
39+
try:
40+
return Datum.from_name(datum_name)
41+
except CRSError:
42+
pass
3743
# step 1: build ellipsoid
3844
ellipsoid = None
3945
ellipsoid_name = cf_params.get("reference_ellipsoid_name")
@@ -46,7 +52,7 @@ def _horizontal_datum_from_params(cf_params):
4652
radius=cf_params.get("earth_radius"),
4753
)
4854
except CRSError:
49-
if ellipsoid_name:
55+
if ellipsoid_name and ellipsoid_name not in ("undefined", "unknown"):
5056
ellipsoid = Ellipsoid.from_name(ellipsoid_name)
5157

5258
# step 2: build prime meridian
@@ -58,19 +64,16 @@ def _horizontal_datum_from_params(cf_params):
5864
longitude=cf_params["longitude_of_prime_meridian"],
5965
)
6066
except KeyError:
61-
if prime_meridian_name:
67+
if prime_meridian_name and prime_meridian_name not in ("undefined", "unknown"):
6268
prime_meridian = PrimeMeridian.from_name(prime_meridian_name)
6369

6470
# step 3: build datum
65-
datum_name = cf_params.get("horizontal_datum_name")
6671
if ellipsoid or prime_meridian:
6772
return CustomDatum(
6873
name=datum_name or "undefined",
6974
ellipsoid=ellipsoid or "WGS 84",
7075
prime_meridian=prime_meridian or "Greenwich",
7176
)
72-
if datum_name:
73-
return Datum.from_name(datum_name)
7477
return None
7578

7679

pyproj/crs/crs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,6 @@ def to_cf(
718718
return cf_dict
719719

720720
# handle projected CRS
721-
if self.is_projected and self.datum:
722-
cf_dict["horizontal_datum_name"] = self.datum.name
723721
coordinate_operation = None
724722
if not self.is_bound and self.is_projected:
725723
coordinate_operation = self.coordinate_operation
@@ -1758,31 +1756,35 @@ class GeographicCRS(CustomConstructorCRS):
17581756
def __init__(
17591757
self,
17601758
name: str = "undefined",
1761-
datum: Any = "urn:ogc:def:datum:EPSG::6326",
1759+
datum: Any = "urn:ogc:def:ensemble:EPSG::6326",
17621760
ellipsoidal_cs: Optional[Any] = None,
17631761
) -> None:
17641762
"""
17651763
Parameters
17661764
----------
17671765
name: str, default="undefined"
17681766
Name of the CRS.
1769-
datum: Any, default="urn:ogc:def:datum:EPSG::6326"
1767+
datum: Any, default="urn:ogc:def:ensemble:EPSG::6326"
17701768
Anything accepted by :meth:`pyproj.crs.Datum.from_user_input` or
17711769
a :class:`pyproj.crs.datum.CustomDatum`.
17721770
ellipsoidal_cs: Any, optional
17731771
Input to create an Ellipsoidal Coordinate System.
17741772
Anything accepted by :meth:`pyproj.crs.CoordinateSystem.from_user_input`
17751773
or an Ellipsoidal Coordinate System created from :ref:`coordinate_system`.
17761774
"""
1775+
datum = Datum.from_user_input(datum).to_json_dict()
17771776
geographic_crs_json = {
17781777
"$schema": "https://proj.org/schemas/v0.2/projjson.schema.json",
17791778
"type": "GeographicCRS",
17801779
"name": name,
1781-
"datum": Datum.from_user_input(datum).to_json_dict(),
17821780
"coordinate_system": CoordinateSystem.from_user_input(
17831781
ellipsoidal_cs or Ellipsoidal2DCS()
17841782
).to_json_dict(),
17851783
}
1784+
if datum["type"] == "DatumEnsemble":
1785+
geographic_crs_json["datum_ensemble"] = datum
1786+
else:
1787+
geographic_crs_json["datum"] = datum
17861788
super().__init__(geographic_crs_json)
17871789

17881790

test/crs/test_crs_cf.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def test_cf_rotated_latlon():
362362
"reference_ellipsoid_name": "WGS 84",
363363
"longitude_of_prime_meridian": 0.0,
364364
"prime_meridian_name": "Greenwich",
365-
"horizontal_datum_name": "World Geodetic System 1984",
365+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
366366
"grid_mapping_name": "rotated_latitude_longitude",
367367
"grid_north_pole_latitude": 32.5,
368368
"grid_north_pole_longitude": 170.0,
@@ -534,7 +534,7 @@ def test_cf_lambert_conformal_conic_1sp():
534534
"reference_ellipsoid_name": "WGS 84",
535535
"longitude_of_prime_meridian": 0.0,
536536
"prime_meridian_name": "Greenwich",
537-
"horizontal_datum_name": "World Geodetic System 1984",
537+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
538538
"grid_mapping_name": "lambert_conformal_conic",
539539
"longitude_of_central_meridian": 265.0,
540540
"false_easting": 0.0,
@@ -598,7 +598,7 @@ def test_cf_lambert_conformal_conic_2sp(standard_parallel):
598598
"reference_ellipsoid_name": "WGS 84",
599599
"longitude_of_prime_meridian": 0.0,
600600
"prime_meridian_name": "Greenwich",
601-
"horizontal_datum_name": "World Geodetic System 1984",
601+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
602602
"grid_mapping_name": "lambert_conformal_conic",
603603
"standard_parallel": (25.0, 30.0),
604604
"latitude_of_projection_origin": 25.0,
@@ -753,7 +753,7 @@ def test_geos_crs_sweep():
753753
"reference_ellipsoid_name": "WGS 84",
754754
"longitude_of_prime_meridian": 0.0,
755755
"prime_meridian_name": "Greenwich",
756-
"horizontal_datum_name": "World Geodetic System 1984",
756+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
757757
"grid_mapping_name": "geostationary",
758758
"sweep_angle_axis": "x",
759759
"perspective_point_height": 1.0,
@@ -801,7 +801,7 @@ def test_geos_crs_fixed_angle_axis():
801801
"reference_ellipsoid_name": "WGS 84",
802802
"longitude_of_prime_meridian": 0.0,
803803
"prime_meridian_name": "Greenwich",
804-
"horizontal_datum_name": "World Geodetic System 1984",
804+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
805805
"grid_mapping_name": "geostationary",
806806
"sweep_angle_axis": "x",
807807
"perspective_point_height": 1.0,
@@ -901,7 +901,7 @@ def test_mercator_b():
901901
"reference_ellipsoid_name": "WGS 84",
902902
"longitude_of_prime_meridian": 0.0,
903903
"prime_meridian_name": "Greenwich",
904-
"horizontal_datum_name": "World Geodetic System 1984",
904+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
905905
"grid_mapping_name": "mercator",
906906
"standard_parallel": 21.354,
907907
"longitude_of_projection_origin": 10.0,
@@ -1205,6 +1205,7 @@ def test_azimuthal_equidistant():
12051205
assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
12061206
assert cf_dict == expected_cf
12071207
# test roundtrip
1208+
expected_cf["horizontal_datum_name"] = "World Geodetic System 1984 ensemble"
12081209
_test_roundtrip(expected_cf, "PROJCRS[")
12091210
# test coordinate system
12101211
assert crs.cs_to_cf() == [
@@ -1232,7 +1233,7 @@ def test_lambert_azimuthal_equal_area():
12321233
"reference_ellipsoid_name": "WGS 84",
12331234
"longitude_of_prime_meridian": 0.0,
12341235
"prime_meridian_name": "Greenwich",
1235-
"horizontal_datum_name": "World Geodetic System 1984",
1236+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
12361237
"grid_mapping_name": "lambert_azimuthal_equal_area",
12371238
"latitude_of_projection_origin": 1.0,
12381239
"longitude_of_projection_origin": 2.0,
@@ -1272,7 +1273,7 @@ def test_lambert_cylindrical_equal_area():
12721273
"reference_ellipsoid_name": "WGS 84",
12731274
"longitude_of_prime_meridian": 0.0,
12741275
"prime_meridian_name": "Greenwich",
1275-
"horizontal_datum_name": "World Geodetic System 1984",
1276+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
12761277
"grid_mapping_name": "lambert_cylindrical_equal_area",
12771278
"standard_parallel": 1.0,
12781279
"longitude_of_central_meridian": 2.0,
@@ -1312,7 +1313,7 @@ def test_mercator_a():
13121313
"reference_ellipsoid_name": "WGS 84",
13131314
"longitude_of_prime_meridian": 0.0,
13141315
"prime_meridian_name": "Greenwich",
1315-
"horizontal_datum_name": "World Geodetic System 1984",
1316+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
13161317
"grid_mapping_name": "mercator",
13171318
"standard_parallel": 0.0,
13181319
"longitude_of_projection_origin": 2.0,
@@ -1353,7 +1354,7 @@ def test_orthographic():
13531354
"reference_ellipsoid_name": "WGS 84",
13541355
"longitude_of_prime_meridian": 0.0,
13551356
"prime_meridian_name": "Greenwich",
1356-
"horizontal_datum_name": "World Geodetic System 1984",
1357+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
13571358
"grid_mapping_name": "orthographic",
13581359
"latitude_of_projection_origin": 1.0,
13591360
"longitude_of_projection_origin": 2.0,
@@ -1393,7 +1394,7 @@ def test_polar_stereographic_a():
13931394
"reference_ellipsoid_name": "WGS 84",
13941395
"longitude_of_prime_meridian": 0.0,
13951396
"prime_meridian_name": "Greenwich",
1396-
"horizontal_datum_name": "World Geodetic System 1984",
1397+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
13971398
"grid_mapping_name": "polar_stereographic",
13981399
"latitude_of_projection_origin": 90.0,
13991400
"straight_vertical_longitude_from_pole": 1.0,
@@ -1434,7 +1435,7 @@ def test_polar_stereographic_b():
14341435
"reference_ellipsoid_name": "WGS 84",
14351436
"longitude_of_prime_meridian": 0.0,
14361437
"prime_meridian_name": "Greenwich",
1437-
"horizontal_datum_name": "World Geodetic System 1984",
1438+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
14381439
"grid_mapping_name": "polar_stereographic",
14391440
"standard_parallel": 0.0,
14401441
"straight_vertical_longitude_from_pole": 1.0,
@@ -1474,7 +1475,7 @@ def test_stereographic():
14741475
"reference_ellipsoid_name": "WGS 84",
14751476
"longitude_of_prime_meridian": 0.0,
14761477
"prime_meridian_name": "Greenwich",
1477-
"horizontal_datum_name": "World Geodetic System 1984",
1478+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
14781479
"grid_mapping_name": "stereographic",
14791480
"latitude_of_projection_origin": 0.0,
14801481
"longitude_of_projection_origin": 1.0,
@@ -1515,7 +1516,7 @@ def test_sinusoidal():
15151516
"reference_ellipsoid_name": "WGS 84",
15161517
"longitude_of_prime_meridian": 0.0,
15171518
"prime_meridian_name": "Greenwich",
1518-
"horizontal_datum_name": "World Geodetic System 1984",
1519+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
15191520
"grid_mapping_name": "sinusoidal",
15201521
"longitude_of_projection_origin": 0.0,
15211522
"false_easting": 1.0,
@@ -1554,7 +1555,7 @@ def test_vertical_perspective():
15541555
"reference_ellipsoid_name": "WGS 84",
15551556
"longitude_of_prime_meridian": 0.0,
15561557
"prime_meridian_name": "Greenwich",
1557-
"horizontal_datum_name": "World Geodetic System 1984",
1558+
"horizontal_datum_name": "World Geodetic System 1984 ensemble",
15581559
"grid_mapping_name": "vertical_perspective",
15591560
"perspective_point_height": 50.0,
15601561
"latitude_of_projection_origin": 0.0,
@@ -1891,7 +1892,7 @@ def test_3d_ellipsoidal_cs_depth():
18911892
"name": "WGS 84 (geographic 3D)",
18921893
"datum": {
18931894
"type": "GeodeticReferenceFrame",
1894-
"name": "World Geodetic System 1984",
1895+
"name": "World Geodetic System 1984 ensemble",
18951896
"ellipsoid": {
18961897
"name": "WGS 84",
18971898
"semi_major_axis": 6378137,

0 commit comments

Comments
 (0)