arc_read: Read an ArcGIS FeatureLayer, Table, or ImageServer

View source: R/arc-read.R

arc_readR Documentation

Read an ArcGIS FeatureLayer, Table, or ImageServer

Description

arc_read() combines the functionality of arc_open() with arc_select() or arc_raster() to read an ArcGIS FeatureLayer, Table, or ImageServer to an sf or SpatRaster object. Optionally, set, check, or modify names for the returned data frame or sf object using the col_names and name_repair parameters.

Usage

arc_read(
  url,
  col_names = TRUE,
  col_select = NULL,
  n_max = getOption("arcgislayers.n_max", default = 10000),
  name_repair = "unique",
  crs = NULL,
  ...,
  fields = NULL,
  token = arc_token()
)

Arguments

url

The url of the remote resource. Must be of length one.

col_names

Default TRUE. If TRUE, use the default column names for the feature. If col_names is a character vector with the same length as the number of columns in the layer, the default names are replaced with the new names. If col_names has one fewer name than the default column names, the existing sf column name is retained. If col_names is the string "alias", names are set to match the alias names for the layer, if available.

col_select

Default NULL. A character vector of the field names to be returned. By default, all fields are returned.

n_max

Defaults to 10000 or an option set with ⁠options("arcgislayers.n_max" = <max records>)⁠. Maximum number of records to return.

name_repair

Default "unique". See vctrs::vec_as_names() for details. If name_repair = NULL, names are set directly.

crs

the spatial reference to be returned. If the CRS is different than the CRS for the input FeatureLayer, a transformation will occur server-side. Ignored if x is a Table.

...

Additional arguments passed to arc_select() if URL is a FeatureLayer or Table or arc_raster() if URL is an ImageLayer.

fields

a character vector of the field names that you wish to be returned. By default all fields are returned.

token

your authorization token.

Details

[Experimental]

Value

An sf object, a data.frame, or an object of class SpatRaster.

Examples

## Not run: 
  furl <- "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census#' /MapServer/3"

  # read entire service
  arc_read(furl)

  # apply tolower() to column names
  arc_read(url, name_repair = tolower)

  # use paste0 to prevent CRAN check NOTE
  furl <- paste0(
    "https://sampleserver6.arcgisonline.com/arcgis/rest/services/",
    "EmergencyFacilities/FeatureServer/0"
  )

 # use field aliases as column names
 arc_read(furl, col_names = "alias")

 # read an ImageServer directly
 img_url <- "https://landsat2.arcgis.com/arcgis/rest/services/Landsat/MS/ImageServer"

 arc_read(
   img_url,
   width = 100, height = 100,
   xmin = -71, ymin = 43,
   xmax = -67, ymax = 47.5,
   bbox_crs = 4326
 )


## End(Not run)

arcgislayers documentation built on May 29, 2024, 10:42 a.m.