Skip to content

Instantly share code, notes, and snippets.

@p1d1d1
Created October 1, 2018 10:55
Show Gist options
  • Save p1d1d1/8b80ff4abfc1408d75791b7888d27f73 to your computer and use it in GitHub Desktop.
Save p1d1d1/8b80ff4abfc1408d75791b7888d27f73 to your computer and use it in GitHub Desktop.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
SELECT ?Municipality ?Name ?Coords ?CoordsLabel WHERE {
?Municipality a <http://www.geonames.org/ontology#A.ADM3> . #municipality
?Municipality <http://schema.org/name> ?Name .
?Municipality <http://www.geonames.org/ontology#parentADM1> ?InCanton .
?InCanton <http://schema.org/name> ?CantonName .
?Municipality <http://purl.org/dc/terms/issued> ?Date .
?Municipality <https://ld.geo.admin.ch/def/bfsNumber> ?bfsNumber . #connect to the ?bfsNumber found in wikidata.
?Municipality geo:hasGeometry ?Geometry .
?Geometry geo:asWKT ?Coords .
#Filter for Municipalities - Version 2017
FILTER (?Date >= "2017-01-01"^^xsd:date)
#FILTER for Municiaplities in Canton Vaud. Change the name for other Cantons (https://ld.geo.admin.ch/boundaries/canton/).
FILTER (?CantonName = "Vaud")
{
SELECT DISTINCT (xsd:integer(?bfs) AS ?bfsNumber) ?WikidataURI ?CoordsLabel WHERE {
SERVICE <https://query.wikidata.org/bigdata/namespace/wdq/sparql>
{
?WikidataURI wdt:P771 ?bfs . #look for bfs number in WD
?WikidataURI wdt:P31 wd:Q70208 . #municipality of Switzerland
?WikidataURI wdt:P18 ?imgURL .
}
BIND (CONCAT('<img src="', ?imgURL, '">') AS ?CoordsLabel)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment