diff --git a/raster_tools/io.py b/raster_tools/io.py index d47eecb..81f5cc1 100644 --- a/raster_tools/io.py +++ b/raster_tools/io.py @@ -1,4 +1,5 @@ import os +import urllib from pathlib import Path import dask @@ -142,16 +143,20 @@ def normalize_null_value(nv, dtype): return nv -def open_raster_from_path(path): +def open_raster_from_path_or_url(path): if type(path) in IO_UNDERSTOOD_TYPES: path = str(path) - path = os.path.abspath(path) else: raise RasterIOError( - f"Could not resolve input to a raster path: '{path}'" + f"Could not resolve input to a raster path or URL: '{path}'" ) - validate_path(path) - ext = _get_extension(path) + if urllib.parse.urlparse(path) == "": + # Assume file path + validate_path(path) + ext = _get_extension(path) + else: + # URL + ext = "" xrs = None # Try to let gdal open anything but NC, HDF, GRIB files diff --git a/raster_tools/raster.py b/raster_tools/raster.py index 1acf110..a02101b 100644 --- a/raster_tools/raster.py +++ b/raster_tools/raster.py @@ -61,7 +61,7 @@ chunk, is_batch_file, normalize_xarray_data, - open_raster_from_path, + open_raster_from_path_or_url, write_raster, ) @@ -568,7 +568,7 @@ def get_raster_ds(raster): ds = parse_batch_script(raster).final_raster._ds else: - rs, mask, nv = open_raster_from_path(raster) + rs, mask, nv = open_raster_from_path_or_url(raster) xmask = xr.DataArray(mask, dims=rs.dims, coords=rs.coords) ds = make_raster_ds(rs.rio.write_nodata(nv), xmask) ds = _xarray_to_raster_ds(ds)