arcgislayers
arcgislayers copied to clipboard
update feature collection (not hosted) data
Is your feature request related to a problem? Please describe.
To update the content of a feature collection object we can recreate the add-item process but instead of
using the /addItem
end point. This can be used, i think, to overwrite an existing feature service in the future.
Describe the solution you'd like
library(sf)
library(httr2)
set_auth_token(auth_code())
y <- sfdep::guerry |>
st_set_crs(27572)
feature_collection <- as_feature_collection(
list(as_layer(y, "new title", "new title"))
)
spatial_reference <- jsonify::to_json(
validate_crs(sf::st_crs(y))[[1]],
unbox = TRUE
)
# https://[root]/content/users/[userName]/items/[itemID]/update(POST only)
# https://developers.arcgis.com/rest/users-groups-and-items/update-item.htm
item_id <- "0b5153ac7d2c4226a6a4a3f57d88c749" # not hosted id
item_id <- "2e7b276b29e248a0a923e8efa2ab0d30" # hosted
host <- arc_host()
user = Sys.getenv("ARCGIS_USER")
token = Sys.getenv("ARCGIS_TOKEN")
req <- req_url_path_append(
request(host),
"sharing", "content",
"users", user,
"items", item_id,
"update"
)
req_body <- req_body_form(
req, f = "json", token = token,
spatialReference = spatial_reference,
text = jsonify::to_json(feature_collection, unbox = TRUE)
)
resp <- req_perform(req_body)
resp_body_string(resp)
Additional context Add any other context or screenshots about the feature request here.