aboutsummaryrefslogtreecommitdiffstats
path: root/gis-observation-map
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2023-10-02 03:24:18 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-10-03 01:47:38 +0200
commit0d56538429885a5b2a80d549f5026712b9e5cdc8 (patch)
treea66e69b4da3472989d9770ebd5342c86fd28a411 /gis-observation-map
parent746eb3900573972afe8598b0606cc223b8928b79 (diff)
Add support for extra layers (such as “Värdekärnor skog”).
Diffstat (limited to 'gis-observation-map')
-rwxr-xr-xgis-observation-map54
1 files changed, 54 insertions, 0 deletions
diff --git a/gis-observation-map b/gis-observation-map
index 9c58b8e..248b63a 100755
--- a/gis-observation-map
+++ b/gis-observation-map
@@ -36,6 +36,7 @@ from qgis.core import (
QgsApplication,
QgsCoordinateReferenceSystem,
QgsLayerDefinition,
+ QgsLayerTreeLayer,
QgsLayerTreeModel,
QgsMapLayer,
QgsPointXY,
@@ -827,6 +828,59 @@ if not args.no_observations:
getObservations(taxonLists, taxonRedlistCategories, searchFilter)
+if args.project_home is not None and projectInstance is not None:
+ for item in config['QGIS'].get('NatureValue', []):
+ name = item['Name'].title()
+ srcPath = Path(item['Source']).expanduser()
+ dstPath = args.project_home.joinpath(srcPath.name)
+
+ fmt = item.get('Format')
+ if fmt is not None:
+ drv = ogr.GetDriverByName(fmt)
+ if drv is None:
+ raise Exception(f'Invalid format {fmt}')
+ suffixes = drv.GetMetadataItem(gdal.DMD_EXTENSIONS).split(' ')
+ if dstPath.suffix[1:] not in suffixes:
+ dstPath = dstPath.with_suffix('.' + suffixes[0])
+
+ layerName = item.get('LayerName')
+ srcDs = gdal.OpenEx(
+ srcPath.as_posix(),
+ gdal.OF_VECTOR,
+ open_options=item.get('SourceOpenOptions', [])
+ )
+
+ dstPath = dstPath.as_posix()
+ gdal.VectorTranslate(
+ dstPath, srcDs, format=fmt,
+ accessMode='overwrite',
+ reproject=True, dstSRS=target_srs,
+ clipDst=clipGeometry.ExportToWkt() if item.get('Clip', True) else None,
+ datasetCreationOptions=item.get('DatasetCreationOptions', []),
+ layerCreationOptions=item.get('LayerCreationOptions', []),
+ geometryType=item.get('GeometryType'),
+ skipFailures=True,
+ layers=[layerName] if layerName is not None else None
+ )
+ srcDs = None
+
+ if layerName is not None:
+ dstPath = f'{dstPath}|layername={layerName}'
+ layer = QgsVectorLayer(dstPath, name, 'ogr')
+ if not layer.isValid():
+ raise Exception(f'ERROR: {dstPath}: failed to load in QGIS')
+ projectInstance.addMapLayer(layer, False)
+ layerTreeRoot.insertChildNode(-1, QgsLayerTreeLayer(layer)) # last
+ layer.setReadOnly(True)
+
+ isVisible = item.get('Visible', True)
+ layerTreeRoot.findLayer(layer.id()).setItemVisibilityChecked(isVisible)
+
+ style = item.get('Style')
+ if style is not None:
+ style = Path(style).expanduser()
+ layer.loadNamedStyle(style.as_posix())
+
topo_maps = ['Topografi 10', 'Topografi 50', 'Topografi 100']
if args.topo_basedir is not None and projectInstance is not None:
idxContains = {}