I would like to retrieve spatial data from a URL. I am using httr2, and I have some code that works (great!) and some code that does not (less great). I am trying to increase my json query to a "multi" query, but need help with the logic/implementation of the .multi argument.
all_the_ids$objectIds <- c(746, 3733, 2271, 2337, 3385, 3610, 2921, 1741, 1883, 885)
snes_url <- "https://services1.arcgis.com/gtRkYQyUQLMTM1uS/arcgis/rest/services/Australian_Species_of_National_Environmental_Significance_Distributions/FeatureServer/0/query"
full_query_params <- list(
where = glue::glue("OBJECTID = {all_the_ids$objectIds[1]}"),
outFields = "*",
outSR = 4326,
f = "json"
)
dat_req <-request(snes_url)
# Add the query parameters using req_url_query
dat_req <- dat_req |> req_url_query(!!!full_query_params)
# Perform the request and get the response
response <- dat_req %>% req_perform()
response |> resp_body_json() |> str()
I am fairly happy with this result, but would like to send a vector of all_the_ids$objectIds[1:10] to return the data for all the objects at once. I see some examples using .multi here, but cannot for the life of me convert it to work in my code.
The things I have done that that don't work is a fairly long list, but includes:
full_query_params <- list(
where = glue::glue("OBJECTID IN {all_the_ids$objectIds[1:3]}"),
outFields = "*",
outSR = 4326,
f = "json",
.multi = "comma"
)
or
full_query_params <- list(
outFields = "*",
outSR = 4326,
f = "json"
)
dat_req <- dat_req |>
req_url_query(OBJECTID = all_the_ids$objectIds[1:3], .multi="comma") |>
req_url_query(!!!full_query_params)
and various iterations using req_url_path_append etc...
I wonder if anyone can help me?