aboutsummaryrefslogtreecommitdiffstats
path: root/gis-observation-map
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2023-09-27 14:56:36 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-09-27 14:56:36 +0200
commit70807f9c3d2932cdcd73b2025fdcf25a32dae76e (patch)
treeb5a44e949b412dc9c99eacc85e911760fb66b363 /gis-observation-map
parent06dc49bc98e988cfa13c9ce66655fb10813db09f (diff)
Get taxon redlist categories.
Diffstat (limited to 'gis-observation-map')
-rwxr-xr-xgis-observation-map37
1 files changed, 34 insertions, 3 deletions
diff --git a/gis-observation-map b/gis-observation-map
index 9c478c7..4fe06cf 100755
--- a/gis-observation-map
+++ b/gis-observation-map
@@ -21,6 +21,7 @@
import argparse
import sys
import json
+import re
import requests
import configparser
from requests.exceptions import HTTPError
@@ -380,7 +381,10 @@ def getTaxonLists():
if not i in taxonLists2[d0]:
raise Exception(f'missing taxon #{i} (in {d}) from {d0}')
- return taxonLists2
+ i = getTaxonList(taxonLists, taxonLists2, 'TaxonIsRedlisted', 'Redlisted species')
+ taxonRedlistCategories = getTaxonRedlistCategories(taxonLists, i)
+
+ return taxonLists2, taxonRedlistCategories
def getTaxonList(taxonLists, taxonLists2, key, name):
i = None
@@ -402,7 +406,34 @@ def getTaxonList(taxonLists, taxonLists2, key, name):
raise Exception(f'expected list, got {type(resp)}')
taxonLists2[key] = {r['id'] for r in resp}
-taxonLists = getTaxonLists()
+ return i
+
+def getTaxonRedlistCategories(taxonLists, i):
+ taxonRedlistCategories = {}
+ r = re.compile(r'\(([A-Z][A-Z])\)\Z')
+ for t in taxonLists:
+ if 'parentId' not in t.keys() or t['parentId'] != i:
+ continue
+ name = t['name']
+ c = r.search(name)
+ if not c:
+ raise Exception(f'invalid redlist name "{name}"')
+ c = c.group(1)
+
+ resp = requests.get(
+ artDataBankenURL + f'/species-observation-system/v1/TaxonLists/{t["id"]}/Taxa',
+ headers=artDataBankenHeaders
+ )
+ resp.raise_for_status()
+ resp = resp.json()
+ if type(resp) != list:
+ raise Exception(f'expected list, got {type(resp)}')
+ for t in resp:
+ j = t['id']
+ if j in taxonRedlistCategories.keys():
+ raise Exception(f'duplicate redlist classification for taxon #{j}')
+ taxonRedlistCategories[j] = c
+ return taxonRedlistCategories
geograficsFilter = {
'geometries': geometricFilter(geometries),
@@ -410,7 +441,7 @@ geograficsFilter = {
'considerObservationAccuracy': True,
'considerDisturbanceRadius': True
}
-print(json.dumps(geograficsFilter, indent=4))
+taxonLists, taxonRedlistCategories = getTaxonLists()
exit()
topo_maps = ['Topografi 10', 'Topografi 50', 'Topografi 100']