query-d3baf0c87979dfac54295199e94fee9c
title:Buildings that are not a part of a bounding box covering the mainland of a country SELECT ?item ?itemLabel WITH { SELECT * WHERE { VALUES ?country { wd:Q145 } # check that the bounding box only covers the mainland ?country p:P1332 [ a wikibase:BestRank; psv:P1332 [ wikibase:geoLatitude ?nmp_lat ] ]. ?country p:P1333 [ a wikibase:BestRank; psv:P1333 [ wikibase:geoLatitude ?smp_lat ] ]. ?country p:P1334 [ a wikibase:BestRank; psv:P1334 [ wikibase:geoLongitude ?emp_long ] ]. ?country p:P1335 [ a wikibase:BestRank; psv:P1335 [ wikibase:geoLongitude ?wmp_long ] ]. } } AS %a WITH { SELECT DISTINCT ?item WHERE { INCLUDE %a ?item wdt:P17 ?country; wdt:P31/wdt:P279* wd:Q41176; p:P625 [ a wikibase:BestRank; psv:P625 ?coord_vn ]. ?coord_vn wikibase:geoLatitude ?lat. hint:Prior hint:rangeSafe true. ?coord_vn wikibase:geoLongitude ?long. hint:Prior hint:rangeSafe true. FILTER(?lat > ?nmp_lat || ?lat < ?smp_lat || ?long > ?emp_long || ?long < ?wmp_long) } LIMIT 200 } AS %b WHERE { INCLUDE %a INCLUDE %b # Try to remove things here to ensure it runs after named subquery b FILTER NOT EXISTS { ?item wdt:P17 ?country2. FILTER(?country2 != ?country) } MINUS { ?item wdt:P5816 wd:Q19860854. } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . } }
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:Buildings that are not a part of a bounding box covering the mainland of a country
SELECT ?item ?itemLabel
WHERE {
{
SELECT *
WHERE {
VALUES ?country { wd:Q145 } # check that the bounding box only covers the mainland
?country p:P1332 [ a wikibase:BestRank; psv:P1332 [ wikibase:geoLatitude ?nmp_lat ] ].
?country p:P1333 [ a wikibase:BestRank; psv:P1333 [ wikibase:geoLatitude ?smp_lat ] ].
?country p:P1334 [ a wikibase:BestRank; psv:P1334 [ wikibase:geoLongitude ?emp_long ] ].
?country p:P1335 [ a wikibase:BestRank; psv:P1335 [ wikibase:geoLongitude ?wmp_long ] ].
}
} {
SELECT DISTINCT ?item
WHERE {
{
SELECT *
WHERE {
VALUES ?country { wd:Q145 } # check that the bounding box only covers the mainland
?country p:P1332 [ a wikibase:BestRank; psv:P1332 [ wikibase:geoLatitude ?nmp_lat ] ].
?country p:P1333 [ a wikibase:BestRank; psv:P1333 [ wikibase:geoLatitude ?smp_lat ] ].
?country p:P1334 [ a wikibase:BestRank; psv:P1334 [ wikibase:geoLongitude ?emp_long ] ].
?country p:P1335 [ a wikibase:BestRank; psv:P1335 [ wikibase:geoLongitude ?wmp_long ] ].
}
} ?item wdt:P17 ?country;
wdt:P31/wdt:P279* wd:Q41176;
p:P625 [ a wikibase:BestRank; psv:P625 ?coord_vn ].
?coord_vn wikibase:geoLatitude ?lat.
?coord_vn wikibase:geoLongitude ?long.
FILTER(?lat > ?nmp_lat || ?lat < ?smp_lat || ?long > ?emp_long || ?long < ?wmp_long)
}
LIMIT 200
} # Try to remove things here to ensure it runs after named subquery b
FILTER NOT EXISTS {
?item wdt:P17 ?country2. FILTER(?country2 != ?country)
}
MINUS { ?item wdt:P5816 wd:Q19860854. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}