From d8cbc8378b103832598af75a303c92742d1e5fad Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 27 Sep 2023 23:38:34 +0200 Subject: Add option --style for the observation layer style file. --- gis-observation-map | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gis-observation-map b/gis-observation-map index 5b750f0..35a2bd0 100755 --- a/gis-observation-map +++ b/gis-observation-map @@ -55,6 +55,12 @@ gpkg_drv = ogr.GetDriverByName('GPKG') geojson_drv = ogr.GetDriverByName('GeoJSON') programName = 'gis-observation-map' + +config = configparser.ConfigParser() +config.read(Path(xdg_config_home()).joinpath(programName).joinpath('config')) +if 'QGIS' not in config.keys() or config['QGIS'] is None: + config['QGIS'] = {} + parser = argparse.ArgumentParser( description='Create a QGIS project with observations from Artdatabanken.', prog = programName, @@ -68,12 +74,10 @@ parser.add_argument('--project-home', help='Project home directory') parser.add_argument('--geometry', nargs='*', default=[], help='Geometry filename(s)') parser.add_argument('--point', nargs='*', metavar='X,Y', default=[], help=f'Coordinates of interest (in {target_srs.GetName()})') parser.add_argument('--observation-format', default='GPKG', help='Format for the observation file (default: %(default)s)') +parser.add_argument('--style', default=config['QGIS']['style'], help='QGIS Layer Style File (*.qml) to apply to the observation layer (default: %(default)s)') args = parser.parse_args() -config = configparser.ConfigParser() -config.read(Path(xdg_config_home()).joinpath(programName).joinpath('config')) - if args.project_home is not None and args.project_name is not None: QgsApplication.setPrefixPath('/usr/bin/qgis', True) qgs = QgsApplication([], False) @@ -417,8 +421,8 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter): 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']: - style = Path(config['QGIS']['style']).expanduser() + if args.style is not None: + style = Path(args.style).expanduser() layer.loadNamedStyle(style.as_posix()) layer.setReadOnly(True) layer.setFlags(QgsMapLayer.Identifiable | QgsMapLayer.Searchable) -- cgit v1.2.3