aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2023-09-28 01:56:33 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-09-28 12:33:07 +0200
commit9583fb67f02d7480022db6aaed345d179246abc2 (patch)
treea201d94565bdd03db90c07f61f51fd2cf15edd95
parent5847087aa2dc05bafdeb8bcfb57b9ccd1a5a2ecd (diff)
Add option --data-provider to filter by data provider.
-rwxr-xr-xgis-observation-map35
1 files changed, 35 insertions, 0 deletions
diff --git a/gis-observation-map b/gis-observation-map
index effc4b2..ec6a020 100755
--- a/gis-observation-map
+++ b/gis-observation-map
@@ -98,6 +98,8 @@ parser.add_argument('--observation-format', default='GPKG',
help='Format for the observation file (default: %(default)s)')
parser.add_argument('--style', default=config['QGIS']['style'], type=ePath,
help='QGIS Layer Style File (*.qml) to apply to the observation layer (default: %(default)s)')
+parser.add_argument('--data-provider', nargs='*', default=[],
+ help='Data provider identifier (for instance "Artportalen,MVM")')
args = parser.parse_args()
@@ -450,6 +452,34 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter):
projectInstance.addMapLayer(layer)
layerTreeRoot.findLayer(layer.id()).setItemVisibilityChecked(True)
+def mapDataProviders(names):
+ # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/DataProviders.md
+ params = {
+ 'cultureCode': 'sv-SE',
+ 'includeProvidersWithNoObservations': 'false',
+ }
+ resp = requests.get(
+ artDataBankenURL + '/species-observation-system/v1/DataProviders',
+ headers=artDataBankenHeaders
+ )
+ resp.raise_for_status()
+ dataProviders = resp.json()
+ #print(json.dumps(dataProviders, indent=2, ensure_ascii=False))
+
+ ids = []
+ for ns in names:
+ for name in ns.split(','):
+ i = None
+ for p in dataProviders:
+ if p['identifier'].lower() == name.lower():
+ if i is not None:
+ raise Exception(f'multiple results found for provider "{name}"')
+ i = p['id']
+ if i is None:
+ raise Exception(f'Unknown data provider "{name}"\nValid providers are {", ".join([p["identifier"] for p in dataProviders])}')
+ ids.append(i)
+ return ids
+
def getTaxonLists():
resp = requests.get(
artDataBankenURL + '/species-observation-system/v1/TaxonLists?cultureCode=en-US',
@@ -685,6 +715,11 @@ searchFilter['taxon'] = {
'taxonListOperator': 'Filter'
}
+if args.data_provider is not None:
+ searchFilter['dataProvider'] = {
+ 'ids': mapDataProviders(args.data_provider)
+ }
+
getObservations(taxonLists, taxonRedlistCategories, searchFilter)
topo_maps = ['Topografi 10', 'Topografi 50', 'Topografi 100']