Six years ago, 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 (SLIP).
I have now updated the script, available in my code repository, with an R implementation of the methodology in SLIP's How To Guides (Archive).
The relevant code looks as follows, simplified greatly through the use of the httr2 library - the equivalent of the Requests library used in the Python example in the SLIP knowledge base:
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)
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):
Figure 1: Pupil density in Western Australian high schools
Posted on Wednesday 11 October 2023 at 23:41