-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_admin_areas_for_country.rq.liquid
29 lines (28 loc) · 1.35 KB
/
select_admin_areas_for_country.rq.liquid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
SELECT DISTINCT ?adminArea
(MIN(?primarySort) AS ?primarySort)
(GROUP_CONCAT(DISTINCT REPLACE(STR(?adminAreaType), '^.*/', ''); SEPARATOR=" ") AS ?adminAreaTypes) {
{
VALUES (?adminArea ?primarySort ?adminAreaType) { (wd:{{ config.country_wikidata_id }} 1 wd:Q6256) }
} UNION {
# Find regional admin areas of this country (generally FLACSen)
?adminArea wdt:P17 wd:{{ config.country_wikidata_id }} ;
wdt:P31/wdt:P279* wd:{{ config.regional_admin_area_type_id }}
VALUES (?primarySort ?adminAreaType) { (2 wd:{{ config.regional_admin_area_type_id }}) }
} UNION {
# Find cities or municipalities with populations of over 250k
VALUES ?adminAreaType { wd:Q515 wd:Q15284 }
?adminArea wdt:P17 wd:{{ config.country_wikidata_id }} ;
wdt:P31/wdt:P279* ?adminAreaType ;
wdt:P1082 ?population .
FILTER (?population > 250000)
VALUES ?primarySort { 3 }
}{% if config.additional_admin_area_ids %} UNION {
VALUES (?adminArea ?primarySort ?adminAreaType) {
{%- for admin_area_id in config.additional_admin_area_ids %}
(wd:{{ admin_area_id }} 4 wd:Q24238356)
{%- endfor %}
}
}{% endif %}
# Remove admin areas that have ended
FILTER NOT EXISTS { ?adminArea wdt:P582|wdt:P576 ?adminAreaEnd . FILTER (?adminAreaEnd < NOW()) }
} GROUP BY ?adminArea ORDER BY ?primarySort ?adminArea