From 9f17020f0d821fc8005f659f1dd49b5e08804431 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 29 Sep 2023 00:29:27 +0200 Subject: Handle the case where no observations are found. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Artdatabanken returns an empty response in that case (Content-Length: 0), but we need a valid GeoJSON file without any features. Unfortunately QGIS appears unable to load such files though, due to the ‘|subset=’ filter which references unknown fields. --- gis-observation-map | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gis-observation-map') diff --git a/gis-observation-map b/gis-observation-map index 91abd1e..966d438 100755 --- a/gis-observation-map +++ b/gis-observation-map @@ -427,7 +427,10 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter): ) resp.raise_for_status() - obs = resp.json() + if resp.text == '': + obs = { 'crs': 'EPSG:4326', 'type': 'FeatureCollection', 'features': [] } + else: + obs = resp.json() # https://www.rfc-editor.org/rfc/rfc7946 if obs is None or type(obs) != dict or 'type' not in obs.keys(): -- cgit v1.2.3