forked from statistikZH/SDD2018ZHHACK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedDataQuery.R
29 lines (24 loc) · 917 Bytes
/
linkedDataQuery.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(SPARQL) # SPARQL querying package
library(ggplot2)
# Step 1 - Set up preliminaries and define query
# Define the data.gov endpoint
endpoint <- "https://ld.geo.admin.ch/query"
# create query statement
query <- 'PREFIX schema: <http://schema.org/>
PREFIX gn: <http://www.geonames.org/ontology#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX dct: <http://purl.org/dc/terms/>
select ?Municipality ?Name
where {
?Municipality a gn:A.ADM3 .
?Municipality schema:name ?Name .
?Municipality dct:issued ?Date .
?Municipality gn:parentADM1 ?InCanton .
?InCanton schema:name ?CantonName .
?Municipality geo:hasGeometry ?Geometry .
##?Geometry geo:asWKT ?WKT .
FILTER (?Date = \"2018-01-01\"^^xsd:date)
FILTER (?CantonName = \"Zürich\")
}'
# Step 2 - Use SPARQL package to submit query and save results to a data frame
municipalities <- SPARQL(endpoint,query)