예제 #1
0
    def __init__(self, initialdata=None, **kwargs):
        """Make a CRS from a PROJ dict or mapping

        Parameters
        ----------
        initialdata : mapping, optional
            A dictionary or other mapping
        kwargs : mapping, optional
            Another mapping. Will be overlaid on the initialdata.

        Returns
        -------
        CRS

        """
        self._wkt = None
        self._data = None
        self._crs = None

        if initialdata or kwargs:

            data = dict(initialdata or {})
            data.update(**kwargs)
            data = {k: v for k, v in data.items() if k in all_proj_keys}

            # always use lowercase 'epsg'.
            if 'init' in data:
                data['init'] = data['init'].replace('EPSG:', 'epsg:')

            proj = ' '.join(
                ['+{}={}'.format(key, val) for key, val in data.items()])
            self._crs = _CRS.from_proj4(proj)

        else:
            self._crs = _CRS()
예제 #2
0
    def from_proj4(cls, proj):
        """Make a CRS from a PROJ4 string

        Parameters
        ----------
        proj : str
            A PROJ4 string like "+proj=longlat ..."

        Returns
        -------
        CRS

        """
        obj = cls()
        obj._crs = _CRS.from_proj4(proj)
        return obj
예제 #3
0
파일: crs.py 프로젝트: DanLipsitt/rasterio
    def from_proj4(cls, proj):
        """Make a CRS from a PROJ4 string

        Parameters
        ----------
        proj : str
            A PROJ4 string like "+proj=longlat ..."

        Returns
        -------
        CRS

        """
        obj = cls()
        obj._crs = _CRS.from_proj4(proj)
        return obj
예제 #4
0
def test_to_epsg(proj_string):
    """CRS has EPSG code"""
    assert _CRS.from_proj4(proj_string).to_epsg() == 4326
예제 #5
0
def test_equality():
    """CRS are or are not equal"""
    _CRS.from_epsg(4326) == _CRS.from_proj4('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
예제 #6
0
def test_exception_proj4():
    """Get the exception message we expect"""
    with pytest.raises(CRSError):
        _CRS.from_proj4("+proj=bogus")
예제 #7
0
def test_epsg_no_code_available():
    """CRS has no EPSG code"""
    lcc_crs = _CRS.from_proj4('+lon_0=-95 +ellps=GRS80 +y_0=0 +no_defs=True +proj=lcc +x_0=0 +units=m +lat_2=77 +lat_1=49 +lat_0=0')
    assert lcc_crs.to_epsg() is None
예제 #8
0
def test_equality():
    """CRS are or are not equal"""
    _CRS.from_epsg(4326) == _CRS.from_proj4(
        '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
예제 #9
0
def test_exception_proj4():
    """Get the exception message we expect"""
    with pytest.raises(CRSError):
        _CRS.from_proj4("+proj=bogus")
예제 #10
0
def test_epsg_no_code_available():
    """CRS has no EPSG code"""
    lcc_crs = _CRS.from_proj4(
        '+lon_0=-95 +ellps=GRS80 +y_0=0 +no_defs=True +proj=lcc +x_0=0 +units=m +lat_2=77 +lat_1=49 +lat_0=0'
    )
    assert lcc_crs.to_epsg() is None
예제 #11
0
def test_to_epsg(proj_string):
    """CRS has EPSG code"""
    assert _CRS.from_proj4(proj_string).to_epsg(
        confidence_threshold=20) == 4326
예제 #12
0
def test_to_epsg(proj_string):
    """CRS has EPSG code"""
    assert _CRS.from_proj4(proj_string).to_epsg() == 4326