How to use pyproj - 10 common examples

To help you get started, weโ€™ve selected a few pyproj examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TUW-GEO / Equi7Grid / tests / test_equi7grid.py View on Github external
'PARAMETER["longitude_of_center",21.5],'
                     'PARAMETER["latitude_of_center",8.5],UNIT["Meter",1.0]]')
        aeqd_sr = osr.SpatialReference()
        aeqd_sr.ImportFromWkt(aeqd_proj)
        p_grid = pyproj.Proj(aeqd_sr.ExportToProj4())
        p_geo = pyproj.Proj(geo_sr.ExportToProj4())
    
        # test locations in Africa
        points = [(-31.627336, 30.306273),
                  (-14.589038, -43.880131),
                  (79.423313, -35.261658),
                  (23.456413, 10.457987)]
    
        for i, pt in enumerate(points):
            # from lat/lon to aeqd
            aeqd_x, aeqd_y = pyproj.transform(p_geo, p_grid, pt[0], pt[1])
            # from aeqd to lat/lon
            lon, lat = pyproj.transform(p_grid, p_geo, aeqd_x, aeqd_y)
            # print info
    
            print("testing location {}:".format(i))
            _info = "   ({:f},{:f}) -> ({:f},{:f}) -> ({:f},{:f})"
            print(_info.format(pt[0], pt[1], aeqd_x, aeqd_y, lon, lat))
            print("    difference: ({:f},{:f})".format(lon - pt[0], lat - pt[1]))
            nptest.assert_allclose(pt[0], lon)
            nptest.assert_allclose(pt[1], lat)
github pyproj4 / pyproj / test / test_geod.py View on Github external
def test_geometry_area_perimeter__linestring():
    geod = Geod(ellps="WGS84")
    assert_almost_equal(
        geod.geometry_area_perimeter(LineString([Point(1, 2), Point(3, 4)])),
        (0.0, 627176.7944251911),
        decimal=2,
    )
github pyproj4 / pyproj / test / test_geod.py View on Github external
def test_geometry_area_perimeter__linestring__radians():
    geod = Geod(ellps="WGS84")
    assert_almost_equal(
        geod.geometry_area_perimeter(
            LineString(
                [
                    Point(math.radians(1), math.radians(2)),
                    Point(math.radians(3), math.radians(4)),
                ]
            ),
            radians=True,
        ),
        (0.0, 627176.7944251911),
        decimal=2,
    )
github pyproj4 / pyproj / test / test_crs.py View on Github external
def test_coordinate_operation_towgs84_three():
    crs = CRS("+proj=latlong +ellps=GRS80 +towgs84=-199.87,74.79,246.62")
    assert crs.coordinate_operation.towgs84 == [-199.87, 74.79, 246.62]
github pyproj4 / pyproj / test / test_crs.py View on Github external
def test_is_geocentric__bound():
    with pytest.warns(FutureWarning):
        ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
    assert ccs.is_geocentric
github pyproj4 / pyproj / test / test_crs_cf.py View on Github external
assert crs.to_dict() == {
            "proj": "omerc",
            "lat_0": 10,
            "lonc": 15,
            "alpha": 0.35,
            "gamma": 0.35,
            "k": 1,
            "x_0": 0,
            "y_0": 0,
            "ellps": "WGS84",
            "units": "m",
            "no_defs": None,
            "type": "crs",
        }
    # test CRS with input as lon_0 from the user
    lon0crs_cf = CRS(
        {
            "proj": "omerc",
            "lat_0": 10,
            "lon_0": 15,
            "alpha": 0.35,
            "gamma": 0.35,
            "k": 1,
            "x_0": 0,
            "y_0": 0,
            "ellps": "WGS84",
            "units": "m",
            "no_defs": None,
            "type": "crs",
        }
    ).to_cf()
    assert lon0crs_cf.pop("crs_wkt").startswith("PROJCRS[")
github pyproj4 / pyproj / test / test_crs_cf.py View on Github external
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",
    )
    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",
github pyproj4 / pyproj / test / test_crs.py View on Github external
def test_init_from_wkt_invalid():
    with pytest.raises(CRSError):
        CRS("trash-54322")
    with pytest.raises(CRSError):
        CRS("")
github pyproj4 / pyproj / test / test_crs.py View on Github external
def test_to_string__no_auth():
    proj = CRS("+proj=latlong +ellps=GRS80 +towgs84=-199.87,74.79,246.62")
    assert (
        proj.to_string()
        == "+proj=latlong +ellps=GRS80 +towgs84=-199.87,74.79,246.62 +type=crs"
    )
github pyproj4 / pyproj / test / test_transformer.py View on Github external
def test_transformer__operations():
    transformer = Transformer.from_crs(28356, 7856)
    assert [op.name for op in transformer.operations] == [
        "Inverse of Map Grid of Australia zone 56",
        "GDA94 to GDA2020 (1)",
        "Map Grid of Australia zone 56",
    ]