aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2023-09-28 04:38:39 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-09-28 12:33:07 +0200
commitf5fd16dff41a71a78ee5ee8ba49ba73c11c37896 (patch)
tree46a7ec8d76c2e617c66d9de762dde9886d33421d
parent2f090cc384318068987d07b66e2764d4ffb22cf4 (diff)
Only make tile sets visible when the union covers all area of interest.
-rwxr-xr-xgis-observation-map26
1 files changed, 22 insertions, 4 deletions
diff --git a/gis-observation-map b/gis-observation-map
index 0d26ce0..5b75b89 100755
--- a/gis-observation-map
+++ b/gis-observation-map
@@ -229,6 +229,7 @@ def idx_intersects(idx_path, geometries):
locFieldIdx = layer.FindFieldIndex('location', True)
locations = []
+ union = None
feature = layer.GetNextFeature()
while feature is not None:
geometry = feature.GetGeometryRef()
@@ -238,9 +239,20 @@ def idx_intersects(idx_path, geometries):
loc = feature.GetField(locFieldIdx)
locations.append(loc)
break
+ if union is None:
+ union = geometry.Clone()
+ else:
+ union = union.Union(geometry)
feature = layer.GetNextFeature()
+
+ contains = True
+ for source_geometry in geometries:
+ if not union.Contains(source_geometry):
+ contains = False
+ break
+
ds = None
- return locations
+ return locations, contains
def find_qlr(basedir):
if not basedir.is_dir():
@@ -743,6 +755,7 @@ getObservations(taxonLists, taxonRedlistCategories, searchFilter)
topo_maps = ['Topografi 10', 'Topografi 50', 'Topografi 100']
if args.topo_basedir is not None:
+ idxContains = {}
for topo in topo_maps:
qlr_paths = []
d = args.topo_basedir.joinpath(topo)
@@ -756,7 +769,7 @@ if args.topo_basedir is not None:
idx = d.joinpath('index.geojson')
if idx.is_file():
- tiles = idx_intersects(idx.as_posix(), geometries)
+ tiles, idxContains[topo] = idx_intersects(idx.as_posix(), geometries)
for tile in tiles:
t = d.joinpath(tile)
qlr_path = find_qlr(t)
@@ -804,7 +817,12 @@ if args.topo_basedir is not None:
maxScale = 1
for topo in topo_maps:
minScale = None
- if topo == 'Topografi 10':
+ rootGroup = QgsProject.instance().layerTreeRoot().findGroup(topo)
+ if topo in idxContains.keys() and not idxContains[topo]:
+ # if the tileset doesn't entirely covers the area of interest,
+ # then uncheck the layer group and disable scale-based visibility
+ rootGroup.setItemVisibilityChecked(False)
+ elif topo == 'Topografi 10':
minScale = 50000
elif topo == 'Topografi 50':
minScale = 100000
@@ -812,7 +830,7 @@ if args.topo_basedir is not None:
minScale = 10000000
if minScale is not None:
- for lt in QgsProject.instance().layerTreeRoot().findGroup(topo).findLayers():
+ for lt in rootGroup.findLayers():
lyr = lt.layer()
lyr.setScaleBasedVisibility(True)
lyr.setMinimumScale(minScale)