sparql-examples

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

View the Project on GitHub AmsterdamUMC/sparql-examples

NGRC_002

Number facility type: dwelling(building=residential),leisure(leisure=*), bank(amenity=bank), shop(landuse=shop/commercial), park(leisure=park), private leisure facility, non-residential land use, point of interest Park number in the radius around person's regular visiting places add optional in order to include all values, even if there is no parks, or ?start is no existing.

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:>

SELECT ?zipcode_start
    (COUNT(?park) AS ?parkCount)
WHERE {
    # 确保每个邮编都有行
    VALUES ?zipcode_start {'1033SC' '1095MS' '1012AB'}

    # 可选的起点节点
    OPTIONAL { ?start osmKey:addr:postcode ?zipcode_start ;
                   osmKey:name ?name_start ;
                   geo:hasGeometry ?geom_start .
               ?geom_start geo:asWKT ?wkt_start .

               # 可选的公园节点
               OPTIONAL { ?park osmkey:leisure "park" ;
                                geo:hasGeometry/geo:asWKT ?park_geometry .
                          FILTER(geof:distance(?wkt_start, ?park_geometry) < 500)
              }
             }
      }
GROUP BY ?zipcode_start
ORDER BY ?zipcode_start

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?geom_start")
  v5("?name_start")
  v7("?park"):::projected 
  v8("?parkCount")
  v3("?park_geometry")
  v4("?start")
  v2("?wkt_start")
  v2("?zipcode_start"):::projected 
  a1((" "))
  c7(["park"]):::literal 
  bind0[/VALUES ?zipcode_start/]
  bind0-->v2
  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:addr:postcode.->  v2
    v4 --https://www.openstreetmap.org/wiki/Key:name-->  v5
    v4 --http://www.opengis.net/ont/geosparql#hasGeometry-->  v6
    v6 --http://www.opengis.net/ont/geosparql#asWKT-->  v2
    subgraph optional1["(optional)"]
    style optional1 fill:#bbf,stroke-dasharray: 5 5;
      v7 -.https://www.openstreetmap.org/wiki/Key:leisure.->  c7
      v7 --http://www.opengis.net/ont/geosparql#hasGeometry-->  a1
      a1 --http://www.opengis.net/ont/geosparql#asWKT-->  v3
    end
  end
  bind2[/"count(?park)"/]
  v7 --o bind2
  bind2 --as--o v8