Skip to content

Commit

Permalink
Initial error handling for DEM/DTM
Browse files Browse the repository at this point in the history
* Some initial error handling for DEM/DTM

* Refactor to use multiple extents to define DTM provider area

* New extents for France

* Superfluous print statement

* refix something?
  • Loading branch information
kbrandwijk authored Jan 21, 2025
1 parent 077c9a6 commit 783810e
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 28 deletions.
3 changes: 1 addition & 2 deletions maps4fs/generator/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def process(self) -> None:
data = self.dtm_provider.get_numpy()
except Exception as e: # pylint: disable=W0718
self.logger.error("Failed to get DEM data from DTM provider: %s.", e)
self._save_empty_dem(dem_output_resolution)
return
raise e

if len(data.shape) != 2:
self.logger.error("DTM provider returned incorrect data: more than 1 channel.")
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/arctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ArcticProvider(DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True

_extents = (83.98823036056658, 50.7492704708152, 179.99698443265999, -180)
_extents = [(83.98823036056658, 50.7492704708152, 179.99698443265999, -180)]

_instructions = (
"This provider source includes 2 meter DEM data for the entire Arctic region above 50 "
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/baden.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BadenWurttembergProvider(WCSProvider, DTMProvider):
_is_community = True
_instructions = None
_is_base = False
_extents = (49.79645444804715, 47.52877040346605, 10.54203149250156, 7.444081717803481)
_extents = [(49.79645444804715, 47.52877040346605, 10.54203149250156, 7.444081717803481)]

_url = "https://owsproxy.lgl-bw.de/owsproxy/wcs/WCS_INSP_BW_Hoehe_Coverage_DGM1"
_wcs_version = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/bavaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BavariaProvider(DTMProvider):
_author = "[H4rdB4se](https://github.com/H4rdB4se)"
_is_community = True
_instructions = None
_extents = (50.56, 47.25, 13.91, 8.95)
_extents = [(50.56, 47.25, 13.91, 8.95)]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/canada.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CanadaProvider(WCSProvider, DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True
_is_base = False
_extents = (76.49491845750764, 33.66564101989275, -26.69697497450798, -157.7322455868316)
_extents = [(76.49491845750764, 33.66564101989275, -26.69697497450798, -157.7322455868316)]
_instructions = (
"HRDEM coverage for Canada is limited. Make sure to check the "
"[coverage map](https://geo.ca/imagery/high-resolution-digital"
Expand Down
4 changes: 3 additions & 1 deletion maps4fs/generator/dtm/czech.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class CzechProvider(WCSProvider, DTMProvider):
_is_community = True
_instructions = None
_is_base = False
_extents = (51.0576876059846754, 48.4917065572081754, 18.9775933665038821, 12.0428143585602161)
_extents = [
(51.0576876059846754, 48.4917065572081754, 18.9775933665038821, 12.0428143585602161)
]

_url = "https://ags.cuzk.cz/arcgis2/services/INSPIRE_Nadmorska_vyska/ImageServer/WCSServer" # pylint: disable=line-too-long
_wcs_version = "1.0.0"
Expand Down
5 changes: 4 additions & 1 deletion maps4fs/generator/dtm/denmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DenmarkProvider(WCSProvider, DTMProvider):
_is_community = True
_is_base = False
_settings = DenmarkProviderSettings
_extents = (57.7690657013977, 54.4354651516217, 15.5979112056959, 8.00830949937517)
_extents = [(57.7690657013977, 54.4354651516217, 15.5979112056959, 8.00830949937517)]

_instructions = (
"ℹ️ This provider requires an access token. See [here](https://confluence"
Expand All @@ -36,6 +36,9 @@ class DenmarkProvider(WCSProvider, DTMProvider):
_tile_size = 1000

def get_wcs_parameters(self, tile):
if not self.user_settings.token:
raise ValueError("A token is required for this provider.")

return {
"identifier": "dhm_terraen",
"bbox": (tile[1], tile[0], tile[3], tile[2]),
Expand Down
11 changes: 7 additions & 4 deletions maps4fs/generator/dtm/dtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DTMProvider(ABC):
_settings: Type[DTMProviderSettings] | None = DTMProviderSettings

"""Bounding box of the provider in the format (north, south, east, west)."""
_extents: tuple[float, float, float, float] | None = None
_extents: list[tuple[float, float, float, float]] | None = None

_instructions: str | None = None

Expand Down Expand Up @@ -248,9 +248,12 @@ def inside_bounding_box(cls, lat_lon: tuple[float, float]) -> bool:
"""
lat, lon = lat_lon
extents = cls._extents
return extents is None or (
extents[0] >= lat >= extents[1] and extents[2] >= lon >= extents[3]
)
if extents is None:
return True
for extent in extents:
if extent[0] >= lat >= extent[1] and extent[2] >= lon >= extent[3]:
return True
return False

@abstractmethod
def download_tiles(self) -> list[str]:
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/england.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class England1MProvider(WCSProvider, DTMProvider):
_is_community = True
_instructions = None
_is_base = False
_extents = (55.87708724246775, 49.85060473351981, 2.0842821419111135, -7.104775741839742)
_extents = [(55.87708724246775, 49.85060473351981, 2.0842821419111135, -7.104775741839742)]

_url = "https://environment.data.gov.uk/geoservices/datasets/13787b9a-26a4-4775-8523-806d13af58fc/wcs" # pylint: disable=line-too-long
_wcs_version = "2.0.1"
Expand Down
5 changes: 4 additions & 1 deletion maps4fs/generator/dtm/finland.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FinlandProvider(WCSProvider, DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True
_is_base = False
_extents = (70.09, 59.45, 31.59, 19.08)
_extents = [(70.09, 59.45, 31.59, 19.08)]

_url = "https://avoin-karttakuva.maanmittauslaitos.fi/ortokuvat-ja-korkeusmallit/wcs/v2"
_wcs_version = "2.0.1"
Expand All @@ -38,6 +38,9 @@ class FinlandProvider(WCSProvider, DTMProvider):
)

def get_wcs_instance_parameters(self):
if not self.user_settings.api_key:
raise ValueError("API Key is required for this provider.")

settings = super().get_wcs_instance_parameters()
settings["auth"] = Authentication(
username=self.user_settings.api_key, password=self.user_settings.api_key
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/flanders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FlandersProvider(WCSProvider, DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True
_is_base = False
_extents = (51.5150730375579684, 50.6694992827160817, 5.9444417082210812, 2.5170092434134252)
_extents = [(51.5150730375579684, 50.6694992827160817, 5.9444417082210812, 2.5170092434134252)]

_url = "https://geo.api.vlaanderen.be/el-dtm/wcs"
_wcs_version = "1.0.0"
Expand Down
12 changes: 11 additions & 1 deletion maps4fs/generator/dtm/france.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ class FranceProvider(DTMProvider):
_url = "https://data.cquest.org/ign/rgealti/repack/cog/RGEALTI_2-0_1M_COG_LAMB93-IGN69_FXX.vrt"
_is_base = False
# no extents, because it also has a few colonies throughout the world
# _extents = (54.148101, 51.153098, 11.754046, 6.505772)
_extents = [
(51.2, 41.333, 9.55, -5.225), # France
(8.6038842, 1.1710017, -61.414905, -56.4689543), # Guyana
(16.5144664, 15.8320085, -61.809764, -61.0003663), # Guadeloupe
(14.8787029, 14.3948596, -61.2290815, -60.8095833), # Martinique
(-12.6365902, -13.0210119, 45.0183298, 45.2999917), # Mayotte
(-20.8717136, -21.3897308, 55.2164268, 55.8366924), # Reunion
(18.1375569, 17.670931, -63.06639, -62.5844019), # Saint Barthelemy
(18.1902778, 17.8963535, -63.3605643, -62.7644063), # Saint Martin
(47.365, 46.5507173, -56.6972961, -55.9033333), # Saint Pierre and Miquelon
]

def download_tiles(self) -> list[str]:
with rasterio.open(
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/hessen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HessenProvider(WCSProvider, DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True
_is_base = False
_extents = (51.66698, 49.38533, 10.25780, 7.72773)
_extents = [(51.66698, 49.38533, 10.25780, 7.72773)]

_url = "https://inspire-hessen.de/raster/dgm1/ows"
_wcs_version = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/italy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ItalyProvider(WCSProvider, DTMProvider):
_is_community = True
_instructions = None
_is_base = False
_extents = (47.15570815704503, 35.177652867276855, 19.720144130809693, 6.527697471770745)
_extents = [(47.15570815704503, 35.177652867276855, 19.720144130809693, 6.527697471770745)]

_url = "http://tinitaly.pi.ingv.it/TINItaly_1_1/wcs"
_wcs_version = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MecklenburgVorpommernProvider(WCSProvider, DTMProvider):
_instructions = None
_is_base = False
_settings = MecklenburgVorpommernProviderSettings
_extents = (54.8, 53, 14.5, 10.5)
_extents = [(54.8, 53, 14.5, 10.5)]

_url = "https://www.geodaten-mv.de/dienste/dgm_wcs"
_wcs_version = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/niedersachsen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NiedersachsenProvider(WMSProvider, DTMProvider):
"to smooth the data."
)
_is_base = False
_extents = (54.148101, 51.153098, 11.754046, 6.505772)
_extents = [(54.148101, 51.153098, 11.754046, 6.505772)]

_url = "https://opendata.lgln.niedersachsen.de/doorman/noauth/dgm_wms"
_source_crs = "EPSG:25832"
Expand Down
4 changes: 3 additions & 1 deletion maps4fs/generator/dtm/norway.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class NorwayProvider(WCSProvider, DTMProvider):
_is_community = True
_instructions = None
_is_base = False
_extents = (72.1016879476356962, 57.2738836442695103, 33.3365910058243742, -2.0075617181675725)
_extents = [
(72.1016879476356962, 57.2738836442695103, 33.3365910058243742, -2.0075617181675725)
]

_instructions = (
"This is a topobathy dataset which means it includes water depth information as well. "
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/nrw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NRWProvider(WCSProvider, DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True
_is_base = False
_extents = (52.6008271, 50.1506045, 9.5315425, 5.8923538)
_extents = [(52.6008271, 50.1506045, 9.5315425, 5.8923538)]

_url = "https://www.wcs.nrw.de/geobasis/wcs_nw_dgm"
_wcs_version = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/rema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class REMAProvider(DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True

_extents = (-53.5443873459092, -53.5443873459092, 179.99698443265999, -180)
_extents = [(-53.5443873459092, -53.5443873459092, 179.99698443265999, -180)]

_instructions = (
"This provider source includes 2 meter DEM data for the entire Antarctic region below 53 "
Expand Down
4 changes: 3 additions & 1 deletion maps4fs/generator/dtm/sachsenanhalt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class SachsenAnhaltProvider(WCSProvider, DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True
_is_base = False
_extents = (53.0769416826493412, 50.8927195980075453, 13.3232545527125836, 10.5092298520646867)
_extents = [
(53.0769416826493412, 50.8927195980075453, 13.3232545527125836, 10.5092298520646867)
]

_url = "https://www.geodatenportal.sachsen-anhalt.de/wss/service/ST_LVermGeo_DGM1_WCS_OpenData/guest" # pylint: disable=line-too-long
_wcs_version = "1.0.0"
Expand Down
4 changes: 3 additions & 1 deletion maps4fs/generator/dtm/scotland.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class ScotlandProvider(DTMProvider):
"Coverage for Scotland is very limited. "
"Make sure to check the [coverage map](https://remotesensingdata.gov.scot/data#/map)."
)
_extents = (60.2151105070992756, 54.5525982243521881, -1.1045617513147328, -6.7070796770431951)
_extents = [
(60.2151105070992756, 54.5525982243521881, -1.1045617513147328, -6.7070796770431951)
]

_url = "https://srsp-catalog.jncc.gov.uk/search/product"

Expand Down
4 changes: 3 additions & 1 deletion maps4fs/generator/dtm/spain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class SpainProvider(WCSProvider, DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True
_is_base = False
_extents = (43.9299999999999997, 27.6299999999999990, 4.9400000000000004, -18.2100000000000009)
_extents = [
(43.9299999999999997, 27.6299999999999990, 4.9400000000000004, -18.2100000000000009)
]

_url = "https://servicios.idee.es/wcs-inspire/mdt"
_wcs_version = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/switzerland.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SwitzerlandProvider(DTMProvider):
_author = "[kbrandwijk](https://github.com/kbrandwijk)"
_is_community = True

_extents = (47.8308275417, 45.7769477403, 10.4427014502, 6.02260949059)
_extents = [(47.8308275417, 45.7769477403, 10.4427014502, 6.02260949059)]

_url = (
"https://ogd.swisstopo.admin.ch/services/swiseld/"
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/dtm/usgs_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class USGSWCSProvider(WCSProvider, DTMProvider):
_is_community = True
_instructions = None
_is_base = False
_extents = (50.0, 17.0, -64.0, -162.0)
_extents = [(50.0, 17.0, -64.0, -162.0)]

_url = "https://elevation.nationalmap.gov/arcgis/services/3DEPElevation/ImageServer/WCSServer"
_wcs_version = "1.0.0"
Expand Down

0 comments on commit 783810e

Please sign in to comment.