sparql-examples

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

View the Project on GitHub AmsterdamUMC/sparql-examples

ngrc_facilities3

Park number in PC4 of person's regular visiting places

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 ?postcode4 (COUNT(?park) AS ?parkCount)
WHERE {
  VALUES ?postcode4 { "1033" "1095" "1012" }
  OPTIONAL {
      ?park osmkey:leisure "park" ;
            osmkey:addr:postcode ?p_park ;
            geo:hasGeometry/geo:asWKT ?park_geometry.
      BIND(SUBSTR(?p_park, 1, 4) AS ?pc4_park)
      FILTER(?pc4_park = ?postcode4)
  }
}
GROUP BY ?postcode4
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("?pc4_park")
  v4("?postcode4"):::projected 
  a1((" "))
  c2(["park"]):::literal 
  bind0[/VALUES ?postcode4/]
  bind0-->v4
  bind00(["1033"])
  bind00 --> bind0
  bind01(["1095"])
  bind01 --> bind0
  bind02(["1012"])
  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','4^^xsd:integer')"/]
    v5 --o bind1
    bind1 --as--o v7
  end
  bind3[/"count(?park)"/]
  v4 --o bind3
  bind3 --as--o v7