]> git.vanrenterghem.biz Git - www2.vanrenterghem.biz.git/blobdiff - posts/obtaining_SLIP_data_using_R.org
Gebruik source folder.
[www2.vanrenterghem.biz.git] / posts / obtaining_SLIP_data_using_R.org
diff --git a/posts/obtaining_SLIP_data_using_R.org b/posts/obtaining_SLIP_data_using_R.org
deleted file mode 100644 (file)
index 1d20221..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#+date: 2023-10-11T23:41:54+08:00 
-#+opengraph2: ogimage="https://www.vanrenterghem.biz/blog/pics/SLIP_WA_schools.png"
-#+filetags: R spatial analysis visualisation
-
-Six years ago, [[file:using spatial features and openstreetmap][I wrote about Simple Features (sf) in R]]. I mapped the number of pupils per high
-school in the Perth metro area. At the time, I didn't include how to
-obtain the shapefile, provided as open data by Landgate on behalf of the
-Western Australian government through its Shared Location Information
-Platform ([[https://data.wa.gov.au/slip][SLIP]]).
-
-I have now updated the script,
-[[http://git.vanrenterghem.biz/?p=R/project-wa-schools.git;a=summary][available
-in my code repository]], with an R implementation of
-[[https://toolkit.data.wa.gov.au/hc/en-gb/articles/115000962734][the
-methodology in SLIP's How To Guides]]
-([[https://web.archive.org/web/20230608184007/https://toolkit.data.wa.gov.au/hc/en-gb/articles/115000962734][Archive]]).
-
-The relevant code looks as follows, simplified greatly through the use
-of the [[https://httr2.r-lib.org/][httr2]] library - the equivalent of
-the [[https://docs.python-requests.org/en/latest/][Requests]] library
-used in the Python example in the SLIP knowledge base:
-
-#+BEGIN_SRC R
-library(httr2) 
-tempdirSHP <- tempdir() 
-tempfileSHP <- tempfile()
-# Create the token request 
-req <- request("https://sso.slip.wa.gov.au/as/token.oauth2") |>
-  req_headers("Authorization" = "Basic ZGlyZWN0LWRvd25sb2Fk") |>
-  req_body_form(grant_type = "password", # SLIP username and password stored in 
-                                         # pass - the standard unix password manager
-  username = system2("pass", args = "slip.wa.gov.au | grep Username | sed -e 's/Username: //'", stdout = TRUE), 
-  password = system2("pass", args = "slip.wa.gov.au | head -1", stdout = TRUE)) 
-# Obtain the token response
-tokenResponse <- req_perform(req) 
-# Define the SLIP file to download
-slipUrl <- "https://direct-download.slip.wa.gov.au/datadownload/Education/Current_Active_Schools_Sem_1_2022_Public_DET_020_WA_GDA94_Public_Shapefile.zip"
-# Create the request for the SLIP file using the received token req <-
-request(slipUrl) |> 
-  req_headers( 'Authorization' = paste0('Bearer',resp_body_json(tokenResponse)$access_token)) 
-# Obtain the SLIP file using the created request 
-responseSlip <- req_perform(req)
-#+END_SRC
-
-An updated plot of the high school enrollment numbers looks as follows
-(for clarity, I've only included the names of schools in the top 5% as
-ranked by student numbers):
-
-#+CAPTION: Pupil density in Western Australian high schools
-#+ATTR_HTML: :class img-fluid :alt Pupil density in Western Australian high schools
-[[file:../assets/SLIP_WA_schools.png]]