query-cee42b66445238b31cf322cd20c2ca1e
TODO
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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel ?countryLabel ?lat ?lon ?nlat ?slat ?elong ?wlong
{
{
select distinct ?country ?nlat ?stal ?elong ?wlong (count(?country) as ?count) where
{ # restrict query to countries that have only one set of bounding coords
?country wdt:P463 wd:Q1065 . #membership of UN taken as a proxy that this is a country
?country p:P1332 [psv:P1332 [wikibase:geoLatitude ?nlat;] ; ] . #get the northernmost coord for the country
?country p:P1333 [psv:P1333 [wikibase:geoLatitude ?slat;] ; ] . #if there is more than one northrn coord
?country p:P1334 [psv:P1334 [wikibase:geoLongitude ?elong;] ; ] . # the having( ?count=1) at the foot of this
?country p:P1335 [psv:P1335 [wikibase:geoLongitude ?wlong;] ; ] . # named-query will reject the country
} group by ?country ?nlat ?stal ?elong ?wlong having( ?count=1) }
{select ?item ?country (count(?item) as ?count2) where
{ # restrict query to airports that are in one country only
?item wdt:P31 wd:Q644371.
?item wdt:P17 ?country . #get country for the airport
# values ?airport_country {wd:Q30 wd:Q123 wd:Q456} #restrict the set of countries for which we will examine airports
} group by ?item ?country having (?count2=1) }
?item p:P625 [ps:P625 ?coord; psv:P625 [ # get coords for the airport
wikibase:geoLongitude ?lon;
wikibase:geoLatitude ?lat;] ; ] .
bind(if(?lat>?nlat,1,0) as ?ntest) #compare country northernmost latitude with the airport northern latitude
bind(if(?lat<?slat,1,0) as ?stest)
bind(if(?lon>?elong,1,0) as ?etest)
bind(if(?lon<?wlong,1,0) as ?wtest)
#check if any of the above tests=1 indicating there's a problem and we should display the row
bind(if(?ntest=1,1,if(?etest=1,1,if(?wtest=1,1,(if(?stest=1,1,0))))) as ?bigtest)
filter(?bigtest=1)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v17("?bigtest")
v10("?coord")
v8("?count")
v10("?count2")
v3("?country")
v6("?elong"):::projected
v15("?etest")
v9("?item"):::projected
v12("?lat"):::projected
v11("?lon"):::projected
v4("?nlat"):::projected
v13("?ntest")
v5("?slat"):::projected
v14("?stest")
v7("?wlong"):::projected
v16("?wtest")
a2((" "))
a1((" "))
a4((" "))
a3((" "))
a6((" "))
a5((" "))
a8((" "))
a7((" "))
a9((" "))
a10((" "))
c23(["en"]):::literal
c15(["wd:Q644371"]):::iri
c21(["bd:serviceParam"]):::iri
c3(["wd:Q1065"]):::iri
f0[["?bigtest = '1^^xsd:integer'"]]
f0 --> v17
f1[["?count = '1^^xsd:integer'"]]
f1 --> v8
v3 --"p:direct/P463"--> c3
a1 --"wikibase:geoLatitude"--> v4
a2 --"p:statement/value/P1332"--> a1
v3 --"p:P1332"--> a2
a3 --"wikibase:geoLatitude"--> v5
a4 --"p:statement/value/P1333"--> a3
v3 --"p:P1333"--> a4
a5 --"wikibase:geoLongitude"--> v6
a6 --"p:statement/value/P1334"--> a5
v3 --"p:P1334"--> a6
a7 --"wikibase:geoLongitude"--> v7
a8 --"p:statement/value/P1335"--> a7
v3 --"p:P1335"--> a8
bind3[/"count(?country)"/]
v3 --o bind3
bind3 --as--o v8
f4[["?count2 = '1^^xsd:integer'"]]
f4 --> v10
v9 --"p:direct/P31"--> c15
v9 --"p:direct/P17"--> v3
bind6[/"count(?item)"/]
v9 --o bind6
bind6 --as--o v10
a9 --"p:statement/P625"--> v10
a10 --"wikibase:geoLongitude"--> v11
a10 --"wikibase:geoLatitude"--> v12
a9 --"p:statement/value/P625"--> a10
v9 --"p:P625"--> a9
bind7[/"if(?lat > ?nlat,'1^^xsd:integer','0^^xsd:integer')"/]
v12 --o bind7
v4 --o bind7
bind7 --as--o v13
bind8[/"if(?lat < ?slat,'1^^xsd:integer','0^^xsd:integer')"/]
v12 --o bind8
v5 --o bind8
bind8 --as--o v14
bind9[/"if(?lon > ?elong,'1^^xsd:integer','0^^xsd:integer')"/]
v11 --o bind9
v6 --o bind9
bind9 --as--o v15
bind10[/"if(?lon < ?wlong,'1^^xsd:integer','0^^xsd:integer')"/]
v11 --o bind10
v7 --o bind10
bind10 --as--o v16
bind11[/"if(?ntest = '1^^xsd:integer','1^^xsd:integer',if(?etest = '1^^xsd:integer','1^^xsd:integer',if(?wtest = '1^^xsd:integer','1^^xsd:integer',if(?stest = '1^^xsd:integer','1^^xsd:integer','0^^xsd:integer'))))"/]
v13 --o bind11
v15 --o bind11
v16 --o bind11
v14 --o bind11
bind11 --as--o v17
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c21 --"wikibase:language"--> c23
end