query-ec28a8af509028e531376b825294c096

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map
SELECT ?item (SAMPLE(?coords) AS ?coord) ?itemLabel ?out WITH {
  SELECT DISTINCT ?out ?depth WHERE {
    SERVICE <https://query.wikidata.org/bigdata/namespace/categories/sparql> {
      SERVICE mediawiki:categoryTree {
        bd:serviceParam mediawiki:start <https://commons.wikimedia.org/wiki/Category:Villages_in_Saale-Holzland-Kreis> .
        bd:serviceParam mediawiki:direction 'Reverse' .
        bd:serviceParam mediawiki:depth 1 .  # direct subcategories only
      }
    }
  }
} AS %subquery WHERE {
  INCLUDE %subquery .
  FILTER(?depth = 1) .  # remove the host category from results
  OPTIONAL {
    ?out schema:about/wdt:P301? ?item .
    FILTER NOT EXISTS { ?item wdt:P31 wd:Q4167836 }  # remove category items from results set
    OPTIONAL {
      ?item wdt:P625 ?coords .
    }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'de' }
} GROUP BY ?item ?itemLabel ?out # to aggregate sample coordinates in case there are multiple P625 values in items

Query found at