def test_custom_datum__input(): cd = CustomDatum( ellipsoid=Ellipsoid.from_epsg(7001), prime_meridian=PrimeMeridian.from_name("Lisbon"), ) assert cd.ellipsoid.name == "Airy 1830" assert cd.prime_meridian.name == "Lisbon"
def test_bound_crs__example(): proj_crs = ProjectedCRS( conversion=TransverseMercatorConversion( latitude_natural_origin=0, longitude_natural_origin=15, false_easting=2520000, false_northing=0, scale_factor_natural_origin=0.9996, ), geodetic_crs=GeographicCRS( datum=CustomDatum(ellipsoid="International 1909 (Hayford)") ), ) bound_crs = BoundCRS( source_crs=proj_crs, target_crs="WGS 84", transformation=ToWGS84Transformation( proj_crs.geodetic_crs, -122.74, -34.27, -22.83, -1.884, -3.4, -3.03, -15.62 ), ) with pytest.warns(UserWarning): assert bound_crs.to_dict() == { "ellps": "intl", "k": 0.9996, "lat_0": 0, "lon_0": 15, "no_defs": None, "proj": "tmerc", "towgs84": [-122.74, -34.27, -22.83, -1.884, -3.4, -3.03, -15.62], "type": "crs", "units": "m", "x_0": 2520000, "y_0": 0, }
def _horizontal_datum_from_params(cf_params): # step 1: build ellipsoid ellipsoid = None ellipsoid_name = cf_params.get("reference_ellipsoid_name") try: ellipsoid = CustomEllipsoid( name=ellipsoid_name or "undefined", semi_major_axis=cf_params.get("semi_major_axis"), semi_minor_axis=cf_params.get("semi_minor_axis"), inverse_flattening=cf_params.get("inverse_flattening"), radius=cf_params.get("earth_radius"), ) except CRSError: if ellipsoid_name: ellipsoid = Ellipsoid.from_name(ellipsoid_name) # step 2: build prime meridian prime_meridian = None prime_meridian_name = cf_params.get("prime_meridian_name") try: prime_meridian = CustomPrimeMeridian( name=prime_meridian_name or "undefined", longitude=cf_params["longitude_of_prime_meridian"], ) except KeyError: if prime_meridian_name: prime_meridian = PrimeMeridian.from_name(prime_meridian_name) # step 3: build datum datum_name = cf_params.get("horizontal_datum_name") if ellipsoid or prime_meridian: return CustomDatum( name=datum_name or "undefined", ellipsoid=ellipsoid or "WGS 84", prime_meridian=prime_meridian or "Greenwich", ) if datum_name: return Datum.from_name(datum_name) return None
def test_custom_datum(): cd = CustomDatum() assert cd.ellipsoid.name == "WGS 84" assert cd.prime_meridian.name == "Greenwich"