From 40649d2064124d70fc6b66dcec3f093e29b6c802 Mon Sep 17 00:00:00 2001 From: Michael Rudolf <rudolf@geo.tu-darmstadt.de> Date: Wed, 5 Mar 2025 10:21:55 +0100 Subject: [PATCH] Fixed a problem with empty API responses --- u4py/addons/web_services.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/u4py/addons/web_services.py b/u4py/addons/web_services.py index 38cef91..91d61cc 100644 --- a/u4py/addons/web_services.py +++ b/u4py/addons/web_services.py @@ -227,7 +227,9 @@ def _save_features( :return: A geodataframe with the features in EPSG:32632 :rtype: gp.GeoDataFrame """ - if isinstance(features, dict): + if len(features) == 0: + gdf = gp.GeoDataFrame(geometry=[]) + elif isinstance(features, dict): with open(out_fname + ".json", "wt") as geojson: json.dump(features, geojson) gdf = gp.read_file(out_fname + ".json").to_crs("EPSG:32632") @@ -288,7 +290,10 @@ def _query_server( restgeom = polygon_to_restapi( region.geometry[0], region.crs.to_string() ) - features = ms_lyr.select_by_location(restgeom) + try: + features = ms_lyr.select_by_location(restgeom) + except restapi.RestAPIException: + features = [] else: features = ms_lyr.query() return features -- GitLab