Skip to content

Commit

Permalink
Merge pull request #198 from R-ArcGIS/arc-open-meta
Browse files Browse the repository at this point in the history
Closes #163
  • Loading branch information
JosiahParry authored Jul 5, 2024
2 parents 014da35 + 21ddf7a commit 4872619
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 41 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# arcgislayers (development)

- `arc_open()` will now work on any resource that works when `f=json` is set in the query parameters closes [#163](https://github.com/R-ArcGIS/arcgislayers/issues/163)
- Now uses [`{arcpbf}`](https://r.esri.com/arcpbf/index.html) when a layer supports protocol buffers.
- This is an ~3x speed improvement over json processing.
- New `query_layer_attachments()` and `download_attachments()` help you access and download attachments to a layer
Expand Down
76 changes: 35 additions & 41 deletions R/arc-open.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,45 @@
#' @returns
#' Depending on the provided URL returns a `FeatureLayer`, `Table`, `FeatureServer`, `ImageServer`, or `MapServer`. Each of these objects is a named list containing the properties of the service.
#' @examples
#'
#' \dontrun{
#' # FeatureLayer
#' furl <- paste0(
#' "https://services3.arcgis.com/ZvidGQkLaDJxRSJ2/arcgis/rest/services/",
#' "PLACES_LocalData_for_BetterHealth/FeatureServer/0"
#' )
#'
#' arc_open(furl)
#' # FeatureLayer
#' furl <- paste0(
#' "https://services3.arcgis.com/ZvidGQkLaDJxRSJ2/arcgis/rest/services/",
#' "PLACES_LocalData_for_BetterHealth/FeatureServer/0"
#' )
#'
#' # Table
#' furl <- paste0(
#' "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/",
#' "USA_Wetlands/FeatureServer/1"
#' )
#' arc_open(furl)
#'
#' arc_open(furl)
#' # Table
#' furl <- paste0(
#' "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/",
#' "USA_Wetlands/FeatureServer/1"
#' )
#'
#' # ImageServer
#' arc_open(
#' "https://landsat2.arcgis.com/arcgis/rest/services/Landsat/MS/ImageServer"
#' )
#' arc_open(furl)
#'
#' # FeatureServer
#' furl <- paste0(
#' "https://services3.arcgis.com/ZvidGQkLaDJxRSJ2/arcgis/rest/services/",
#' "PLACES_LocalData_for_BetterHealth/FeatureServer"
#' )
#' # ImageServer
#' arc_open(
#' "https://landsat2.arcgis.com/arcgis/rest/services/Landsat/MS/ImageServer"
#' )
#'
#' arc_open(furl)
#' # FeatureServer
#' furl <- paste0(
#' "https://services3.arcgis.com/ZvidGQkLaDJxRSJ2/arcgis/rest/services/",
#' "PLACES_LocalData_for_BetterHealth/FeatureServer"
#' )
#'
#' # MapServer
#' map_url <- paste0(
#' "https://services.arcgisonline.com/ArcGIS/rest/services/",
#' "World_Imagery/MapServer"
#' )
#' arc_open(furl)
#'
#' arc_open(map_url)
#' # MapServer
#' map_url <- paste0(
#' "https://services.arcgisonline.com/ArcGIS/rest/services/",
#' "World_Imagery/MapServer"
#' )
#'
#'}
#' arc_open(map_url)
#' }
arc_open <- function(url, token = arc_token()) {

check_url(url)

# extract layer metadata
Expand All @@ -78,16 +75,13 @@ arc_open <- function(url, token = arc_token()) {
} else if ("layers" %in% names(meta) || grepl("FeatureServer", meta[["url"]])) {
layer_class <- "FeatureServer"
} else {
cli::cli_abort(
"Can't determine layer type from {.arg url}: {.url {url}}"
)
return(meta)
}
}

# construct the appropriate class based on the resultant `layer_class`
res <- switch(
layer_class,
"FeatureLayer" = structure(
res <- switch(layer_class,
"FeatureLayer" = structure(
meta,
class = layer_class,
query = list()
Expand All @@ -98,19 +92,19 @@ arc_open <- function(url, token = arc_token()) {
query = list()
),
"FeatureServer" = structure(
meta, class = layer_class
meta,
class = layer_class
),
"ImageServer" = structure(meta, class = layer_class),
"MapServer" = structure(meta, class = layer_class),
"GroupLayer" = structure(meta, class = layer_class),
cli::cli_abort(
c(
"Service type {.val {layer_class}} is not supported.",
"i"= "Please report this at {.url https://github.com/R-ArcGIS/arcgislayers/issues}"
"i" = "Please report this at {.url https://github.com/R-ArcGIS/arcgislayers/issues}"
)
)
)

res
}

0 comments on commit 4872619

Please sign in to comment.