當前位置: 首頁>>代碼示例>>Python>>正文


Python pyproj.CRS屬性代碼示例

本文整理匯總了Python中pyproj.CRS屬性的典型用法代碼示例。如果您正苦於以下問題:Python pyproj.CRS屬性的具體用法?Python pyproj.CRS怎麽用?Python pyproj.CRS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在pyproj的用法示例。


在下文中一共展示了pyproj.CRS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _parse_crs

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def _parse_crs(value):
        """ Method for parsing different inputs representing the same CRS enum. Examples:

        - 4326
        - 'EPSG:3857'
        - {'init': 32633}
        - pyproj.CRS(32743)
        """
        if isinstance(value, dict) and 'init' in value:
            value = value['init']
        if isinstance(value, pyproj.CRS):
            if value == CRSMeta._UNSUPPORTED_CRS:
                raise ValueError('sentinelhub-py supports only WGS 84 coordinate reference system with '
                                 'coordinate order lng-lat. However pyproj.CRS(4326) has coordinate order lat-lng')

            value = value.to_epsg()

        if isinstance(value, int):
            return str(value)
        if isinstance(value, str):
            return value.lower().strip('epsg: ')
        return value 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:24,代碼來源:constants.py

示例2: test_utm

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def test_utm(self):
        known_values = (
            (13, 46, '32633'),
            (13, 0, '32633'),
            (13, -45, '32733'),
            (13, 0, '32633'),
            (13, -0.0001, '32733'),
            (13, -46, '32733')
        )
        for known_val in known_values:
            lng, lat, epsg = known_val
            with self.subTest(msg=epsg):
                crs = CRS.get_utm_from_wgs84(lng, lat)
                self.assertEqual(epsg, crs.value,
                                 msg="Expected {}, got {} for lng={},lat={}".format(epsg, crs.value, str(lng),
                                                                                    str(lat))) 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:18,代碼來源:test_constants.py

示例3: test_crs_parsing

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def test_crs_parsing(self):
        test_cases = [
            (4326, CRS.WGS84),
            ('4326', CRS.WGS84),
            ('EPSG:3857', CRS.POP_WEB),
            ({'init': 'EPSG:32638'}, CRS.UTM_38N),
            (pyproj.CRS('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'), CRS.WGS84),
            (pyproj.CRS(3857), CRS.POP_WEB),
        ]
        for parse_value, expected_result in test_cases:
            with self.subTest(msg=str(parse_value)):
                parsed_result = CRS(parse_value)
                self.assertEqual(parsed_result, expected_result)

        with self.assertRaises(ValueError):
            CRS(pyproj.CRS(4326)) 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:18,代碼來源:test_constants.py

示例4: test_proj4_radius_parameters_provided

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def test_proj4_radius_parameters_provided(self):
        """Test proj4_radius_parameters with a/b."""
        from pyresample import utils
        a, b = utils.proj4.proj4_radius_parameters(
            '+proj=stere +a=6378273 +b=6356889.44891',
        )
        np.testing.assert_almost_equal(a, 6378273)
        np.testing.assert_almost_equal(b, 6356889.44891)

        # test again but force pyproj <2 behavior
        with mock.patch.object(utils.proj4, 'CRS', None):
            a, b = utils.proj4.proj4_radius_parameters(
                '+proj=stere +a=6378273 +b=6356889.44891',
            )
            np.testing.assert_almost_equal(a, 6378273)
            np.testing.assert_almost_equal(b, 6356889.44891) 
開發者ID:pytroll,項目名稱:pyresample,代碼行數:18,代碼來源:test_utils.py

示例5: test_proj4_radius_parameters_ellps

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def test_proj4_radius_parameters_ellps(self):
        """Test proj4_radius_parameters with ellps."""
        from pyresample import utils
        a, b = utils.proj4.proj4_radius_parameters(
            '+proj=stere +ellps=WGS84',
        )
        np.testing.assert_almost_equal(a, 6378137.)
        np.testing.assert_almost_equal(b, 6356752.314245, decimal=6)

        # test again but force pyproj <2 behavior
        with mock.patch.object(utils.proj4, 'CRS', None):
            a, b = utils.proj4.proj4_radius_parameters(
                '+proj=stere +ellps=WGS84',
            )
            np.testing.assert_almost_equal(a, 6378137.)
            np.testing.assert_almost_equal(b, 6356752.314245, decimal=6) 
開發者ID:pytroll,項目名稱:pyresample,代碼行數:18,代碼來源:test_utils.py

示例6: test_proj4_radius_parameters_default

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def test_proj4_radius_parameters_default(self):
        """Test proj4_radius_parameters with default parameters."""
        from pyresample import utils
        a, b = utils.proj4.proj4_radius_parameters(
            '+proj=lcc +lat_0=10 +lat_1=10',
        )
        # WGS84
        np.testing.assert_almost_equal(a, 6378137.)
        np.testing.assert_almost_equal(b, 6356752.314245, decimal=6)

        # test again but force pyproj <2 behavior
        with mock.patch.object(utils.proj4, 'CRS', None):
            a, b = utils.proj4.proj4_radius_parameters(
                '+proj=lcc +lat_0=10 +lat_1=10',
            )
            # WGS84
            np.testing.assert_almost_equal(a, 6378137.)
            np.testing.assert_almost_equal(b, 6356752.314245, decimal=6) 
開發者ID:pytroll,項目名稱:pyresample,代碼行數:20,代碼來源:test_utils.py

示例7: test_proj4_radius_parameters_spherical

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def test_proj4_radius_parameters_spherical(self):
        """Test proj4_radius_parameters in case of a spherical earth."""
        from pyresample import utils
        a, b = utils.proj4.proj4_radius_parameters(
            '+proj=stere +R=6378273',
        )
        np.testing.assert_almost_equal(a, 6378273.)
        np.testing.assert_almost_equal(b, 6378273.)

        # test again but force pyproj <2 behavior
        with mock.patch.object(utils.proj4, 'CRS', None):
            a, b = utils.proj4.proj4_radius_parameters(
                '+proj=stere +R=6378273',
            )
            np.testing.assert_almost_equal(a, 6378273.)
            np.testing.assert_almost_equal(b, 6378273.) 
開發者ID:pytroll,項目名稱:pyresample,代碼行數:18,代碼來源:test_utils.py

示例8: rasterio_crs

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def rasterio_crs(projparams):
    """
    Return a rasterio.crs.CRS object that corresponds to the given parameters.
    See: https://pyproj4.github.io/pyproj/stable/crs_compatibility.html#converting-from-pyproj-crs-crs-to-rasterio-crs-crs

    Args:
        projparams (int, str, dict, pyproj.CRS): PROJ parameters

    Returns:
        rasterio.crs.CRS: object that can be used with rasterio
    """
    proj_crs = pyproj_crs(projparams)
    if LooseVersion(rasterio.__gdal_version__) < LooseVersion("3.0.0"):
        rio_crs = RioCRS.from_wkt(proj_crs.to_wkt(WktVersion.WKT1_GDAL))
    else:
        rio_crs = RioCRS.from_wkt(proj_crs.to_wkt())
    return rio_crs 
開發者ID:cmla,項目名稱:s2p,代碼行數:19,代碼來源:geographiclib.py

示例9: pyproj_crs

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def pyproj_crs(projparams):
    """
    Wrapper around pyproj to return a pyproj.crs.CRS object that corresponds
    to the given parameters

    Args:
        projparams (int, str, dict): CRS parameters

    Returns:
        pyproj.crs.CRS: object that defines a CRS
    """
    if isinstance(projparams, str):
        try:
            projparams = int(projparams)
        except (ValueError, TypeError):
            pass
    return pyproj.crs.CRS(projparams) 
開發者ID:cmla,項目名稱:s2p,代碼行數:19,代碼來源:geographiclib.py

示例10: pyproj_transform

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def pyproj_transform(x, y, in_crs, out_crs, z=None):
    """
    Wrapper around pyproj to convert coordinates from an EPSG system to another.

    Args:
        x (scalar or array): x coordinate(s), expressed in in_crs
        y (scalar or array): y coordinate(s), expressed in in_crs
        in_crs (pyproj.crs.CRS or int): input coordinate reference system or EPSG code
        out_crs (pyproj.crs.CRS or int): output coordinate reference system or EPSG code
        z (scalar or array): z coordinate(s), expressed in in_crs

    Returns:
        scalar or array: x coordinate(s), expressed in out_crs
        scalar or array: y coordinate(s), expressed in out_crs
        scalar or array (optional if z): z coordinate(s), expressed in out_crs
    """
    transformer = pyproj.Transformer.from_crs(in_crs, out_crs, always_xy=True)
    if z is None:
        return transformer.transform(x, y)
    else:
        return transformer.transform(x, y, z) 
開發者ID:cmla,項目名稱:s2p,代碼行數:23,代碼來源:geographiclib.py

示例11: __new__

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def __new__(mcs, cls, bases, classdict):
        """ This is executed at the beginning of runtime when CRS class is created
        """
        for direction, direction_value in [('N', '6'), ('S', '7')]:
            for zone in range(1, 61):
                classdict['UTM_{}{}'.format(zone, direction)] = '32{}{}'.format(direction_value, str(zone).zfill(2))

        return super().__new__(mcs, cls, bases, classdict) 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:10,代碼來源:constants.py

示例12: __call__

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def __call__(cls, crs_value, *args, **kwargs):
        """ This is executed whenever CRS('something') is called
        """
        # pylint: disable=signature-differs
        crs_value = cls._parse_crs(crs_value)

        if isinstance(crs_value, str) and not cls.has_value(crs_value) and crs_value.isdigit() and len(crs_value) >= 4:
            crs_name = 'EPSG_{}'.format(crs_value)
            extend_enum(cls, crs_name, crs_value)

        return super().__call__(crs_value, *args, **kwargs) 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:13,代碼來源:constants.py

示例13: __str__

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def __str__(self):
        """ Method for casting CRS enum into string
        """
        return self.ogc_string() 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:6,代碼來源:constants.py

示例14: __repr__

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def __repr__(self):
        """ Method for retrieving CRS enum representation
        """
        return "CRS('{}')".format(self.value) 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:6,代碼來源:constants.py

示例15: epsg

# 需要導入模塊: import pyproj [as 別名]
# 或者: from pyproj import CRS [as 別名]
def epsg(self):
        """ EPSG code property

        :return: EPSG code of given CRS
        :rtype: int
        """
        return int(self.value) 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:9,代碼來源:constants.py


注:本文中的pyproj.CRS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。