query-28a7950c5ddb0e581382b23cd6bcf7c6
Elements that are close from a centroïd of a country
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map
SELECT ?item ?country ?coord ?dist {
VALUES ?country { wd:Q40 } .
OPTIONAL{?country wdt:P5140 ?centerGeog .}
OPTIONAL{?country wdt:P625 ?Coords .}
BIND(COALESCE(?centerGeog,?Coords) as ?center)
SERVICE wikibase:around {
?item wdt:P625 ?coord .
bd:serviceParam wikibase:center ?center .
bd:serviceParam wikibase:radius "50" .
bd:serviceParam wikibase:distance ?dist .
bd:serviceParam wikibase:geoGlobe ?globe .
} .
BIND(COALESCE(?globe,wd:Q2) as ?Globe)
FILTER (?Globe =wd:Q2)
MINUS { ?item wdt:P17 [] } .
MINUS { ?item (wdt:P31/wdt:P279*) wd:Q4830453. } # exclude ENTREPRISES
MINUS { ?item (wdt:P31/wdt:P279*) wd:Q15893266. } # exclude old entities
MINUS { ?item wdt:P576 _:b2. } # remove items with P576 (dissolved, abolished or demolished) as a main property
} ORDER BY ?dist
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?Coords")
v10("?Globe")
v6("?center")
v4("?centerGeog")
v8("?coord"):::projected
v3("?country"):::projected
v1("?dist"):::projected
v9("?globe")
v7("?item"):::projected
a1((" "))
a4((" "))
a2((" "))
a3((" "))
c15(["wd:Q15893266"]):::iri
c14(["wd:Q4830453"]):::iri
c5(["bd:serviceParam"]):::iri
c8(["50"]):::literal
f0[["?Globe = 'wd:Q2'"]]
f0 --> v10
bind1[/VALUES ?country/]
bind1-->v3
bind10(["wd:Q40"])
bind10 --> bind1
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P5140".-> v4
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P625".-> v5
end
bind2[/"?centerGeog?Coords"/]
v4 --o bind2
v5 --o bind2
bind2 --as--o v6
subgraph s1["http://wikiba.se/ontology#around"]
style s1 stroke-width:4px;
v7 --"wdt:P625"--> v8
c5 --"wikibase:center"--> v6
c5 --"wikibase:radius"--> c8
c5 --"wikibase:distance"--> v1
c5 --"wikibase:geoGlobe"--> v9
end
bind3[/"?globe'wd:Q2'"/]
v9 --o bind3
bind3 --as--o v10
subgraph minus4["MINUS"]
style minus4 stroke-width:6px,fill:pink,stroke:red;
v7 --"wdt:P17"--> a1
end
subgraph minus5["MINUS"]
style minus5 stroke-width:6px,fill:pink,stroke:red;
v7 --"wdt:P31"--> a2
a2 --"wdt:P279"--> c14
end
subgraph minus6["MINUS"]
style minus6 stroke-width:6px,fill:pink,stroke:red;
v7 --"wdt:P31"--> a3
a3 --"wdt:P279"--> c15
end
subgraph minus7["MINUS"]
style minus7 stroke-width:6px,fill:pink,stroke:red;
v7 --"wdt:P576"--> a4
end