Skip to content

Sample SPARQL queries

Timo edited this page Oct 17, 2022 · 1 revision

This page shows sample queries which can be used with their respective SPARQL endpoints in the plugin:

Sample queries

Wikidata

Airports in Germany

SELECT ?label ?geo ?item WHERE {
  ?item wdt:P31 wd:Q1248784; #Airport
    ?range wd:Q183; #Germany
    wdt:P625 ?geo;
    rdfs:label ?label.
  FILTER((LANG(?label)) = "en")
}

Airports in European countries

SELECT ?label ?geo ?item ?country ?labelC WHERE {
  ?item wdt:P31 wd:Q1248784;
    ?range ?country;
    wdt:P625 ?geo;
    rdfs:label ?label.
  ?country rdfs:label ?labelC.
  FILTER((LANG(?label)) = "en")
  FILTER((LANG(?labelC)) = "en")
  FILTER(?country IN(wd:Q183, wd:Q142, wd:Q145, wd:Q27, wd:Q29, wd:Q38, wd:Q35, wd:Q34, wd:Q20, wd:Q33, wd:Q45, wd:Q189))
}

Hospitals

SELECT ?label ?geo ?item WHERE {
  ?item ((wdt:P31*)/(wdt:P279*)) wd:Q16917; #Hospital
    wdt:P625 ?geo;
    rdfs:label ?label.
  FILTER((LANG(?label)) = "en")
}

Castles as archaeological sites

SELECT ?label ?geo ?item WHERE {
  ?item wdt:P31 wd:Q839954; #archaeologicalSite
    (wdt:P31/(wdt:P279*)) wd:Q23413; #Castle
    wdt:P625 ?geo;
    rdfs:label ?label.
  FILTER((LANG(?label)) = "en")
}

Ogam Stones

SELECT ?label ?geo ?item WHERE {
  ?item wdt:P31 wd:Q2016147; #Ogam Stone
    wdt:P361 wd:Q67978809;
    wdt:P195 ?collection.
  OPTIONAL { ?item wdt:P625 ?geo. }
  OPTIONAL {
    ?item rdfs:label ?label.
    FILTER((LANG(?label)) = "en")
  }
  OPTIONAL {
    ?collection rdfs:label ?collectionLabel.
    FILTER((LANG(?collectionLabel)) = "en")
  }
}

Ordnance Survey (OS)

Roman Antiquity Sites in UK

SELECT ?uri ?label ?easting ?northing
WHERE {
  ?uri
    gaz:featureType gaz:RomanAntiquity;
    rdfs:label ?label;
    spatial:easting ?easting;
    spatial:northing ?northing;
}

Antiquity Sites in UK

SELECT ?uri ?label ?easting ?northing
WHERE {
  ?uri
    gaz:featureType gaz:Antiquity;
    rdfs:label ?label;
    spatial:easting ?easting;
    spatial:northing ?northing;
}

Nomisma.org

All Mints

SELECT ?mint ?label ?lat ?long WHERE {
   ?loc geo:lat ?lat ;
        geo:long ?long .
   ?mint geo:location ?loc ;
         skos:prefLabel ?label ;
         a nmo:Mint
  FILTER langMatches (lang(?label), 'en')
}

Kerameikos.org

All Production Places

SELECT ?pp ?label ?lat ?long WHERE {
   ?loc geo:lat ?lat ;
        geo:long ?long .
   ?pp geo:location ?loc ;
         skos:prefLabel ?label ;
         a kon:ProductionPlace
  FILTER langMatches (lang(?label), 'en')
}

LinkedGeodata.org

Restaurants in Mainz, 500m around of the Mainzer Dom

SELECT ?item ?label ?geo
FROM <http://linkedgeodata.org> {
  ?item
    a lgdo:Restaurant ;
    rdfs:label ?label ;
    geom:geometry [
      ogc:asWKT ?geo
    ] .

  Filter (
    bif:st_intersects (?geo, bif:st_point (8.274167,49.998889),0.5)
  ) .
}

Amenity in Cork, 1km around of the UCC

SELECT ?item ?label ?geo
FROM <http://linkedgeodata.org> {
  ?item
    a lgdo:Amenity ;
    rdfs:label ?label ;
    geom:geometry [
      ogc:asWKT ?geo
    ] .

  Filter (
    bif:st_intersects (?geo, bif:st_point (-8.491873,51.893497),1.0)
  ) .
}

DBPedia

10 Points from DBPedia

SELECT ?lat ?lon ?location WHERE {
  ?location geo:lat ?lat .
  ?location geo:long ?lon .
}
LIMIT 10

Geonames

10 Points from Geonames

SELECT ?lat ?lon ?location WHERE {
  ?location geo:lat ?lat .
  ?location geo:long ?lon .
}
LIMIT 10

Ordnance Survey Ireland (OSi)

10 Points from OSi

SELECT ?item ?label ?geo WHERE {
  ?item a <http://www.opengis.net/ont/geosparql#Feature>.
  ?item rdfs:label ?label.
  FILTER (lang(?label) = 'en')
  ?item ogc:hasGeometry [
    ogc:asWKT ?geo
  ] .
}
LIMIT 10