示例#1
0
def test_oblique_mercator_losing_gamma():
    crs = CRS(
        "+proj=omerc +lat_0=-36.10360962430914 +lonc=147.0632291727015 "
        "+alpha=-54.78622979612904 +k=1 +x_0=0 +y_0=0 +gamma=-54.78622979612904"
    )
    with pytest.warns(
            UserWarning,
            match=
            "angle from rectified to skew grid parameter lost in conversion to CF",
    ):
        crs.to_cf()
示例#2
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_proj4_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",
    }
示例#3
0
def test_export_compound_crs():
    crs = CRS("urn:ogc:def:crs,crs:EPSG::2393,crs:EPSG::5717")
    expected_cf = {
        "semi_major_axis": 6378388.0,
        "semi_minor_axis": crs.ellipsoid.semi_minor_metre,
        "inverse_flattening": 297.0,
        "reference_ellipsoid_name": "International 1924",
        "longitude_of_prime_meridian": 0.0,
        "prime_meridian_name": "Greenwich",
        "geographic_crs_name": "KKJ",
        "horizontal_datum_name": "Kartastokoordinaattijarjestelma (1966)",
        "projected_crs_name": "KKJ / Finland Uniform Coordinate System",
        "grid_mapping_name": "transverse_mercator",
        "latitude_of_projection_origin": 0.0,
        "longitude_of_central_meridian": 27.0,
        "false_easting": 3500000.0,
        "false_northing": 0.0,
        "scale_factor_at_central_meridian": 1.0,
        "geopotential_datum_name": "Helsinki 1960",
    }
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("COMPOUNDCRS[")
    assert cf_dict == expected_cf
    # test roundtrip
    _test_roundtrip(expected_cf, "COMPOUNDCRS[")
示例#4
0
def test_geos_proj_string():
    crs = CRS({
        "proj": "geos",
        "h": 35785831.0,
        "a": 6378169.0,
        "b": 6356583.8
    })
    expected_cf = {
        "semi_major_axis": 6378169.0,
        "semi_minor_axis": 6356583.8,
        "inverse_flattening": crs.ellipsoid.inverse_flattening,
        "longitude_of_prime_meridian": 0.0,
        "prime_meridian_name": "Greenwich",
        "grid_mapping_name": "geostationary",
        "sweep_angle_axis": "y",
        "perspective_point_height": 35785831.0,
        "latitude_of_projection_origin": 0.0,
        "longitude_of_projection_origin": 0.0,
        "false_easting": 0.0,
        "false_northing": 0.0,
    }
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == expected_cf
    # test roundtrip
    _test_roundtrip(expected_cf, "PROJCRS[")
示例#5
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",
    }
示例#6
0
def test_ob_tran_not_rotated_latlon():
    crs = CRS("+proj=ob_tran +o_proj=moll +o_lat_p=45 +o_lon_p=-90 +lon_0=-90")
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == {
        "grid_mapping_name": "unknown",
        "longitude_of_projection_origin": -90,
        "grid_north_pole_latitude": 45,
        "grid_north_pole_longitude": -90,
    }
示例#7
0
def test_cf_from_utm__nad83():
    crs = CRS("epsg:26917")
    with pytest.warns(UserWarning):
        cf_dict = crs.to_cf(errcheck=True)
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == {
        "projected_crs_name": "NAD83 / UTM zone 17N",
        "latitude_of_projection_origin": 0.0,
        "longitude_of_central_meridian": -81.0,
        "scale_factor_at_central_meridian": 0.9996,
        "false_easting": 500000.0,
        "false_northing": 0.0,
        "grid_mapping_name": "transverse_mercator",
        "horizontal_datum_name": "NAD83",
        "unit": "m",
    }
示例#8
0
def test_osgb_1936():
    crs = CRS("OSGB 1936 / British National Grid")
    param_dict = _to_dict(crs.coordinate_operation)
    expected_cf = {
        "semi_major_axis":
        crs.ellipsoid.semi_major_metre,
        "semi_minor_axis":
        crs.ellipsoid.semi_minor_metre,
        "inverse_flattening":
        crs.ellipsoid.inverse_flattening,
        "reference_ellipsoid_name":
        "Airy 1830",
        "longitude_of_prime_meridian":
        0.0,
        "prime_meridian_name":
        "Greenwich",
        "geographic_crs_name":
        "OSGB 1936",
        "horizontal_datum_name":
        "OSGB 1936",
        "projected_crs_name":
        "OSGB 1936 / British National Grid",
        "grid_mapping_name":
        "transverse_mercator",
        "latitude_of_projection_origin":
        49.0,
        "longitude_of_central_meridian":
        -2.0,
        "false_easting":
        400000.0,
        "false_northing":
        -100000.0,
        "scale_factor_at_central_meridian":
        param_dict["Scale factor at natural origin"],
    }
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == expected_cf
    # test roundtrip
    _test_roundtrip(expected_cf, "PROJCRS[")
示例#9
0
def test_azimuthal_equidistant():
    crs = CRS("ESRI:54032")
    expected_cf = {
        "semi_major_axis": 6378137.0,
        "semi_minor_axis": crs.ellipsoid.semi_minor_metre,
        "inverse_flattening": crs.ellipsoid.inverse_flattening,
        "reference_ellipsoid_name": "WGS 84",
        "longitude_of_prime_meridian": 0.0,
        "prime_meridian_name": "Greenwich",
        "geographic_crs_name": "WGS 84",
        "horizontal_datum_name": "World Geodetic System 1984",
        "projected_crs_name": "World_Azimuthal_Equidistant",
        "grid_mapping_name": "azimuthal_equidistant",
        "latitude_of_projection_origin": 0.0,
        "longitude_of_projection_origin": 0.0,
        "false_easting": 0.0,
        "false_northing": 0.0,
    }
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == expected_cf
    # test roundtrip
    _test_roundtrip(expected_cf, "PROJCRS[")
示例#10
0
def test_albers_conical_equal_area():
    crs = CRS("ESRI:102008")
    expected_cf = {
        "semi_major_axis": 6378137.0,
        "semi_minor_axis": crs.ellipsoid.semi_minor_metre,
        "inverse_flattening": crs.ellipsoid.inverse_flattening,
        "reference_ellipsoid_name": "GRS 1980",
        "longitude_of_prime_meridian": 0.0,
        "prime_meridian_name": "Greenwich",
        "geographic_crs_name": "NAD83",
        "horizontal_datum_name": "North American Datum 1983",
        "projected_crs_name": "North_America_Albers_Equal_Area_Conic",
        "grid_mapping_name": "albers_conical_equal_area",
        "standard_parallel": (20.0, 60.0),
        "latitude_of_projection_origin": 40.0,
        "longitude_of_central_meridian": -96.0,
        "false_easting": 0.0,
        "false_northing": 0.0,
    }
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == expected_cf
    # test roundtrip
    _test_roundtrip(expected_cf, "PROJCRS[")
示例#11
0
def test_cf_from_utm__nad83():
    crs = CRS("epsg:26917")
    expected_cf = {
        "semi_major_axis": 6378137.0,
        "semi_minor_axis": crs.ellipsoid.semi_minor_metre,
        "inverse_flattening": crs.ellipsoid.inverse_flattening,
        "reference_ellipsoid_name": "GRS 1980",
        "longitude_of_prime_meridian": 0.0,
        "prime_meridian_name": "Greenwich",
        "geographic_crs_name": "NAD83",
        "horizontal_datum_name": "North American Datum 1983",
        "projected_crs_name": "NAD83 / UTM zone 17N",
        "grid_mapping_name": "transverse_mercator",
        "latitude_of_projection_origin": 0.0,
        "longitude_of_central_meridian": -81.0,
        "false_easting": 500000.0,
        "false_northing": 0.0,
        "scale_factor_at_central_meridian": 0.9996,
    }
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == expected_cf
    # test roundtrip
    _test_roundtrip(expected_cf, "PROJCRS[")
示例#12
0
文件: cf.py 项目: strawpants/geoslurp
def cfadd_global(ds,
                 title=None,
                 comment="Auto generated",
                 references="",
                 source=None,
                 crs=None,
                 update=False):
    if not update:
        ds.attrs = {}
    ds.attrs['Conventions'] = cfdefaults["Conventions"]
    if title:
        ds.attrs['title'] = title

    ds.attrs['institution'] = cfdefaults["institution"]
    if source:
        ds.attrs['source'] = source
    else:
        ds.attrs['source'] = cfdefaults["source"]
    ds.attrs['history'] = str(datetime.utcnow()) + ' geoslurp'
    ds.attrs['references'] = references
    ds.attrs['comment'] = comment
    if crs:
        crs = CRS(crs)
        ds.attrs['spatial_ref'] = crs.to_cf()
示例#13
0
def test_geoid_model_name():
    wkt = (
        'COMPOUNDCRS["NAD83 / Pennsylvania South + NAVD88 height",\n'
        '    PROJCRS["NAD83 / Pennsylvania South",\n'
        '        BASEGEOGCRS["NAD83",\n'
        '            DATUM["North American Datum 1983",\n'
        '                ELLIPSOID["GRS 1980",6378137,298.257222101,\n'
        '                    LENGTHUNIT["metre",1]]],\n'
        '            PRIMEM["Greenwich",0,\n'
        '                ANGLEUNIT["degree",0.0174532925199433]]],\n'
        '        CONVERSION["SPCS83 Pennsylvania South zone (meters)",\n'
        '            METHOD["Lambert Conic Conformal (2SP)",\n'
        '                ID["EPSG",9802]],\n'
        '            PARAMETER["Latitude of false origin",39.3333333333333,\n'
        '                ANGLEUNIT["degree",0.0174532925199433],\n'
        '                ID["EPSG",8821]],\n'
        '            PARAMETER["Longitude of false origin",-77.75,\n'
        '                ANGLEUNIT["degree",0.0174532925199433],\n'
        '                ID["EPSG",8822]],\n'
        '            PARAMETER["Latitude of 1st standard '
        'parallel",40.9666666666667,\n'
        '                ANGLEUNIT["degree",0.0174532925199433],\n'
        '                ID["EPSG",8823]],\n'
        '            PARAMETER["Latitude of 2nd standard '
        'parallel",39.9333333333333,\n'
        '                ANGLEUNIT["degree",0.0174532925199433],\n'
        '                ID["EPSG",8824]],\n'
        '            PARAMETER["Easting at false origin",600000,\n'
        '                LENGTHUNIT["metre",1],\n'
        '                ID["EPSG",8826]],\n'
        '            PARAMETER["Northing at false origin",0,\n'
        '                LENGTHUNIT["metre",1],\n'
        '                ID["EPSG",8827]]],\n'
        "        CS[Cartesian,2],\n"
        '            AXIS["easting (X)",east,\n'
        "                ORDER[1],\n"
        '                LENGTHUNIT["metre",1]],\n'
        '            AXIS["northing (Y)",north,\n'
        "                ORDER[2],\n"
        '                LENGTHUNIT["metre",1]]],\n'
        '    VERTCRS["NAVD88 height",\n'
        '        VDATUM["North American Vertical Datum 1988"],\n'
        "        CS[vertical,1],\n"
        '            AXIS["gravity-related height (H)",up,\n'
        '                LENGTHUNIT["metre",1]],\n'
        '        GEOIDMODEL["GEOID12B"]]]')
    crs = CRS(wkt)
    param_dict = _to_dict(crs.sub_crs_list[0].coordinate_operation)
    expected_cf = {
        "semi_major_axis":
        6378137.0,
        "semi_minor_axis":
        crs.ellipsoid.semi_minor_metre,
        "inverse_flattening":
        crs.ellipsoid.inverse_flattening,
        "reference_ellipsoid_name":
        "GRS 1980",
        "longitude_of_prime_meridian":
        0.0,
        "prime_meridian_name":
        "Greenwich",
        "geographic_crs_name":
        "NAD83",
        "horizontal_datum_name":
        "North American Datum 1983",
        "projected_crs_name":
        "NAD83 / Pennsylvania South",
        "grid_mapping_name":
        "lambert_conformal_conic",
        "standard_parallel": (
            param_dict["Latitude of 1st standard parallel"],
            param_dict["Latitude of 2nd standard parallel"],
        ),
        "latitude_of_projection_origin":
        param_dict["Latitude of false origin"],
        "longitude_of_central_meridian":
        -77.75,
        "false_easting":
        600000.0,
        "false_northing":
        0.0,
        "geoid_name":
        "GEOID12B",
        "geopotential_datum_name":
        "North American Vertical Datum 1988",
    }
    cf_dict = crs.to_cf()
    assert cf_dict.pop("crs_wkt").startswith("COMPOUNDCRS[")
    assert cf_dict == expected_cf
    # test roundtrip
    _test_roundtrip(expected_cf, "COMPOUNDCRS[")
示例#14
0
def test_ob_tran_not_rotated_latlon():
    crs = CRS("+proj=ob_tran +o_proj=moll +o_lat_p=45 +o_lon_p=-90 +lon_0=-90")
    with pytest.warns(UserWarning):
        cf_dict = crs.to_cf(errcheck=True)
    assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
    assert cf_dict == {}
示例#15
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",
        }