diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2023-09-27 19:59:53 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2023-09-27 19:59:53 +0200 |
commit | 16332c374f8c134c5413eddb5b490048f7841ce5 (patch) | |
tree | a524e1e9c99a25765afdd749a1193cb7ee4dbaa2 /gis-observation-map | |
parent | 9312e1b3513100c229fc67308bddf9132b284c9e (diff) |
Fix scale-based visibility logic.
Diffstat (limited to 'gis-observation-map')
-rwxr-xr-x | gis-observation-map | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/gis-observation-map b/gis-observation-map index afc4071..481dd3a 100755 --- a/gis-observation-map +++ b/gis-observation-map @@ -335,7 +335,7 @@ artDataBankenHeaders = { 'Ocp-Apim-Subscription-Key': config['ArtDataBanken']['Subscription-Key'] } -def getObservations(taxonLists, taxonRedlistCategories, data): +def getObservations(taxonLists, taxonRedlistCategories, searchFilter): # https://api-portal.artdatabanken.se/docs/services/sos-api-v1/operations/Exports_DownloadGeoJson headers = artDataBankenHeaders.copy() headers['Content-Type'] = 'application/json' @@ -352,7 +352,7 @@ def getObservations(taxonLists, taxonRedlistCategories, data): artDataBankenURL + '/species-observation-system/v1/Exports/Download/GeoJson', headers=headers, params=params, - data=json.dumps(data) + data=json.dumps(searchFilter) ) resp.raise_for_status() @@ -396,10 +396,8 @@ def getObservations(taxonLists, taxonRedlistCategories, data): json.dump(obs, fp, indent=2, ensure_ascii=False) if projectInstance is not None: - layer = QgsVectorLayer( - path.as_posix() + '''|subset="IsPositiveObservation" AND "IsNaturalOccurrence" AND "CoordinateUncertaintyInMeters" <= 250''', - 'Fynd', 'ogr' - ) + query = '''"IsPositiveObservation" AND "IsNaturalOccurrence" AND "CoordinateUncertaintyInMeters" <= 250''' + layer = QgsVectorLayer(path.as_posix() + f'|subset={query}', 'Fynd', 'ogr') if not layer.isValid(): raise Exception(f'ERROR: {path}: failed to load in QGIS') if 'QGIS' in config.keys() and 'style' in config['QGIS']: @@ -649,7 +647,6 @@ getObservations(taxonLists, taxonRedlistCategories, searchFilter) topo_maps = ['Topografi 10', 'Topografi 50', 'Topografi 100'] if projectInstance is not None: - currentMaxScale = 1 basedir = Path(args.topo_basedir) basedir = basedir.expanduser() @@ -703,22 +700,24 @@ if projectInstance is not None: lyr = lyr.layer() lyr.setReadOnly(True) lyr.setFlags(QgsMapLayer.Removable) - - if topo == 'Topografi 10': - lyr.setScaleBasedVisibility(True) - lyr.setMaximumScale(currentMaxScale) - currentMaxScale = 50000 - lyr.setMinimumScale(currentMaxScale) - elif topo == 'Topografi 50': - lyr.setScaleBasedVisibility(True) - lyr.setMaximumScale(currentMaxScale) - currentMaxScale = 100000 - lyr.setMinimumScale(currentMaxScale) - elif topo == 'Topografi 100': - lyr.setScaleBasedVisibility(True) - lyr.setMaximumScale(currentMaxScale) - currentMaxScale = 10000000 - lyr.setMinimumScale(currentMaxScale) rootGroup.setExpanded(False) + maxScale = 1 + for topo in topo_maps: + minScale = None + if topo == 'Topografi 10': + minScale = 50000 + elif topo == 'Topografi 50': + minScale = 100000 + elif topo == 'Topografi 100': + minScale = 10000000 + + if minScale is not None: + for lt in QgsProject.instance().layerTreeRoot().findGroup(topo).findLayers(): + lyr = lt.layer() + lyr.setScaleBasedVisibility(True) + lyr.setMinimumScale(minScale) + lyr.setMaximumScale(maxScale) + maxScale = minScale + projectInstance.write() |