示例#1
0
def test_to_dict_no_proj4():
    crs = CRS(
        {
            "a": 6371229.0,
            "b": 6371229.0,
            "lon_0": -10.0,
            "o_lat_p": 30.0,
            "o_lon_p": 0.0,
            "o_proj": "longlat",
            "proj": "ob_tran",
        }
    )
    if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"):
        with pytest.warns(UserWarning):
            assert crs.to_proj4() == (
                "+proj=ob_tran +o_proj=longlat +lon_0=-10 +o_lat_p=30 "
                "+o_lon_p=0 +R=6371229 +no_defs +type=crs"
            )
            assert crs.to_dict() == {
                "R": 6371229,
                "lon_0": -10,
                "no_defs": None,
                "o_lat_p": 30,
                "o_lon_p": 0,
                "o_proj": "longlat",
                "proj": "ob_tran",
                "type": "crs",
            }
    else:
        with pytest.warns(UserWarning):
            assert crs.to_proj4() is None
            assert crs.to_dict() == {}
示例#2
0
def test_to_dict_no_proj4():
    crs = CRS({
        "a": 6371229.0,
        "b": 6371229.0,
        "lon_0": -10.0,
        "o_lat_p": 30.0,
        "o_lon_p": 0.0,
        "o_proj": "longlat",
        "proj": "ob_tran",
    })
    if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"):
        with pytest.warns(UserWarning):
            assert crs.to_dict() == {
                "R": 6371229,
                "lon_0": -10,
                "no_defs": None,
                "o_lat_p": 30,
                "o_lon_p": 0,
                "o_proj": "longlat",
                "proj": "ob_tran",
                "type": "crs",
            }
    else:
        with pytest.warns(UserWarning):
            assert crs.to_proj4() is None
            assert crs.to_dict() == {}
示例#3
0
def test_to_cf_transverse_mercator():
    crs = CRS(
        init="epsg:3004", towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62"
    )
    with pytest.warns(UserWarning):
        cf_dict = crs.to_cf(errcheck=True)
    towgs84_test = [-122.74, -34.27, -22.83, -1.884, -3.4, -3.03, -15.62]
    assert cf_dict.pop("crs_wkt").startswith("BOUNDCRS[")
    assert cf_dict == {
        "grid_mapping_name": "transverse_mercator",
        "latitude_of_projection_origin": 0,
        "longitude_of_central_meridian": 15,
        "fase_easting": 2520000,
        "fase_northing": 0,
        "reference_ellipsoid_name": "intl",
        "towgs84": towgs84_test,
        "unit": "m",
    }
    assert crs.to_dict() == {
        "proj": "tmerc",
        "lat_0": 0,
        "lon_0": 15,
        "k": 0.9996,
        "x_0": 2520000,
        "y_0": 0,
        "ellps": "intl",
        "towgs84": towgs84_test,
        "units": "m",
        "no_defs": None,
        "type": "crs",
    }
def crs_to_proj_dict(crs: CRS) -> dict:
    warnings.filterwarnings("ignore", module="pyproj", category=UserWarning)
    if crs.to_epsg() is not None:
        proj_dict = {"EPSG": crs.to_epsg()}
    else:
        proj_dict = crs.to_dict()
    _remove_unnecessary_proj_params(proj_dict)
    return proj_dict
示例#5
0
def test_to_dict_no_proj4():
    crs = CRS({
        "a": 6371229.0,
        "b": 6371229.0,
        "lon_0": -10.0,
        "o_lat_p": 30.0,
        "o_lon_p": 0.0,
        "o_proj": "longlat",
        "proj": "ob_tran",
    })
    assert crs.to_proj4() is None
    assert crs.to_dict() == {}
示例#6
0
文件: proj4.py 项目: BENR0/pyresample
def proj4_str_to_dict(proj4_str):
    """Convert PROJ.4 compatible string definition to dict.

    EPSG codes should be provided as "EPSG:XXXX" where "XXXX"
    is the EPSG number code. It can also be provided as
    ``"+init=EPSG:XXXX"`` as long as the underlying PROJ library
    supports it (deprecated in PROJ 6.0+).

    Note: Key only parameters will be assigned a value of `True`.
    """
    # convert EPSG codes to equivalent PROJ4 string definition
    crs = CRS(proj4_str)
    return crs.to_dict()
示例#7
0
def test_to_dict_no_proj4():
    crs = CRS({
        "a": 6371229.0,
        "b": 6371229.0,
        "lon_0": -10.0,
        "o_lat_p": 30.0,
        "o_lon_p": 0.0,
        "o_proj": "longlat",
        "proj": "ob_tran",
    })
    with pytest.warns(UserWarning):
        assert crs.to_dict() == {
            "R": 6371229,
            "lon_0": -10,
            "no_defs": None,
            "o_lat_p": 30,
            "o_lon_p": 0,
            "o_proj": "longlat",
            "proj": "ob_tran",
            "type": "crs",
        }
示例#8
0
def test_to_cf_transverse_mercator():
    crs = CRS(
        proj="tmerc",
        lat_0=0,
        lon_0=15,
        k=0.9996,
        x_0=2520000,
        y_0=0,
        ellps="intl",
        units="m",
        towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62",
    )
    towgs84_test = [-122.74, -34.27, -22.83, -1.884, -3.4, -3.03, -15.62]
    expected_cf = {
        "semi_major_axis":
        6378388.0,
        "semi_minor_axis":
        crs.ellipsoid.semi_minor_metre,
        "inverse_flattening":
        297.0,
        "reference_ellipsoid_name":
        "International 1909 (Hayford)",
        "longitude_of_prime_meridian":
        0.0,
        "prime_meridian_name":
        "Greenwich",
        "horizontal_datum_name":
        ("Unknown based on International 1909 (Hayford) ellipsoid"),
        "towgs84":
        towgs84_test,
        "grid_mapping_name":
        "transverse_mercator",
        "latitude_of_projection_origin":
        0.0,
        "longitude_of_central_meridian":
        15.0,
        "false_easting":
        2520000.0,
        "false_northing":
        0.0,
        "scale_factor_at_central_meridian":
        0.9996,
    }
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("BOUNDCRS[")
    assert cf_dict == expected_cf
    # test roundtrip
    _test_roundtrip(expected_cf, "BOUNDCRS[")

    with pytest.warns(UserWarning):
        assert crs.to_dict() == {
            "proj": "tmerc",
            "lat_0": 0,
            "lon_0": 15,
            "k": 0.9996,
            "x_0": 2520000,
            "y_0": 0,
            "ellps": "intl",
            "towgs84": towgs84_test,
            "units": "m",
            "no_defs": None,
            "type": "crs",
        }