Skip to content

Commit

Permalink
Test with GDAL 3 and Py38 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Jul 29, 2020
1 parent bd03501 commit b5b054f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ matrix:
- os: linux
env: PYTHON_VERSION="3.7" MAINDEPS="numpy=1.16 scipy=1.3 pytz" DEPS="dask-core=1.* gdal=2.* toolz pandas=0.25 geopandas=0.6 pyproj>=2"
- os: linux
env: PYTHON_VERSION="3.7" MAINDEPS="numpy scipy pytz" DEPS="dask-core gdal=2.* toolz geopandas pyproj>=2"
env: PYTHON_VERSION="3.8" MAINDEPS="" DEPS="numpy scipy pytz dask-core gdal toolz geopandas pyproj"

install:
- wget https://repo.anaconda.com/pkgs/misc/conda-execs/conda-latest-$TRAVIS_OS_NAME-64.exe -O conda.exe
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog of dask-geomodeling

- Fix point requests in raster.Smooth.

- GDAL 3 compatibility fixes.


2.2.9 (2020-06-23)
------------------
Expand Down
11 changes: 8 additions & 3 deletions dask_geomodeling/raster/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def __init__(self, store, data, select=False):
if not hasattr(data, "__iter__"):
raise TypeError("'{}' object is not allowed".format(type(data)))
try:
source, target = map(np.asarray, zip(*data))
source, target = self._data_as_ndarray(data)
except ValueError:
raise ValueError("Please supply a list of [from, to] values")
# "from" can have bool or int dtype, "to" can also be float
Expand All @@ -398,6 +398,11 @@ def __init__(self, store, data, select=False):
raise TypeError("'{}' object is not allowed".format(type(select)))
super().__init__(store, data, select)

@staticmethod
def _data_as_ndarray(data):
source, target = zip(*data)
return np.asarray(source), np.asarray(target)

@property
def data(self):
return self.args[1]
Expand All @@ -408,7 +413,7 @@ def select(self):

@property
def dtype(self):
_, target = map(np.asarray, zip(*self.data))
_, target = self._data_as_ndarray(self.data)
return target.dtype

@property
Expand All @@ -431,7 +436,7 @@ def process(store_data, process_kwargs):

no_data_value = store_data["no_data_value"]
values = store_data["values"]
source, target = map(np.asarray, zip(*process_kwargs["data"]))
source, target = Reclassify._data_as_ndarray(process_kwargs["data"])
dtype = np.dtype(process_kwargs["dtype"])
fillvalue = process_kwargs["fillvalue"]

Expand Down
16 changes: 10 additions & 6 deletions dask_geomodeling/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ def test_get_epsg_or_wkt(self):
self.assertEqual(out, "EPSG:3857")
# no epsg
wkt = """GEOGCS["GCS_WGS_1984",
DATUM["D_WGS_1984",SPHEROID[
"WGS_1984",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["Degree",
0.017453292519943295]]"""
DATUM["D_WGS_1984",SPHEROID[
"WGS_1984",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["Degree",
0.017453292519943295]]"""
out = utils.get_epsg_or_wkt(wkt)
self.assertEqual(out, wkt.replace(" ", "").replace("\n", ""))
# do not test exact equality: different GDAL versions give different
# results
assert out.startswith("GEOGCS")
assert 'PRIMEM["Greenwich",0]' in out
assert 'UNIT["Degree"' in out

def test_get_footprint(self):
output = utils.get_footprint(size=5)
Expand Down
11 changes: 10 additions & 1 deletion dask_geomodeling/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
from pyproj import CRS


GDAL3 = gdal.VersionInfo().startswith("3")

def get_index(values, no_data_value):
""" Return an index to access for data values in values. """
equal = np.isclose if values.dtype.kind == "f" else np.equal
Expand Down Expand Up @@ -354,7 +356,14 @@ def aligns_with(self, other):
@lru_cache(32) # least-recently-used cache of size 32
def get_sr(user_input):
""" Return osr.SpatialReference for user input. """
return osr.SpatialReference(osr.GetUserInputAsWKT(str(user_input)))
sr = osr.SpatialReference(osr.GetUserInputAsWKT(str(user_input)))
# https://github.com/OSGeo/gdal/blob/release/3.0/gdal/MIGRATION_GUIDE.TXT
#
# GDAL takes into account official axis order.
# Traditional GIS-friendly axis order can be restored with:
if GDAL3:
sr.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
return sr


def get_crs(user_input):
Expand Down

0 comments on commit b5b054f

Please sign in to comment.