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:

tempdirSHP <- tempdir() 
tempfileSHP <- tempfile()
# Create the token request 
req <- request("") |>
  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 = " | grep Username | sed -e 's/Username: //'", stdout = TRUE), 
  password = system2("pass", args = " | head -1", stdout = TRUE)) 
# Obtain the token response
tokenResponse <- req_perform(req) 
# Define the SLIP file to download
slipUrl <- ""
# 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):

Pupil density in Western Australian high schools

Figure 1: Pupil density in Western Australian high schools