sparql-examples

A set of SPARQL examples that are used in different AMC resources

View the Project on GitHub AmsterdamUMC/sparql-examples

ngrc_facilities5

Park density in PC6

Use at


PREFIX osmKey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX osmrel: <https://www.openstreetmap.org/relation/>
PREFIX ogc: <http://www.opengis.net/rdf#>
PREFIX osm2rdf: <https://osm2rdf.cs.uni-freiburg.de/rdf#>
SELECT ?postcode6 (COUNT(?park) AS ?parkCount)
WHERE {
  VALUES ?postcode6 { "1033SC" "1095MS" "1012AB" }
  OPTIONAL {
      ?park osmkey:leisure "park" ;
            osmkey:addr:postcode ?p_park ;
            geo:hasGeometry/geo:asWKT ?park_geometry.
      BIND(SUBSTR(?p_park, 1, 6) AS ?pc6_park)
      FILTER(?pc6_park = ?postcode6)
  }
}
GROUP BY ?postcode6
ORDER BY DESC(?parkCount)

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?p_park")
  v4("?park"):::projected 
  v7("?parkCount")
  v6("?park_geometry")
  v7("?pc6_park")
  v4("?postcode6"):::projected 
  a1((" "))
  c2(["park"]):::literal 
  bind0[/VALUES ?postcode6/]
  bind0-->v4
  bind00(["1033SC"])
  bind00 --> bind0
  bind01(["1095MS"])
  bind01 --> bind0
  bind02(["1012AB"])
  bind02 --> bind0
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v4 -.https://www.openstreetmap.org/wiki/Key:leisure.->  c2
    v4 --https://www.openstreetmap.org/wiki/Key:addr:postcode-->  v5
    v4 --http://www.opengis.net/ont/geosparql#hasGeometry-->  a1
    a1 --http://www.opengis.net/ont/geosparql#asWKT-->  v6
    bind1[/"substring(?p_park,'1^^xsd:integer','6^^xsd:integer')"/]
    v5 --o bind1
    bind1 --as--o v7
  end
  bind3[/"count(?park)"/]
  v4 --o bind3
  bind3 --as--o v7