query-d85b9b3639bd6376c2fe4ebddf255797

rq turtle/ttl

SPARQL query

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map
SELECT
  ?item
  ?itemLabel
  ?coords
{
   {
  SELECT DISTINCT ?item ?location {
     {
  SELECT DISTINCT ?item {
    {?item wdt:P512/(wdt:P31|wdt:P279)* wd:Q752297}
    UNION
    {
      ?item p:P69 [
        pq:P512/(wdt:P31|wdt:P279)* wd:Q752297;
        wikibase:rank wikibase:NormalRank
      ]
    }
    UNION
    {
      ?item p:P69 [
        pq:P512/(wdt:P31|wdt:P279)* wd:Q752297;
        wikibase:rank wikibase:PreferredRank
      ]
    }
  }
}
    ?item wdt:P19 ?location.
  }
}
  OPTIONAL{ {
  SELECT DISTINCT ?location ?coords {
     {
  SELECT DISTINCT ?location {
    INCLUDE %1.
  }
}
    OPTIONAL{?location wdt:P625 ?P625}.
    OPTIONAL{?location (wdt:P131|wdt:P276)+/wdt:P625 ?P131_or_P276__P625}.
    BIND(COALESCE(IF(BOUND(?P625), ?P625, 1/0),
                  IF(BOUND(?P276_P625), ?P276_P625, 1/0),
                  IF(BOUND(?P131_or_P276__P625), ?P131_or_P276__P625, 1/0))
         AS ?coords)
  }
}}.
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE]"}.
}

Query found at