query-b86b3d41076c22d5c50061f16bf7b3e6
title: The northernmost city in Africa SELECT ?x ?xLabel ?latitude ?longitude WITH {
select all the cities in a continent
SELECT ?x WHERE { ?x wdt:P31/wdt:P279* wd:Q515 . # x is a type of city (big city, city state etc) ?x wdt:P17 ?country . ?country wdt:P30 wd:Q15 . # <== put the continent here MINUS { ?country wdt:P31 wd:Q3024240 } # current countries only } } AS %cities
get each city's latitude/longitude
sort depending on east/west or north/south
select the first one
WHERE {
INCLUDE %cities
?x p:P625 [
psv:P625 [
wikibase:geoLatitude ?latitude ;
wikibase:geoLongitude ?longitude ;
]
]
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC (?latitude) # ASC for southernmost; DESC for northernmost
ORDER BY ASC (?longitude) # ASC for westernmost; DESC for easternmost
LIMIT 1
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 psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#title: The northernmost city in Africa
SELECT ?x ?xLabel ?latitude ?longitude
# get each city's latitude/longitude
# sort depending on east/west or north/south
# select the first one
WHERE {
{
# select all the cities in a continent
SELECT ?x WHERE {
?x wdt:P31/wdt:P279* wd:Q515 . # x is a type of city (big city, city state etc)
?x wdt:P17 ?country .
?country wdt:P30 wd:Q15 . # <== put the continent here
MINUS { ?country wdt:P31 wd:Q3024240 } # current countries only
} } ?x p:P625 [
psv:P625 [
wikibase:geoLatitude ?latitude ;
wikibase:geoLongitude ?longitude ;
]
]
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC (?latitude) # ASC for southernmost; DESC for northernmost
#ORDER BY ASC (?longitude) # ASC for westernmost; DESC for easternmost
LIMIT 1
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?country")
v1("?latitude"):::projected
v4("?longitude"):::projected
v2("?x"):::projected
a1((" "))
a3((" "))
a2((" "))
c6(["wd:Q15"]):::iri
c7(["wd:Q3024240"]):::iri
c13(["bd:serviceParam"]):::iri
c3(["wd:Q515"]):::iri
c15(["#91;AUTO_LANGUAGE#93;,en"]):::literal
v2 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c3
v2 --"p:direct/P17"--> v3
v3 --"p:direct/P30"--> c6
subgraph minus0["MINUS"]
style minus0 stroke-width:6px,fill:pink,stroke:red;
v3 --"p:direct/P31"--> c7
end
a2 --"wikibase:geoLatitude"--> v1
a2 --"wikibase:geoLongitude"--> v4
a3 --"p:statement/value/P625"--> a2
v2 --"p:P625"--> a3
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c13 --"wikibase:language"--> c15
end