diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2023-09-27 23:38:34 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2023-09-28 00:23:01 +0200 |
commit | d8cbc8378b103832598af75a303c92742d1e5fad (patch) | |
tree | 0f9a8a166fabae390a683234b7ae3857a9b62e81 | |
parent | 7ea0e2bc49b50d04177913b97131910d4725e51f (diff) |
Add option --style for the observation layer style file.
-rwxr-xr-x | gis-observation-map | 14 |
1 files 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) |