Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update feature collection (not hosted) data #99

Open
JosiahParry opened this issue Nov 15, 2023 · 1 comment
Open

update feature collection (not hosted) data #99

JosiahParry opened this issue Nov 15, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@JosiahParry
Copy link
Collaborator

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.

@JosiahParry JosiahParry added the enhancement New feature or request label Nov 15, 2023
@JosiahParry
Copy link
Collaborator Author

To find the publish parameters of a hosted feature service

set_auth_token(auth_code())

item_id <- "2e7b276b29e248a0a923e8efa2ab0d30"

#  https://www.arcgis.com/sharing/rest/content/items/10ba62fe50864339a8a3e0f18ca85506/info
req <- httr2::req_url_path_append(
  httr2::request(arc_host()),
  "sharing", "content",
  "items", item_id, "info",
  "publishParameters.json"
)

req_body <- httr2::req_body_form(
  req, 
  f = "json",
  token = token
)

 <- httr2::req_perform(req_body) |> 
  httr2::resp_body_string() |>
  RcppSimdJson::fparse()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant