query-d3baf0c87979dfac54295199e94fee9c

rq turtle/ttl

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

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" . }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v10("?coord_vn") v10("?country") v1("?country2") v6("?emp_long") v3("?item"):::projected v8("?lat") v9("?long") v4("?nmp_lat") v5("?smp_lat") v7("?wmp_long") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) a6((" ")) a7((" ")) a8((" ")) a9((" ")) a10((" ")) a11((" ")) a12((" ")) a13((" ")) a14((" ")) a15((" ")) a16((" ")) a17((" ")) a18((" ")) c20(["wd:Q19860854"]):::iri c16(["wd:Q41176"]):::iri c3(["wikibase:BestRank"]):::iri c22(["bd:serviceParam"]):::iri c24(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["not "]] subgraph f0e0["Exists Clause"] e0f0[["?country2 != ?country"]] e0f0 --> e0v1 e0f0 --> e0v2 e0v3 --"p:direct/P17"--> e0v1 e0v2("?country"):::projected e0v1("?country2"):::projected e0v3("?item"):::projected end f0--EXISTS--> f0e0 f0 --> v1 f0 --> v10 f0 --> v3 f0 --> c1 f1[["?country2 != ?country"]] f1 --> v1 f1 --> v10 v3 --"p:direct/P17"--> v1 bind2[/VALUES ?country/] bind2-->v10 bind20(["wd:Q145"]) bind20 --> bind2 a1 --"a"--> c3 a2 --"wikibase:geoLatitude"--> v4 a1 --"p:statement/value/P1332"--> a2 v10 --"p:P1332"--> a1 a3 --"a"--> c3 a4 --"wikibase:geoLatitude"--> v5 a3 --"p:statement/value/P1333"--> a4 v10 --"p:P1333"--> a3 a5 --"a"--> c3 a6 --"wikibase:geoLongitude"--> v6 a5 --"p:statement/value/P1334"--> a6 v10 --"p:P1334"--> a5 a7 --"a"--> c3 a8 --"wikibase:geoLongitude"--> v7 a7 --"p:statement/value/P1335"--> a8 v10 --"p:P1335"--> a7 f3[["(?lat > ?nmp_lat || (?lat < ?smp_lat || (?long > ?emp_long || ?long < ?wmp_long)))"]] f3 --> v8 f3 --> v4 f3 --> v5 f3 --> v9 f3 --> v6 f3 --> v7 bind4[/VALUES ?country/] bind4-->v10 bind40(["wd:Q145"]) bind40 --> bind4 a9 --"a"--> c3 a10 --"wikibase:geoLatitude"--> v4 a9 --"p:statement/value/P1332"--> a10 v10 --"p:P1332"--> a9 a11 --"a"--> c3 a12 --"wikibase:geoLatitude"--> v5 a11 --"p:statement/value/P1333"--> a12 v10 --"p:P1333"--> a11 a13 --"a"--> c3 a14 --"wikibase:geoLongitude"--> v6 a13 --"p:statement/value/P1334"--> a14 v10 --"p:P1334"--> a13 a15 --"a"--> c3 a16 --"wikibase:geoLongitude"--> v7 a15 --"p:statement/value/P1335"--> a16 v10 --"p:P1335"--> a15 v3 --"p:direct/P17"--> v10 v3 --"p:direct/P31"--> a17 a17 --"p:direct/P279"--> c16 a18 --"a"--> c3 a18 --"p:statement/value/P625"--> v10 v3 --"p:P625"--> a18 v10 --"wikibase:geoLatitude"--> v8 v10 --"wikibase:geoLongitude"--> v9 subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; v3 --"p:direct/P5816"--> c20 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c22 --"wikibase:language"--> c24 end