Skip to content

Commit

Permalink
'Support' some geojson files
Browse files Browse the repository at this point in the history
In case the geojson file of NSI is named like an Osmose extract (e.g. like US Iowa, or Quebec (CA), it'll support include/exclude statements for those subregions.
  • Loading branch information
Famlam authored and frodrigo committed Nov 18, 2024
1 parent 80fae44 commit be3fbba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
37 changes: 37 additions & 0 deletions plugins/TagFix_Brand.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,41 @@ class father:
a.father = father()
a.init(None)

# Include CA, exclude CA-QC
assert a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"})

def test_CA_ON(self):
a = TagFix_Brand(None)
class _config:
options = {"country": "CA-ON"}
class father:
config = _config()
a.father = father()
a.init(None)

# Include CA, exclude CA-QC
assert a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"})

def test_CA_QC_LAN(self):
a = TagFix_Brand(None)
class _config:
options = {"country": "CA-QC-LAN"}
class father:
config = _config()
a.father = father()
a.init(None)

# Include CA, exclude CA-QC
assert not a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"})

def test_CA_QC(self):
a = TagFix_Brand(None)
class _config:
options = {"country": "CA-QC"}
class father:
config = _config()
a.father = father()
a.init(None)

# Include CA, exclude CA-QC
assert not a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"})
8 changes: 5 additions & 3 deletions plugins/modules/name_suggestion_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ def download_nsi():
def nsi_rule_applies(locationSet, country):
if not "include" in locationSet and not "exclude" in locationSet:
return True
incl = set(map(lambda c: str(c).lower().replace('.geojson', '', 1), locationSet["include"] if "include" in locationSet else []))
excl = set(map(lambda c: str(c).lower().replace('.geojson', '', 1), locationSet["exclude"] if "exclude" in locationSet else []))
# For extract with country="AB-CD-EF", check "AB-CD-EF", then "AB-CD", then "AB", then worldwide ("001")
for c in ['-'.join(country.lower().split("-")[:i]) for i in range(country.count("-")+1, 0, -1)]:
if "exclude" in locationSet and c in locationSet["exclude"]:
if c in excl:
return False
if "include" in locationSet and c in locationSet["include"]:
if c in incl:
return True
return not "include" in locationSet or "001" in locationSet["include"]
return len(incl) == 0 or "001" in locationSet["include"]


# Gets all valid (shop, amenity, ...) names that exist within a certain country
Expand Down

0 comments on commit be3fbba

Please sign in to comment.