path: root/gis-observation-map
diff options
authorGuilhem Moulin <guilhem@fripost.org>2023-10-01 22:19:14 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-10-01 22:19:14 +0200
commit1154471abecfd967dd566160243174fe06973bcf (patch)
tree7c99c0f2f40591fd7005af1fc6b06df2bf5add3c /gis-observation-map
parent9abfea72dfa8f97accd208fc6c01605af7bafe7b (diff)
Replace `in ….keys()` usage with `….get()`.
Diffstat (limited to 'gis-observation-map')
1 files changed, 10 insertions, 11 deletions
diff --git a/gis-observation-map b/gis-observation-map
index bc1ab73..18d88f6 100755
--- a/gis-observation-map
+++ b/gis-observation-map
@@ -59,7 +59,7 @@ programName = 'gis-observation-map'
with Path(xdg_config_home()).joinpath(programName).joinpath('config.yml').open(mode='r') as fp:
config = yaml.load(fp, Loader=yaml.FullLoader)
-if 'QGIS' not in config.keys() or config['QGIS'] is None:
+if config.get('QGIS') is None:
config['QGIS'] = {}
def ePath(v):
@@ -86,7 +86,7 @@ parser.add_argument('--project-home', type=ePath, metavar='DIRECTORY',
help='Project home directory')
parser.add_argument('--project-name', metavar='NAME',
help='Project filename (and title) relative to --project-home')
-parser.add_argument('--topo-basedir', default=config['QGIS']['topo-basedir'], type=ePath, metavar='DIRECTORY',
+parser.add_argument('--topo-basedir', default=config['QGIS'].get('topo-basedir'), type=ePath, metavar='DIRECTORY',
help='Base directory for "Topografi 10", "Topografi 50", etc.')
parser_geom = parser.add_argument_group('Geographic area of interest')
parser_geom.add_argument('--geometry-style', type=ePath, dest='geometry_style', metavar='STYLE_FILE',
@@ -106,7 +106,7 @@ parser_obs.add_argument('--observation-file', type=Path, metavar='NAME',
help='Observation file name relative to --project-home')
parser_obs.add_argument('--observation-format', metavar='FORMAT',
help='Format for the observation file')
-parser_obs.add_argument('--observation-style', default=config['QGIS']['observation-style'], metavar='STYLE_FILE', type=ePath,
+parser_obs.add_argument('--observation-style', default=config['QGIS'].get('observation-style'), metavar='STYLE_FILE', type=ePath,
help='QGIS Layer Style File (*.qml) to apply to the observation layer (default: %(default)s)')
parser_filter = parser.add_argument_group('Search filter')
parser_filter.add_argument('--data-provider', nargs='*', metavar='IDENTIFIER', default=[],
@@ -448,19 +448,18 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter):
if 'crs' not in obs.keys():
print('WARN: GeoJSON output lacks CRS', file=sys.stderr)
- if obs['type'] == 'FeatureCollection' and 'features' in obs.keys() and type(obs['features']) == list:
+ if obs['type'] == 'FeatureCollection' and type(obs.get('features')) == list:
print(f'{len(obs["features"])} observations found', file=sys.stderr)
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):
+ properties = feat['properties']
+ if type(feat) != dict or feat.get('type') != 'Feature' or type(properties) != dict:
print('WARN: Invalid feature in GeoJSON output', file=sys.stderr)
- properties = feat['properties']
- if 'DyntaxaTaxonId' not in properties.keys() or properties['DyntaxaTaxonId'] is None:
+ tid = properties.get('DyntaxaTaxonId')
+ if tid is None:
print('WARN: Feature lacks taxon ID', file=sys.stderr)
- tid = properties['DyntaxaTaxonId']
for k, taxonList in taxonLists.items():
v = (tid in taxonList)
if k in properties.keys() and properties[k] != v:
@@ -669,7 +668,7 @@ def getTaxonRedlistCategories(taxonLists, i):
taxonRedlistCategories = {}
r = re.compile(r'\(([A-Z][A-Z])\)\Z')
for t in taxonLists:
- if 'parentId' not in t.keys() or t['parentId'] != i:
+ if t.get('parentId') != i:
name = t['name']
c = r.search(name)
@@ -932,7 +931,7 @@ if args.topo_basedir is not None and projectInstance is not None:
rootGroup = QgsProject.instance().layerTreeRoot().findGroup(topo)
if rootGroup is None:
- if topo in idxContains.keys() and not idxContains[topo]:
+ if idxContains.get(topo) == False:
# if the tileset doesn't entirely covers the area of interest,
# then uncheck the layer group and disable scale-based visibility