query-3726831ca74edf3bb04ac097edd093f4

rq turtle/ttl

Buildings that are not a part of a bounding box covering the mainland of a country SELECT ?item ?itemLabel ?coord WITH { SELECT * WHERE { VALUES ?country { wd:Q20 } # check that the bounding box only covers the mainland ?country wdt:P1332 ?nmp ; wdt:P1333 ?smp ; wdt:P1334 ?emp ; wdt:P1335 ?wmp . } } AS %a WITH { SELECT DISTINCT ?item ?coord WHERE { INCLUDE %a ?item wdt:P17 ?country; wdt:P31/wdt:P279* wd:Q811979. ?item wdt:P625 ?coord . hint:Prior hint:rangeSafe true. FILTER(geof:latitude(?coord) > geof:latitude(?nmp) || geof:latitude(?coord) < geof:latitude(?smp) || geof:longitude(?coord) > geof:longitude(?emp) || geof:longitude(?coord) < geof:longitude(?wmp)) } LIMIT 1000 } AS %b WHERE { INCLUDE %b # Try to remove things here to ensure it runs after the named subquery b FILTER NOT EXISTS { ?item wdt:P17 ?country2. FILTER(?country2 != ?country) } MINUS { ?item wdt:P5816 wd:Q19860854. } MINUS { ?item wdt:P576|wdt:P3999 []. } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . } }

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Buildings that are not a part of a bounding box covering the mainland of a country
SELECT ?item ?itemLabel ?coord
WHERE {
   {
  SELECT DISTINCT ?item ?coord
  WHERE {
     {
  SELECT *
  WHERE {
    VALUES ?country { wd:Q20 } # check that the bounding box only covers the mainland
    ?country wdt:P1332 ?nmp ;
      wdt:P1333 ?smp ;
      wdt:P1334 ?emp ;
      wdt:P1335 ?wmp .
  }
}    ?item wdt:P17 ?country;
      wdt:P31/wdt:P279* wd:Q811979.
    ?item wdt:P625 ?coord . 
    FILTER(geof:latitude(?coord) > geof:latitude(?nmp) || geof:latitude(?coord) < geof:latitude(?smp) ||
           geof:longitude(?coord) > geof:longitude(?emp) || geof:longitude(?coord) < geof:longitude(?wmp))
  }
  LIMIT 1000
}  # Try to remove things here to ensure it runs after the named subquery b
  FILTER NOT EXISTS {
    ?item wdt:P17 ?country2. FILTER(?country2 != ?country)
  }
  MINUS { ?item wdt:P5816 wd:Q19860854. }
  MINUS { ?item wdt:P576|wdt:P3999 []. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?coord"):::projected v9("?country") v1("?country2") v7("?emp") v3("?item"):::projected v5("?nmp") v6("?smp") v8("?wmp") a2((" ")) a1((" ")) c11(["wd:Q19860854"]):::iri c8(["wd:Q811979"]):::iri c15(["bd:serviceParam"]):::iri c17(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["not "]] subgraph f0e0["Exists Clause"] e0f0[["?country2 != ?country"]] e0f0 --> e0v1 e0f0 --> e0v2 e0v3 --"wdt:P17"--> e0v1 e0v2("?country"):::projected e0v1("?country2"):::projected e0v3("?item"):::projected end f0--EXISTS--> f0e0 f0 --> v1 f0 --> v9 f0 --> v3 f0 --> c1 f1[["?country2 != ?country"]] f1 --> v1 f1 --> v9 v3 --"wdt:P17"--> v1 f2[["(http://www.opengis.net/def/function/geosparql/latitude(?coord) > http://www.opengis.net/def/function/geosparql/latitude(?nmp) || (http://www.opengis.net/def/function/geosparql/latitude(?coord) < http://www.opengis.net/def/function/geosparql/latitude(?smp) || (http://www.opengis.net/def/function/geosparql/longitude(?coord) > http://www.opengis.net/def/function/geosparql/longitude(?emp) || http://www.opengis.net/def/function/geosparql/longitude(?coord) < http://www.opengis.net/def/function/geosparql/longitude(?wmp))))"]] f2 --> v4 f2 --> v5 f2 --> v6 f2 --> v7 f2 --> v8 bind3[/VALUES ?country/] bind3-->v9 bind30(["wd:Q20"]) bind30 --> bind3 v9 --"wdt:P1332"--> v5 v9 --"wdt:P1333"--> v6 v9 --"wdt:P1334"--> v7 v9 --"wdt:P1335"--> v8 v3 --"wdt:P17"--> v9 v3 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c8 v3 --"wdt:P625"--> v4 subgraph minus4["MINUS"] style minus4 stroke-width:6px,fill:pink,stroke:red; v3 --"wdt:P5816"--> c11 end subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P3999"--> a2 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P576"--> a2 end union0r <== or ==> union0l end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c15 --"wikibase:language"--> c17 end