From 1154471abecfd967dd566160243174fe06973bcf Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 1 Oct 2023 22:19:14 +0200 Subject: =?UTF-8?q?Replace=20`in=20=E2=80=A6.keys()`=20usage=20with=20`?= =?UTF-8?q?=E2=80=A6.get()`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gis-observation-map | 21 ++++++++++----------- 1 file 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) continue - 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) continue - 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: continue 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: continue - 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 rootGroup.setItemVisibilityChecked(False) -- cgit v1.2.3