arcgislayers
arcgislayers copied to clipboard
How to support Hydrology service
We have discussed the hydrology service as a possible supported service. However, it is not clear how this service works or how it can be useful to R users.
To me, it appears that we send data to AGOL for a job. We then wait for the job to complete and poll the job endpoint until it succeeds. When it succeeds what do we expect? Do we want data to come back into R? Do we want something informative? I'm unsure what is happening with the endpoint.
library(httr2)
token <- arcgis::auth_client()$access_token
burl <- "https://hydro.arcgis.com/arcgis/rest/services/Tools/Hydrology/GPServer/Watershed/submitJob"
resp <- request(burl) |>
req_body_form(
InputPoints = '{"geometryType":"esriGeometryPoint","features":[{"geometry":{"x":-11946425.36295705,"y":4930494.072505761,"spatialReference":{"wkid":102100,"latestWkid":3857}}}],"sr":{"wkid":102100,"latestWkid":3857}}',
SnapDistance = 500,
SnapDistanceUnits = "Meters",
Generalize = TRUE,
f = "json",
token = token
) |>
req_perform()
res_id <- resp_body_json(resp)
job_res_url <- glue::glue("https://hydro.arcgis.com/arcgis/rest/services/Tools/Hydrology/GPServer/Watershed/jobs/{res_id$jobId}")
Sys.sleep(5)
job_resp <- request(job_res_url) |>
req_body_form(
f = "json",
token = token
) |>
req_perform()
job_res <- resp_body_json(job_resp)
job_res$results
#> $WatershedArea
#> $WatershedArea$paramUrl
#> [1] "results/WatershedArea"
#>
#>
#> $SnappedPoints
#> $SnappedPoints$paramUrl
#> [1] "results/SnappedPoints"
Created on 2023-04-03 with reprex v2.0.2