-# Read the shapefile obtained from WA opendata (SLIP)
-#shape <- readOGR(dsn = "data/", layer = "CurrentActiveSchoolsSemester12017_PublicDET_014")
-shape.df <- st_read(dsn = "data/", layer = "CurrentActiveSchoolsSemester12017_PublicDET_014", stringsAsFactors = FALSE)
+## Obtain the shapefile from WA opendata (SLIP)
+tempdirSHP <- tempdir()
+tempfileSHP <- tempfile()
+req <- request("https://sso.slip.wa.gov.au/as/token.oauth2") |>
+ req_headers("Authorization" = "Basic ZGlyZWN0LWRvd25sb2Fk") |>
+ req_body_form(list("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)))
+
+tokenResponse <- req_perform(req)
+
+slipUrl <- "https://direct-download.slip.wa.gov.au/datadownload/Education/Current_Active_Schools_Sem_1_2022_Public_DET_020_WA_GDA94_Public_Shapefile.zip"
+
+req <- request(slipUrl) |>
+ req_headers( 'Authorization' = paste0('Bearer ',resp_body_json(tokenResponse)$access_token))
+
+responseSlip <- req_perform(req)
+writeBin(resp_body_raw(responseSlip), con = tempfileSHP)
+unzip(tempfileSHP, exdir = tempdirSHP)
+shape.df <- st_read(dsn = tempdirSHP)