Skip to content

Commit daff5c8

Browse files
committed
Fix: try to get SpatialRef info
1 parent 47a7bf3 commit daff5c8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pygeoc/raster.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,15 @@ def read_raster(raster_file):
277277
geotrans = ds.GetGeoTransform()
278278
dttype = band.DataType
279279

280-
srs = osr_SpatialReference()
281-
srs.ImportFromWkt(ds.GetProjection())
282-
# print(srs.ExportToProj4())
280+
srs = ds.GetSpatialRef()
281+
if srs is None:
282+
wkt = ds.GetProjection()
283+
srs = osr_SpatialReference()
284+
if wkt:
285+
# print(wkt)
286+
srs.ImportFromWkt(wkt) # srs may still be empty if file has no SRS
287+
# print(srs.ExportToProj4())
288+
283289
if nodata_value is None:
284290
nodata_value = DEFAULT_NODATA
285291
band = None
@@ -738,9 +744,9 @@ def closing(input_rasterfilename, times):
738744

739745
if __name__ == '__main__':
740746
# Run doctest in docstrings of Google code style
741-
# python -m doctest raster.py (only when doctest.ELLIPSIS is not specified)
742-
# or python raster.py -v
743-
# or py.test --doctest-modules raster.py
747+
# (Recommended) python -m doctest -o ELLIPSIS -v pygeoc/raster.py
748+
# or python pygeoc/raster.py -v
749+
# or py.test --doctest-modules pygeoc/raster.py
744750
import doctest
745751

746752
doctest.testmod(optionflags=doctest.ELLIPSIS)

0 commit comments

Comments
 (0)