OSM Example Queries


Note: The predicate

bif:st_intersects
is used to efficiently find points in the vicinity of a given point. The first two arguments must be (point-)geometries whereas the third argument specifies the maximum distance between them in kilometers for which the predicate evaluates to true.


Retrieve all amenities 100 from Leipzig Central Station

Prefix lgdo: <http://linkedgeodata.org/ontology/>
Prefix geom: <http://geovocab.org/geometry#>
Prefix ogc: <http://www.opengis.net/ont/geosparql#>
Prefix owl: <http://www.w3.org/2002/07/owl#>

Select * {
  ?s
    owl:sameAs <http://dbpedia.org/resource/Leipzig_Hauptbahnhof> ;
    geom:geometry [
      ogc:asWKT ?sg
    ] .

  ?x
    a lgdo:Amenity ;
    rdfs:label ?l ;    
    geom:geometry [
      ogc:asWKT ?xg
    ] .


    Filter(bif:st_intersects (?sg, ?xg, 0.1)) .
Limit 10

Click here to run the query


Retrieve all amenities 100m from Connewitz Kreuz

Prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix ogc: <http://www.opengis.net/ont/geosparql#>
Prefix geom: <http://geovocab.org/geometry#>
Prefix lgdo: <http://linkedgeodata.org/ontology/>

Select *
From <http://linkedgeodata.org> {
  ?s
    a lgdo:Amenity ;
    rdfs:label ?l ;    
    geom:geometry [
      ogc:asWKT ?g
    ] .

    Filter(bif:st_intersects (?g, bif:st_point (12.37296651.310228), 0.1)) .
}

Run the query on Virtuoso or Sparqlify


Get all icons associated with the schema.

Prefix lgdo: <http://linkedgeodata.org/ontology/>

Select *
From <http://linkedgeodata.org> {
  ?s lgdo:schemaIcon ?o .
}

Click here to run the query


Bakeries in Leipzig

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX geom: <http://geovocab.org/geometry#>
PREFIX lgdo: <http://linkedgeodata.org/ontology/>
PREFIX bif: <http://www.openlinksw.com/schemas/bif#>

SELECT ?s ?sg WHERE {
  ?s
    a lgdo:Bakery ;
    geom:geometry [ ogc:asWKT ?sg ] .

  ?a
    owl:sameAs <http://dbpedia.org/resource/Leipzig> ;
    geom:geometry [ ogc:asWKT ?ag ] .

  Filter(bif:st_intersects(?sg, ?ag))
}
LIMIT 10

Click here to run the query


Get relations with postal codes and region polygon

PREFIX meta: <http://linkedgeodata.org/meta/>
PREFIX lgdo: <http://linkedgeodata.org/ontology/>
PREFIX geom: <http://geovocab.org/geometry#>
PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
SELECT * {
  ?s
    a meta:Relation ;
    lgdo:postalCode ?pc ;
    geom:geometry [
      ogc:asWKT ?w
    ]
 
}
LIMIT 10

Click here to run the query


Example with a polygon: Bakeries in (roughly) Germany

Prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix ogc: <http://www.opengis.net/ont/geosparql#>
Prefix geom: <http://geovocab.org/geometry#>
Prefix lgdo: <http://linkedgeodata.org/ontology/>

Select *
From <http://linkedgeodata.org> {
  ?s
    a lgdo:Bakery ;
    rdfs:label ?l ;    
    geom:geometry [
      ogc:asWKT ?g
    ] .

    Filter(bif:st_intersects (?g, bif:st_geomFromText("POLYGON((6.11553983198 54.4380166083576.95050076948 47.23098535835713.36651639448 47.62649317085714.99249295698 54.7016884833576.11553983198 54.438016608357))"))) .
Limit 10


Click here to run the query


Find all schools within a 5km radius around a specific location, and for each school find coffeeshops that are closer than 1km.

Prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix ogc: <http://www.opengis.net/ont/geosparql#>
Prefix geom: <http://geovocab.org/geometry#>
Prefix lgdo: <http://linkedgeodata.org/ontology/>

Select ?school ?schoolLabel ?coffeeShop ?coffeeShopLabel
From <http://linkedgeodata.org> {
  ?school
    a lgdo:School ;
    rdfs:label ?schoolLabel ;
    geom:geometry [
      ogc:asWKT ?schoolGeo
    ] .
    
  ?coffeeShop
    a lgdo:CoffeeShop ;
    rdfs:label ?coffeeShopLabel ;
    geom:geometry [
      ogc:asWKT ?coffeeShopGeo
    ] .

  Filter (
    bif:st_intersects (?schoolGeo, bif:st_point (4.89222252.373056), 5) &&
    bif:st_intersects (?coffeeShopGeo, ?schoolGeo, 1)
  ) .
}

Click here to run the query


Find helipads near hospitals

Prefix lgdo:<http://linkedgeodata.org/ontology/>
Prefix geom:<http://geovocab.org/geometry#>
Prefix ogc: <http://www.opengis.net/ont/geosparql#>
SELECT * WHERE {
    ?p a lgdo:Helipad ; geom:geometry/ogc:asWKT ?pgv .
    ?h a lgdo:Hospital; geom:geometry/ogc:asWKT ?hgv . 

    Filter(bif:st_intersects(?pgv, ?hgv, 0.5))
}
LIMIT 10

Click to run the query


 
There are no files on this page. [Display files/form]
Comments [Hide comments/form]

Information

Last Modification: 2016-09-14 13:19:32 by Claus Stadler