Skip to content

Commit 2af4408

Browse files
committed
'Support' some geojson files
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.
1 parent f95f929 commit 2af4408

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

plugins/TagFix_Brand.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,41 @@ class father:
153153
a.father = father()
154154
a.init(None)
155155

156+
# Include CA, exclude CA-QC
156157
assert a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"})
158+
159+
def test_CA_ON(self):
160+
a = TagFix_Brand(None)
161+
class _config:
162+
options = {"country": "CA-ON"}
163+
class father:
164+
config = _config()
165+
a.father = father()
166+
a.init(None)
167+
168+
# Include CA, exclude CA-QC
169+
assert a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"})
170+
171+
def test_CA_QC_LAN(self):
172+
a = TagFix_Brand(None)
173+
class _config:
174+
options = {"country": "CA-QC-LAN"}
175+
class father:
176+
config = _config()
177+
a.father = father()
178+
a.init(None)
179+
180+
# Include CA, exclude CA-QC
181+
assert not a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"})
182+
183+
def test_CA_QC(self):
184+
a = TagFix_Brand(None)
185+
class _config:
186+
options = {"country": "CA-QC"}
187+
class father:
188+
config = _config()
189+
a.father = father()
190+
a.init(None)
191+
192+
# Include CA, exclude CA-QC
193+
assert not a.node(None, {"name": "National Bank", "amenity": "bank", "atm": "yes"})

plugins/modules/name_suggestion_index.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ def download_nsi():
3939
def nsi_rule_applies(locationSet, country):
4040
if not "include" in locationSet and not "exclude" in locationSet:
4141
return True
42+
incl = set(map(lambda c: str(c).lower().replace('.geojson', '', 1), locationSet["include"] if "include" in locationSet else []))
43+
excl = set(map(lambda c: str(c).lower().replace('.geojson', '', 1), locationSet["exclude"] if "exclude" in locationSet else []))
4244
# For extract with country="AB-CD-EF", check "AB-CD-EF", then "AB-CD", then "AB", then worldwide ("001")
4345
for c in ['-'.join(country.lower().split("-")[:i]) for i in range(country.count("-")+1, 0, -1)]:
44-
if "exclude" in locationSet and c in locationSet["exclude"]:
46+
if c in excl:
4547
return False
46-
if "include" in locationSet and c in locationSet["include"]:
48+
if c in incl:
4749
return True
48-
return not "include" in locationSet or "001" in locationSet["include"]
50+
return len(incl) == 0 or "001" in locationSet["include"]
4951

5052

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

0 commit comments

Comments
 (0)