Skip to content
Commits on Source (4)
Changes
=======
1.0.18 (2019-02-07)
-------------------
- Fix a regression reported in #1623.
1.0.17 (2019-02-05)
-------------------
......
rasterio (1.0.18-1) unstable; urgency=medium
* Team upload.
* New upstream release.
-- Bas Couwenberg <sebastic@debian.org> Fri, 08 Feb 2019 07:03:16 +0100
rasterio (1.0.17-1) unstable; urgency=medium
* Team upload.
......
......@@ -42,7 +42,7 @@ import rasterio.path
__all__ = ['band', 'open', 'pad', 'Env']
__version__ = "1.0.17"
__version__ = "1.0.18"
__gdal_version__ = gdal_version()
# Rasterio attaches NullHandler to the 'rasterio' logger and its
......
......@@ -130,8 +130,8 @@ cdef class _CRS(object):
finally:
_safe_osr_release(osr)
@classmethod
def from_epsg(cls, code):
@staticmethod
def from_epsg(code):
"""Make a CRS from an EPSG code
Parameters
......@@ -148,9 +148,19 @@ cdef class _CRS(object):
CRS
"""
if int(code) <= 0:
cdef _CRS obj = _CRS.__new__(_CRS)
code = int(code)
if code <= 0:
raise CRSError("EPSG codes are positive integers")
return cls.from_proj4('+init=epsg:{}'.format(code))
try:
exc_wrap_ogrerr(exc_wrap_int(OSRImportFromEPSG(obj._osr, <int>code)))
except CPLE_BaseError as exc:
raise CRSError("The EPSG code is unknown. {}".format(exc))
else:
return obj
@staticmethod
def from_proj4(proj):
......@@ -168,7 +178,7 @@ cdef class _CRS(object):
"""
cdef _CRS obj = _CRS.__new__(_CRS)
# Filter out nonsensical items.
# Filter out nonsensical items that might have crept in.
items_filtered = []
items = proj.split()
for item in items:
......@@ -207,10 +217,13 @@ cdef class _CRS(object):
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:')
# "+init=epsg:xxxx" is deprecated in GDAL. If we find this, we will
# extract the epsg code and dispatch to from_epsg.
if 'init' in data and data['init'].lower().startswith('epsg:'):
epsg_code = int(data['init'].split(':')[1])
return _CRS.from_epsg(epsg_code)
# Continue with the general case.
proj = ' '.join(['+{}={}'.format(key, val) for key, val in data.items()])
b_proj = proj.encode('utf-8')
......
......@@ -66,23 +66,7 @@ class CRS(collections.Mapping):
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_parts = []
for key, val in data.items():
if val is False or None:
continue
elif val is True:
proj_parts.append('+{}'.format(key))
else:
proj_parts.append('+{}={}'.format(key, val))
proj = ' '.join(proj_parts)
self._crs = _CRS.from_proj4(proj)
self._crs = _CRS.from_dict(data)
else:
self._crs = _CRS()
......
......@@ -42,21 +42,21 @@ def test_crs_constructor_dict():
"""Can create a CRS from a dict"""
crs = CRS({'init': 'epsg:3857'})
assert crs['init'] == 'epsg:3857'
assert 'PROJCS["unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",6378137,0]' in crs.wkt
assert 'PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]]' in crs.wkt
def test_crs_constructor_keywords():
"""Can create a CRS from keyword args, ignoring unknowns"""
crs = CRS(init='epsg:3857', foo='bar')
assert crs['init'] == 'epsg:3857'
assert 'PROJCS["unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",6378137,0]' in crs.wkt
assert 'PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]]' in crs.wkt
def test_crs_constructor_crs_obj():
"""Can create a CRS from a CRS obj"""
crs = CRS(CRS(init='epsg:3857'))
assert crs['init'] == 'epsg:3857'
assert 'PROJCS["unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",6378137,0]' in crs.wkt
assert 'PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]]' in crs.wkt
@pytest.fixture(scope='session')
......