From d5e1dccb6864ed691022dd9ed55eae9c116c0185 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 29 Sep 2023 01:04:13 +0200 Subject: Observations: factor out layername. --- gis-observation-map | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gis-observation-map b/gis-observation-map index 8f3f999..ea057e0 100755 --- a/gis-observation-map +++ b/gis-observation-map @@ -440,8 +440,6 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter): if obs['type'] == 'FeatureCollection' and 'features' in obs.keys() and type(obs['features']) == list: print(f'{len(obs["features"])} observations found', file=sys.stderr) - if 'name' not in obs.keys() or obs['name'] is None: - obs['name'] = 'Fynd' for feat in obs['features']: if (type(feat) != dict or 'type' not in feat.keys() or feat['type'] != 'Feature' or 'properties' not in feat.keys() or type(feat['properties']) != dict): @@ -506,6 +504,9 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter): if args.observation_format is not None and drv.name.lower() != args.observation_format.lower(): print(f'WARN: overwriting observation file format to {drv.name}', file=sys.stderr) + layername = 'fynd' + obs['name'] = layername + if drv.name == geojson_drv.name: # for GeoJSON, don't reproject and pretty-print the output; this # is useful for manual inspection and/or debugging @@ -518,7 +519,7 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter): gdal.VectorTranslate( path.as_posix(), fp.name, format=drv.name, - layerName='Fynd', + layerName=layername, geometryType='POINT', accessMode='overwrite', reproject=True, dstSRS=target_srs) @@ -526,7 +527,7 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter): if projectInstance is not None: query = '''"IsPositiveObservation" AND "IsNaturalOccurrence" AND "CoordinateUncertaintyInMeters" <= 250''' - layer = QgsVectorLayer(path.as_posix() + f'|subset={query}', 'Fynd', 'ogr') + layer = QgsVectorLayer(f'{path.as_posix()}|layername={layername}|subset={query}', layername.title(), 'ogr') if not layer.isValid(): raise Exception(f'ERROR: {path}: failed to load in QGIS') if args.observation_style is not None: -- cgit v1.2.3