Commit c6d9fb54 authored by Daniel Scheffler's avatar Daniel Scheffler

Fixed exceptions caused by WKT2 strings passed to GDAL<3.

Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 619c0cbd
Pipeline #11938 failed with stages
in 16 minutes and 31 seconds
......@@ -2,6 +2,12 @@
History
=======
0.15.1 (2020-08-26)
-------------------
* Fixed exceptions caused by WKT2 strings passed to GDAL<3.
0.15.0 (2020-08-26)
-------------------
......
......@@ -254,7 +254,8 @@ def geotransform2mapinfo(gt, prj):
try:
if int(gdal.__version__[0]) < 3:
prj = CRS(prj).to_wkt(version="WKT1_GDAL") # noqa
# noinspection PyTypeChecker
prj = CRS(prj).to_wkt(version="WKT1_GDAL")
ds_out = gdal.GetDriverByName('ENVI').Create(fn_bsq, 2, 2, 1, gdal.GDT_Int32)
ds_out.SetGeoTransform(gt)
......
......@@ -27,6 +27,7 @@ import multiprocessing
from pkgutil import find_loader
# custom
from pyproj import CRS
try:
from osgeo import gdal
from osgeo import gdalnumeric
......@@ -308,6 +309,14 @@ def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
raise ValueError("'out_bounds_prj' cannot have a projection if 'in_prj' and 'out_prj' are not given.")
in_prj = out_prj = out_bounds_prj = "LOCAL_CS[\"MAP\"]"
# ensure GDAL 2 only get WKT1 strings (WKT2 requires GDAL>=3)
if in_prj and int(gdal.__version__[0]) < 3:
# noinspection PyTypeChecker
in_prj = CRS(in_prj).to_wkt(version="WKT1_GDAL")
if out_prj and int(gdal.__version__[0]) < 3:
# noinspection PyTypeChecker
out_prj = CRS(out_prj).to_wkt(version="WKT1_GDAL")
# assertions
if rspAlg == 'average':
is_avail_rsp_average = int(gdal.VersionInfo()[0]) >= 2
......
......@@ -27,6 +27,7 @@ import numpy as np
from shapely.geometry import shape, mapping, box
from shapely.geometry import Polygon # noqa F401 # flake8 issue
from shapely import wkt
from pyproj import CRS
try:
from osgeo import ogr
......@@ -108,6 +109,10 @@ def points_to_raster(points, values, tgt_res, prj=None, fillVal=None):
ds = ogr.GetDriverByName("Memory").CreateDataSource('wrk')
if prj is not None:
if int(gdal.__version__[0]) < 3:
# noinspection PyTypeChecker
prj = CRS(prj).to_wkt(version="WKT1_GDAL")
srs = osr.SpatialReference()
srs.ImportFromWkt(prj)
else:
......
......@@ -29,6 +29,7 @@ import os
import numpy as np
from pandas import DataFrame
from osgeo import gdal_array
from pyproj import CRS
try:
from osgeo import gdal
......@@ -65,6 +66,10 @@ def get_GDAL_ds_inmem(array, gt=None, prj=None, nodata=None):
if gt:
ds.SetGeoTransform(gt)
if prj:
if int(gdal.__version__[0]) < 3:
# noinspection PyTypeChecker
prj = CRS(prj).to_wkt(version="WKT1_GDAL")
ds.SetProjection(prj)
if nodata is not None:
......
......@@ -24,6 +24,7 @@
import os
import multiprocessing
from pyproj import CRS
try:
import gdal
except ImportError:
......@@ -48,6 +49,10 @@ def write_numpy_to_image(array, path_out, outFmt='GTIFF', gt=None, prj=None):
if gt:
outDs.SetGeoTransform(gt)
if prj:
if int(gdal.__version__[0]) < 3:
# noinspection PyTypeChecker
prj = CRS(prj).to_wkt(version="WKT1_GDAL")
outDs.SetProjection(prj)
del outDs
......
......@@ -19,5 +19,5 @@
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.15.0'
__versionalias__ = '20200826_01'
__version__ = '0.15.1'
__versionalias__ = '20200827_01'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment