diff --git a/.config/docker_environment.yml b/.config/docker_environment.yml index 8980f48a6..37b822cc2 100644 --- a/.config/docker_environment.yml +++ b/.config/docker_environment.yml @@ -4,8 +4,7 @@ channels: - nodefaults dependencies: - conda-forge::python=3.10 - - conda-forge::gdal=3.5.1 - # from here some dragons + # from here some dragons - conda-forge::geopandas - conda-forge::rasterio - conda-forge::osmnx diff --git a/.config/environment.yml b/.config/environment.yml index 5897030e9..df7e33767 100644 --- a/.config/environment.yml +++ b/.config/environment.yml @@ -4,7 +4,6 @@ channels: - nodefaults dependencies: - conda-forge::python=3.10 - - conda-forge::gdal=3.5.1 # Install poetry 1.3.2 (1.4.*) gives issues. # If this does not work then exclude it from the environment and install it manually # with: conda install -c conda-forge poetry=1.3.2 diff --git a/.config/tc_environment.yml b/.config/tc_environment.yml index 8cb91cc23..70d85db7e 100644 --- a/.config/tc_environment.yml +++ b/.config/tc_environment.yml @@ -4,6 +4,5 @@ channels: - nodefaults dependencies: - python=3.10 - - conda-forge::gdal=3.5.1 - conda-forge::pandoc - teamcity-messages \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index fcffefcd1..f48405655 100644 --- a/poetry.lock +++ b/poetry.lock @@ -981,20 +981,6 @@ files = [ {file = "fqdn-1.5.1.tar.gz", hash = "sha256:105ed3677e767fb5ca086a0c1f4bb66ebc3c100be518f0e0d755d9eae164d89f"}, ] -[[package]] -name = "gdal" -version = "3.5.1" -description = "GDAL: Geospatial Data Abstraction Library" -category = "main" -optional = false -python-versions = ">=3.6.0" -files = [ - {file = "GDAL-3.5.1.tar.gz", hash = "sha256:e2cfe1f338b9d84e8f6d93883712344d6d27ebaffaaa24733603a7713949a2be"}, -] - -[package.extras] -numpy = ["numpy (>1.0.0)"] - [[package]] name = "geographiclib" version = "2.0" @@ -4742,4 +4728,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9, <3.11" -content-hash = "b366a4070c5329084a9e11140fbe358eb637c6bba66784d523664b6d2278c516" +content-hash = "14e5c82186348a4139d3bb7718bef030491596ccabdf88c7aa21d29ab6c1fe5b" diff --git a/pyproject.toml b/pyproject.toml index d343364c0..d59b387ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,6 @@ openpyxl = "^3.0.10" xlrd = "^2.0.1" xarray = "^2022.6.0" scipy = "^1.9.1" -GDAL = "3.5.1" pygeos = "^0.14" momepy = "0.5.0" geopandas = "^0.14.0" diff --git a/ra2ce/network/hazard/hazard_common_functions.py b/ra2ce/network/hazard/hazard_common_functions.py index 44d08ea96..48538b732 100644 --- a/ra2ce/network/hazard/hazard_common_functions.py +++ b/ra2ce/network/hazard/hazard_common_functions.py @@ -22,8 +22,8 @@ import logging from pathlib import Path +import rasterio from networkx import Graph -from osgeo import gdal from ra2ce.network.networks_utils import bounds_intersect_2d, get_extent @@ -40,16 +40,20 @@ def validate_extent_graph(extent_graph: list[float], tif_hazard_file: Path) -> N ValueError: When the hazard raster and the graph geometries do not overlap. """ # Check if the hazard and graph extents overlap - extent = get_extent(gdal.Open(str(tif_hazard_file))) + with rasterio.open(tif_hazard_file) as src: + # Get the bounding box + bounds = src.bounds + + # Extract the extent extent_hazard = ( - extent["minX"], - extent["maxX"], - extent["minY"], - extent["maxY"], + bounds.left, + bounds.right, + bounds.bottom, + bounds.top, ) if not bounds_intersect_2d(extent_graph, extent_hazard): - logging.info("Raster extent: {}, Graph extent: {}".format(extent, extent_graph)) + logging.info("Raster extent: {}, Graph extent: {}".format(bounds, extent_graph)) raise ValueError( "The hazard raster and the graph geometries do not overlap, check projection" ) diff --git a/ra2ce/network/networks_utils.py b/ra2ce/network/networks_utils.py index 49d59fc49..8ac5d460a 100644 --- a/ra2ce/network/networks_utils.py +++ b/ra2ce/network/networks_utils.py @@ -37,7 +37,6 @@ import rtree from geopy import distance from numpy.ma import MaskedArray -from osgeo import gdal from osmnx import graph_to_gdfs from rasterio.features import shapes from rasterio.mask import mask @@ -1279,28 +1278,6 @@ def read_merge_shp(shp_file_analyse, id_name, shp_file_diversion=[], crs_=4326): return lines -def check_hazard_extent_resolution(list_hazards): - """Checks whether the extent of a list of hazard rasters is exactly the same. - - Args: - list_hazards (list of pathlib paths or strings): A list of paths to the hazard map rasters of which - the extent needs to be checked - - Returns: - (bool): True if the extents are exactly the same, False if they are not. - """ - if len(list_hazards) == 1: - return True - check_hazard_extent = [ - gdal.Open(str(haz)).GetGeoTransform() for haz in list_hazards - ] - if len(set(check_hazard_extent)) == 1: - # All hazard have the exact same extents and resolution - return True - else: - return False - - def get_extent(dataset): cols = dataset.RasterXSize rows = dataset.RasterYSize