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()
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
def test_to_epsg(proj_string): """CRS has EPSG code""" assert _CRS.from_proj4(proj_string).to_epsg() == 4326
def test_equality(): """CRS are or are not equal""" _CRS.from_epsg(4326) == _CRS.from_proj4('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
def test_exception_proj4(): """Get the exception message we expect""" with pytest.raises(CRSError): _CRS.from_proj4("+proj=bogus")
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
def test_equality(): """CRS are or are not equal""" _CRS.from_epsg(4326) == _CRS.from_proj4( '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
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
def test_to_epsg(proj_string): """CRS has EPSG code""" assert _CRS.from_proj4(proj_string).to_epsg( confidence_threshold=20) == 4326