Skip to content

Commit

Permalink
crs of dataset with no SRS is None
Browse files Browse the repository at this point in the history
str(CRS()) == ''

Resolves #1616
  • Loading branch information
Sean Gillies committed Feb 4, 2019
1 parent 63589a4 commit ca6ae34
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
6 changes: 4 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Changes
=======

Next (?)
--------
1.0.16 (2019-02-04)
-------------------

- A bug preventing GCPs from being created with new BufferedDatasetWriter
instances (#1600) has been fixed (#1610).
- A previously unreported bug preventing BufferedDatasetWriters from being
opened in r+ mode has been fixed.
- A regression in creating CRS objects from PROJ4 strings that include
"+wktext" (#1609) has been fixed.
- Regressions in str representations of empty CRS objects and the handling of
unreferenced datasets in rasterio._base have been fixed (#1616).

1.0.15 (2019-01-27)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion rasterio/_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ cdef class DatasetBase(object):
if wkt:
return CRS.from_wkt(wkt)
else:
return CRS()
return None

def read_crs(self):
"""Return the GDAL dataset's stored CRS"""
Expand Down
15 changes: 11 additions & 4 deletions rasterio/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,18 @@ def to_dict(self):
dict
"""
epsg_code = self.to_epsg()
if epsg_code:
return {'init': 'epsg:{}'.format(epsg_code)}
if self._crs is None:
raise CRSError("Undefined CRS has no dict representation")

else:
return self._crs.to_dict()
epsg_code = self.to_epsg()
if epsg_code:
return {'init': 'epsg:{}'.format(epsg_code)}
else:
try:
return self._crs.to_dict()
except CRSError:
return {}

@property
def data(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ def test_read_esri_wkt():
}


def test_read_no_crs():
"""crs of a dataset with no SRS is None"""
with rasterio.open('tests/data/389225main_sw_1965_1024.jpg') as src:
assert src.crs is None


# Ensure that CRS sticks when we write a file.
@pytest.mark.gdalbin
def test_write_3857(tmpdir):
Expand Down Expand Up @@ -415,3 +421,8 @@ def test_issue1609_wktext_b():
'wktext': True}
wkt = CRS(dst_proj).wkt
assert 'EXTENSION["PROJ4","+ellps=WGS84 +h=9000000.0 +lat_0=-78.0 +lon_0=0.0 +proj=nsper +units=m +x_0=0 +y_0=0 +wktext"]]' in wkt


def test_empty_crs_str():
"""str(CRS()) should be empty string"""
assert str(CRS()) == ''

0 comments on commit ca6ae34

Please sign in to comment.