### Install arcgis Metapackage Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Install the complete R-ArcGIS Bridge toolkit by installing the arcgis metapackage. This is recommended for most users. ```r install.packages("arcgis") ``` -------------------------------- ### Install Development Version Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Install the development version of the arcgislayers package using the pak package manager. ```r pak::pak("r-arcgis/arcgislayers") ``` -------------------------------- ### Install arcgislayers Individually Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Install the arcgislayers package individually from CRAN if you do not need the full arcgis metapackage. ```r install.packages("arcgislayers") ``` -------------------------------- ### Get All Layers and Tables Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Retrieves all layers and tables from a FeatureServer, MapServer, or ImageServer. The result is returned as a list containing two elements: 'layers' and 'tables'. ```r get_all_layers(x, token = arc_token()) ``` -------------------------------- ### Get Layers by Name from MapServer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layers.md Retrieve multiple layers from a MapServer by specifying their names. This is the preferred method for clarity and maintainability. ```r get_layers(msrv, name = c("Census Block Points", "Census Block Group")) ``` -------------------------------- ### Get Layers from FeatureServer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-all-layers.md Retrieves all layers from a FeatureServer object. The output lists each layer with its name, geometry type, CRS, and capabilities. ```r get_all_layers(fsrv) ``` -------------------------------- ### Get MapServer Layer by Name Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layer.md Retrieve a layer from a MapServer object by its name. This approach is convenient for selecting layers based on their recognizable names. ```R get_layer(msrv, name = "Citations") ``` -------------------------------- ### Get Layers by ID from MapServer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layers.md Retrieve multiple layers from a MapServer using their numeric IDs. Note that MapServer layer IDs typically start from 1. ```r get_layers(msrv, 1:2) ``` -------------------------------- ### Get Multiple Layers from Server Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Extracts multiple layers or tables from a server endpoint. Specify layers by a vector of IDs or names. Returns a named list of the requested layers. ```r get_layers(x, id = NULL, name = NULL, token = arc_token()) ``` -------------------------------- ### Get Layers by Name from FeatureServer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layers.md Retrieve multiple layers from a FeatureServer by specifying their names as a character vector. This method is more readable and robust against changes in layer order. ```r get_layers(fsrv, name = c("Tracts", "ZCTAs")) ``` -------------------------------- ### Get Layers by Name from GroupLayer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layers.md Retrieve layers from a GroupLayer by their names. This approach is recommended for accessing specific layers within a group. ```r get_layers(glyr, name = c("Bus Stops", "Bus Routes")) ``` -------------------------------- ### Get FeatureServer Layer by Name Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layer.md Retrieve a layer from a FeatureServer object using its name. This method is helpful when the layer's name is known and more descriptive than its ID. ```R get_layer(fsrv, name = "states_hex") ``` -------------------------------- ### Get FeatureServer Layer by ID Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layer.md Retrieve a layer from a FeatureServer object using its numerical ID. This is useful when the layer's ID is known. ```R get_layer(fsrv, 0) ``` -------------------------------- ### Get MapServer Layer by ID Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layer.md Access a layer from a MapServer object by its ID. This is a direct way to select a specific layer when its ID is available. ```R get_layer(msrv, 3) ``` -------------------------------- ### Get Layers from MapLayer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-all-layers.md Retrieves all layers from a MapLayer object. The output details each layer's name, geometry type, CRS, and capabilities. ```r get_all_layers(msrv) ``` -------------------------------- ### Get Layers by ID from FeatureServer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layers.md Retrieve multiple layers from a FeatureServer using their numeric IDs. This is useful when you know the exact position of the layers within the service. ```r get_layers(fsrv, 0:1) ``` -------------------------------- ### Get Layers from GroupLayer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-all-layers.md Retrieves all layers from a GroupLayer object. The output is a list where each element represents a layer with its name, geometry type, CRS, and capabilities. ```r get_all_layers(glyr) ``` -------------------------------- ### Query Specific Columns and Rows Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Select specific fields and filter rows based on a condition using arc_select(). This example retrieves large counties based on population. ```r # Get specific columns and rows large_counties <- arc_select( county_fl, fields = c("state_abbr", "population"), where = "population > 1000000" ) large_counties #> Simple feature collection with 49 features and 2 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -158.2674 ymin: 21.24986 xmax: -71.02671 ymax: 47.77552 #> Geodetic CRS: WGS 84 #> First 10 features: #> STATE_ABBR POPULATION geometry #> 1 OH 1264817 POLYGON ((-81.37707 41.3463... #> 2 OH 1323807 POLYGON ((-83.24282 39.8044... #> 3 PA 1250578 POLYGON ((-79.86399 40.2007... #> 4 PA 1603797 POLYGON ((-75.1429 39.8816,... #> 5 HI 1016508 POLYGON ((-157.6733 21.2980... #> 6 IL 5275541 POLYGON ((-88.26711 41.9887... #> 7 AZ 4420568 POLYGON ((-111.0425 33.4759... #> 8 AZ 1043433 POLYGON ((-110.4522 31.7360... #> 9 CA 1682353 POLYGON ((-121.4721 37.4777... #> 10 CA 1165927 POLYGON ((-122.3076 37.8917... ``` -------------------------------- ### Get Single Layer from Server Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Extracts a specific FeatureLayer or Table from a FeatureServer, MapServer, or GroupLayer. You can specify the layer by its numeric ID or character name. ```r get_layer(x, id = NULL, name = NULL, token = arc_token()) ``` -------------------------------- ### Get GroupLayer Layer by ID Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layer.md Fetch a layer from a GroupLayer object using its numerical ID. This is suitable for accessing layers within a group when the ID is known. ```R get_layer(glyr, 2) ``` -------------------------------- ### Get GroupLayer Layer by Name Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layer.md Retrieve a layer from a GroupLayer object by its name. This method provides an intuitive way to select layers within a group using their names. ```R get_layer(glyr, name = "Bus Stops") ``` -------------------------------- ### Core Workflow: Open, Select, Calculate, Publish Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Demonstrates a typical workflow: opening a feature layer, selecting features based on a condition, calculating a new field, and publishing the result as a new layer. Ensure necessary libraries are loaded. ```r library(arcgis) fl <- arc_open("https://.../FeatureServer/0") res <- arc_select(fl, fields = c("name", "pop"), where = "pop > 1000000") res$density <- res$pop / as.numeric(sf::st_area(res)) publish_layer(res, title = "My Analysis") ``` -------------------------------- ### Navigate FeatureServer Layers Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Open a FeatureServer, retrieve all its layers, and then select a specific layer by name. This is the initial step for interacting with a FeatureServer. ```r fs <- arc_open("https://.../FeatureServer") layers <- get_all_layers(fs) fl <- get_layer(fs, name = "Parcels") ``` -------------------------------- ### Open and Inspect a Map Server Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/map-services.md Opens a map server and displays its layers, CRS, and capabilities. Useful for understanding the structure of a map service. ```r nhd_srv <- "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer" nhd_srv ``` -------------------------------- ### xss_defaults Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Returns a list containing the default settings for Cross-Site Scripting (XSS) prevention, which are used by the `create_feature_server()` function. ```APIDOC ## xss_defaults ### Description Returns the default XSS prevention settings list used by `create_feature_server()`. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters None ### Response - Returns a list of default XSS prevention settings. ``` -------------------------------- ### Load arcgis Package Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Load the arcgis package to begin using its functionalities. This also attaches core arcgis packages like arcgislayers. ```r library(arcgis) #> Attaching core arcgis packages: #> → arcgisutils v0.4.0.9001 #> → arcgislayers v0.5.2 #> → arcgisgeocode v0.3.0.9000 #> → arcgisplaces v0.1.2 #> → arcpbf v0.1.7.9000 ``` -------------------------------- ### create_feature_server Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Creates an empty hosted `FeatureServer` on ArcGIS Online or Enterprise. This function allows configuration of service name, description, CRS, capabilities, query formats, and other properties. Returns the metadata of the created FeatureServer. ```APIDOC ## create_feature_server ### Description Creates an empty hosted `FeatureServer` on ArcGIS Online or Enterprise. Returns the metadata of the created FeatureServer. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **service_name** (string) - The name for the new FeatureServer. - **description** (string, optional) - A description for the FeatureServer. Defaults to "". - **crs** (integer, optional) - The Coordinate Reference System for the FeatureServer. Defaults to 3857. - **capabilities** (vector of strings, optional) - The capabilities of the FeatureServer. Defaults to `c("create", "delete", "query", "update", "editing")`. - **query_formats** (vector of strings, optional) - The supported query formats. Defaults to `c("json", "geojson")`. - **initial_extent** (list, optional) - The initial extent of the FeatureServer. - **max_record_count** (integer, optional) - The maximum number of records allowed. Defaults to 1000. - **allow_updates** (boolean, optional) - Whether updates are allowed. Defaults to TRUE. - **copyright** (string, optional) - Copyright information. Defaults to "". - **has_static_data** (boolean, optional) - Whether the service has static data. Defaults to FALSE. - **xss_prevention** (list, optional) - XSS prevention settings. Defaults to `xss_defaults()`. - **token** (authentication token, optional) - The authentication token to use for the request. ### Response - Returns the metadata of the created FeatureServer. ``` -------------------------------- ### get_all_layers Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Returns all layers and tables from a FeatureServer, MapServer, or ImageServer as a list with elements 'layers' and 'tables'. ```APIDOC ## get_all_layers(x, token = arc_token()) ### Description Returns all layers and tables from a `FeatureServer`, `MapServer`, or `ImageServer` as a list with elements `"layers"` and `"tables"`. ### Parameters #### Path Parameters - **x** (FeatureServer, MapServer, or ImageServer) - Required - The server object. #### Query Parameters - **token** (function) - Optional - An authentication token. ``` -------------------------------- ### Add and Update Features Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Add new features using 'add_features' and update existing ones with 'update_features'. Ensure that features passed to 'update_features' contain an 'ObjectID'. ```r add_features(fl, new_sf) update_features(fl, modified_sf) # must contain ObjectID ``` -------------------------------- ### download_attachments Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Downloads attachments, previously queried using `query_layer_attachments`, to a specified local directory. It can optionally overwrite existing files. Returns a list of file paths or error conditions. ```APIDOC ## download_attachments ### Description Downloads attachments returned by `query_layer_attachments()` to a local directory. Returns a list of file paths or error conditions. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **attachments** (data.frame) - The output from `query_layer_attachments()`. - **out_dir** (string) - The directory where attachments will be downloaded. - **overwrite** (boolean, optional) - Whether to overwrite existing files. Defaults to FALSE. - **.progress** (boolean, optional) - Whether to show a progress indicator. Defaults to TRUE. - **token** (authentication token, optional) - The authentication token to use for the request. - **...** (additional arguments) ### Response - Returns a list of file paths or error conditions. ``` -------------------------------- ### Connect to ArcGIS Feature Service Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Use arc_open() to establish a connection to an ArcGIS feature service using its URL. This does not download data. ```r # Connect to a feature service furl <- "https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Counties_Generalized_Boundaries/FeatureServer/0" county_fl <- arc_open(furl) county_fl #> #> Name: USA Counties - Generalized #> Geometry Type: esriGeometryPolygon #> CRS: 4326 #> Capabilities: Query,Extract ``` -------------------------------- ### Read ArcGIS Data with Convenience Wrapper Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt A convenience function that combines `arc_open()` and `arc_select()` (or `arc_raster()`) into a single call. It respects global options for maximum records and allows control over field alias handling. ```r arc_read(url, col_names = TRUE, col_select = NULL, n_max = Inf, name_repair = "unique", crs = NULL, ..., fields = NULL, alias = "drop", token = arc_token()) ``` -------------------------------- ### Fetch a Table from FeatureServer Source: https://github.com/r-arcgis/arcgislayers/blob/main/tests/testthat/_snaps/get-layers.md Retrieve a Table object from a FeatureServer by specifying its ID. This demonstrates that `get_layers` can also fetch non-spatial tables. ```r get_layers(fsrv, 1) ``` -------------------------------- ### sf::st_crs() / sf::st_crs() Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt S3 methods registered to allow the `sf::st_crs()` function to directly work on `FeatureLayer` and `ImageServer` objects, retrieving their Coordinate Reference System information. ```APIDOC ## sf::st_crs() / sf::st_crs() ### Description S3 methods are registered so `sf::st_crs()` works directly on `FeatureLayer` and `ImageServer` objects. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (`FeatureLayer` or `ImageServer` object) - The layer object to get the CRS from. ### Response - Returns the Coordinate Reference System (CRS) of the layer. ``` -------------------------------- ### publish_item Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Publishes an existing portal item as a hosted feature service. This function takes the item ID of a previously added portal item and publishes it. Returns a list containing the encoded service URL. ```APIDOC ## publish_item ### Description Publishes an existing portal item as a hosted feature service. Returns a list with the encoded service URL. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **item_id** (string) - The ID of the portal item to publish. - **publish_params** (list, optional) - Parameters for publishing. Defaults to `.publish_params()`. - **file_type** (string, optional) - The type of file the item represents. Defaults to "featureCollection". - **token** (authentication token, optional) - The authentication token to use for the request. ### Response - Returns a list with the encoded service URL. ``` -------------------------------- ### Query Feature Layer and Return sf Object Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Queries a FeatureLayer, Table, or ImageServer and returns data as an sf object or data.frame. Handles pagination automatically. Use `fields` for column selection and `where` for SQL filtering. Spatial filtering is possible with `filter_geom`. ```r arc_select(x, ..., fields = NULL, where = NULL, crs = sf::st_crs(x), geometry = TRUE, filter_geom = NULL, predicate = "intersects", n_max = Inf, page_size = NULL, token = arc_token()) ``` -------------------------------- ### arc_select Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Queries a FeatureLayer, Table, or ImageServer and returns an sf object or data.frame. It handles pagination automatically and supports field selection, SQL filtering, and spatial filtering. ```APIDOC ## arc_select(x, ..., fields = NULL, where = NULL, crs = sf::st_crs(x), geometry = TRUE, filter_geom = NULL, predicate = "intersects", n_max = Inf, page_size = NULL, token = arc_token()) ### Description Queries a `FeatureLayer`, `Table`, or `ImageServer` and returns an `sf` object or `data.frame`. Handles pagination automatically. Use `fields` for column selection, `where` for SQL filtering, `filter_geom` (an `sfc`, `sfg`, or `bbox`) for spatial filtering, and `page_size` to reduce features per request when timeouts occur. ### Parameters #### Path Parameters - **x** (FeatureLayer, Table, or ImageServer) - Required - The layer or server to query. #### Query Parameters - **fields** (character vector) - Optional - Columns to select. - **where** (string) - Optional - SQL-like query string for filtering features. - **crs** (CRS object) - Optional - Coordinate reference system for the output. - **geometry** (boolean) - Optional - Whether to include geometry in the output. Defaults to TRUE. - **filter_geom** (sfc, sfg, or bbox) - Optional - Spatial filter geometry. - **predicate** (string) - Optional - Spatial predicate for filtering (e.g., "intersects"). Defaults to "intersects". - **n_max** (numeric) - Optional - Maximum number of features to return. Defaults to Inf. - **page_size** (numeric) - Optional - Number of features per request page. - **token** (function) - Optional - An authentication token. ``` -------------------------------- ### Query All Data from Feature Layer Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Retrieve all data from an opened feature layer using arc_select(). Use with caution on large datasets. ```r # Get all data (use with caution on large datasets!) counties_all <- arc_select(county_fl) ``` -------------------------------- ### Paginated Query for Large Layers Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Retrieve data from large layers by specifying 'page_size' to manage the number of records fetched per request. This helps prevent timeouts and memory issues. ```r result <- arc_select(fl, page_size = 100) ``` -------------------------------- ### list_raster_fns Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Lists the available server-side raster functions for an `ImageServer`. This is useful for understanding the analytical capabilities of an image service. Returns a data.frame containing the names and descriptions of the raster functions. ```APIDOC ## list_raster_fns ### Description Lists available server-side raster functions for an `ImageServer`. Returns a `data.frame` with function names and descriptions. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (`ImageServer` object) - The ImageServer to query for raster functions. ### Response - Returns a `data.frame` with function names and descriptions. ``` -------------------------------- ### Export ImageServer Region as SpatRaster Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Exports a specified region of an ImageServer as a `terra::SpatRaster` object. Requires bounding box coordinates and optionally accepts server-side raster functions. ```r arc_raster(x, xmin, xmax, ymin, ymax, bbox_crs = NULL, crs = sf::st_crs(x), width = NULL, height = NULL, format = "tiff", ..., raster_fn = NULL, token = arc_token()) ``` -------------------------------- ### get_layers Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Extracts multiple layers or tables from a FeatureServer, MapServer, or GroupLayer by a vector of IDs or names. Returns a named list. ```APIDOC ## get_layers(x, id = NULL, name = NULL, token = arc_token()) ### Description Extracts multiple layers by a vector of `id` or `name` values. Returns a named list. ### Parameters #### Path Parameters - **x** (FeatureServer, MapServer, or GroupLayer) - Required - The server or group layer object. #### Query Parameters - **id** (numeric vector) - Optional - Numeric IDs of the layers or tables. - **name** (character vector) - Optional - Character names of the layers or tables. - **token** (function) - Optional - An authentication token. ``` -------------------------------- ### Read Layer with Field Aliases Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Use 'alias = "replace"' to rename fields during data retrieval. Ensure the alias value is a valid string. ```r fl <- arc_open(url) data <- arc_read(url, alias = "replace") ``` -------------------------------- ### arc_open Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Opens a connection to any ArcGIS service or portal item. It accepts a REST endpoint URL or a portal item ID and returns the appropriate class object without downloading data. ```APIDOC ## arc_open(url, host = arc_host(), token = arc_token()) ### Description Opens a connection to any ArcGIS service or portal item. `url` can be a REST endpoint URL or a portal item ID. Returns the appropriate class object (`FeatureLayer`, `Table`, `FeatureServer`, `MapServer`, `ImageServer`, `PortalItem`, etc.) without downloading data. ### Parameters #### Path Parameters - **url** (string) - Required - The REST endpoint URL or a portal item ID. - **host** (function) - Optional - The ArcGIS host to connect to. - **token** (function) - Optional - An authentication token. ``` -------------------------------- ### list_fields Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Returns a data.frame of field metadata (name, alias, type, etc.) for a FeatureLayer, Table, or ImageServer. ```APIDOC ## list_fields(x) ### Description Returns a `data.frame` of field metadata (name, alias, type, etc.) for a `FeatureLayer`, `Table`, or `ImageServer`. ### Parameters #### Path Parameters - **x** (FeatureLayer, Table, or ImageServer) - Required - The layer or server object. ``` -------------------------------- ### Encode Field Values using Coded Domains Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Replaces or labels column values based on coded value domains defined in the layer. Options include replacing codes with descriptions, replacing only valid codes, or applying labels compatible with the `haven` package. ```r encode_field_values(.data, .layer, field = NULL, codes = c("replace", "replace-valid", "label"), call) ``` -------------------------------- ### add_attachments Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Uploads files as attachments to features in a FeatureLayer. It takes a FeatureLayer object, feature IDs, and the path to the file to be uploaded. Optional parameters include file name, progress tracking, and authentication token. ```APIDOC ## add_attachments ### Description Uploads files as attachments to features in a `FeatureLayer`. `feature_id` is a vector of object IDs (recycled to match `path`). Returns a `data.frame` of attachment metadata. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (`FeatureLayer` object) - The FeatureLayer to which attachments will be added. - **feature_id** (vector of IDs) - The object IDs of the features to which attachments will be added. - **path** (string) - The file path of the attachment to upload. - **file_name** (string, optional) - The name of the attachment file. Defaults to the basename of the `path`. - **.progress** (boolean, optional) - Whether to show a progress indicator. Defaults to TRUE. - **token** (authentication token, optional) - The authentication token to use for the request. ### Response - Returns a `data.frame` of attachment metadata. ``` -------------------------------- ### add_features Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Adds features from an sf object or data.frame to a FeatureLayer. Returns a data.frame with information about the added features. ```APIDOC ## add_features(x, .data, chunk_size = 500, match_on = c("name", "alias"), rollback_on_failure = TRUE, progress = TRUE, token = arc_token()) ### Description Adds features from an `sf` object or `data.frame` to a `FeatureLayer`. Returns a `data.frame` with `objectId`, `uniqueId`, `globalId`, and `success` columns. ### Parameters #### Path Parameters - **x** (FeatureLayer) - Required - The FeatureLayer to add features to. - **.data** (sf object or data.frame) - Required - The features to add. #### Query Parameters - **chunk_size** (numeric) - Optional - Number of features to add per chunk. Defaults to 500. - **match_on** (character vector) - Optional - How to match fields between `.data` and the layer. Defaults to c("name", "alias"). - **rollback_on_failure** (boolean) - Optional - Whether to rollback on failure. Defaults to TRUE. - **progress** (boolean) - Optional - Whether to show progress. Defaults to TRUE. - **token** (function) - Optional - An authentication token. ``` -------------------------------- ### arc_read Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt A convenience wrapper that combines arc_open() and arc_select() (or arc_raster() for ImageServers) into a single call for reading data. ```APIDOC ## arc_read(url, col_names = TRUE, col_select = NULL, n_max = Inf, name_repair = "unique", crs = NULL, ..., fields = NULL, alias = "drop", token = arc_token()) ### Description Convenience wrapper combining `arc_open()` and `arc_select()` (or `arc_raster()` for ImageServers) in a single call. `alias` controls field alias handling: `"drop"` (default), `"label"` (adds label attribute), or `"replace"` (renames columns). Respects `options("arcgislayers.n_max")`. ### Parameters #### Path Parameters - **url** (string) - Required - The REST endpoint URL or a portal item ID. #### Query Parameters - **col_names** (boolean) - Optional - Whether to use column names. Defaults to TRUE. - **col_select** (character vector) - Optional - Columns to select. - **n_max** (numeric) - Optional - Maximum number of features to return. Defaults to Inf. - **name_repair** (string) - Optional - Method for repairing duplicate column names. Defaults to "unique". - **crs** (CRS object) - Optional - Coordinate reference system for the output. - **fields** (character vector) - Optional - Columns to select (alternative to col_select). - **alias** (string) - Optional - Field alias handling: "drop", "label", or "replace". Defaults to "drop". - **token** (function) - Optional - An authentication token. ``` -------------------------------- ### Exploring Available Attributes with list_fields Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Use list_fields() to view the names, types, and other metadata of attributes available in a feature layer. This helps in understanding the data structure before querying. ```r list_fields(county_fl) #> # A data frame: 12 × 10 #> name type alias sqlType nullable editable domain defaultValue length #> * #> 1 OBJECTID esri… OBJE… sqlTyp… FALSE FALSE NA NA NA #> 2 NAME esri… Name sqlTyp… TRUE TRUE NA NA 50 #> 3 STATE_NAME esri… Stat… sqlTyp… TRUE TRUE NA NA 20 #> 4 STATE_FIPS esri… Stat… sqlTyp… TRUE TRUE NA NA 2 #> 5 FIPS esri… FIPS sqlTyp… TRUE TRUE NA NA 5 #> 6 SQMI esri… Area… sqlTyp… TRUE TRUE NA NA NA #> 7 POPULATION esri… 2020… sqlTyp… TRUE TRUE NA NA NA #> 8 POP_SQMI esri… Peop… sqlTyp… TRUE TRUE NA NA NA #> 9 STATE_ABBR esri… Stat… sqlTyp… TRUE TRUE NA NA 2 #> 10 COUNTY_FIPS esri… Coun… sqlTyp… TRUE TRUE NA NA 3 #> 11 Shape__Area esri… Shap… sqlTyp… TRUE FALSE NA NA NA #> 12 Shape__Leng… esri… Shap… sqlTyp… TRUE FALSE NA NA NA #> # ℹ 1 more variable: description ``` -------------------------------- ### Download Survey123 Attachments Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Query and download attachments associated with features, often used with Survey123 data. Specify an output directory using 'out_dir'. ```r att <- query_layer_attachments(fl) download_attachments(att, out_dir = tempdir()) ``` -------------------------------- ### Connect to ArcGIS Service Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Opens a connection to an ArcGIS service or portal item using its URL or ID. No data is downloaded; it returns an object representing the service. Supports various service types like FeatureServer, MapServer, etc. ```r arc_open(url, host = arc_host(), token = arc_token()) ``` -------------------------------- ### Spatial Filtering with arc_select Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Filter spatial data by a bounding box before loading into R. Requires the sf package for spatial operations. ```r # Spatial filter: get counties that intersect with North Carolina nc <- sf::st_read(system.file("shape/nc.shp", package="sf")) #> Reading layer `nc' from data source #> `/Users/josiahparry/Library/R/arm64/4.5/library/sf/shape/nc.shp' #> using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 nc_area_counties <- arc_select( county_fl, filter_geom = sf::st_bbox(nc[1,]) ) nc_area_counties #> Simple feature collection with 6 features and 12 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -82.0477 ymin: 35.98946 xmax: -80.83795 ymax: 36.80746 #> Geodetic CRS: WGS 84 #> OBJECTID NAME STATE_NAME STATE_FIPS FIPS SQMI POPULATION #> 1 467 Johnson County Tennessee 47 47091 302.6644 17948 #> 2 1924 Alleghany County North Carolina 37 37005 236.1822 10888 #> 3 1926 Ashe County North Carolina 37 37009 429.3538 26577 #> 4 2016 Watauga County North Carolina 37 37189 313.3604 54086 #> 5 2018 Wilkes County North Carolina 37 37193 756.5252 65969 #> 6 2995 Grayson County Virginia 51 51077 445.7267 15333 #> POP_SQMI STATE_ABBR COUNTY_FIPS Shape__Area Shape__Length #> 1 59.3 TN 091 0.07960385 1.290607 #> 2 46.1 NC 005 0.06140165 1.231232 #> 3 61.9 NC 009 0.11428581 1.442112 #> 4 172.6 NC 189 0.08142272 1.287674 #> 5 87.2 NC 193 0.19911944 1.984232 #> 6 34.4 VA 077 0.11578917 1.945424 #> geometry #> 1 POLYGON ((-81.74091 36.3919... #> 2 POLYGON ((-81.2397 36.36549... #> 3 POLYGON ((-81.47258 36.2344... #> 4 POLYGON ((-81.80605 36.1046... #> 5 POLYGON ((-81.02037 36.0350... #> 6 POLYGON ((-81.34512 36.5729... ``` -------------------------------- ### add_item Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Adds an `sf` or `data.frame` object as a `FeatureCollection` portal item. This is a step towards publishing a hosted feature service. Returns a data.frame containing metadata of the newly created item, including its ID. ```APIDOC ## add_item ### Description Adds an `sf` or `data.frame` as a `FeatureCollection` portal item. Returns a `data.frame` with item metadata including the item ID. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (`sf` or `data.frame` object) - The spatial data to add as a portal item. - **title** (string) - The title of the portal item. - **description** (string, optional) - A description for the portal item. Defaults to "". - **tags** (vector of strings, optional) - Tags for the portal item. Defaults to `character(0)`. - **snippet** (string, optional) - A short summary or snippet for the portal item. Defaults to "". - **categories** (vector of strings, optional) - Categories for the portal item. Defaults to `character(0)`. - **async** (boolean, optional) - Whether to perform the operation asynchronously. Defaults to FALSE. - **type** (string, optional) - The type of portal item to create. Defaults to "Feature Service". - **token** (authentication token, optional) - The authentication token to use for the request. ### Response - Returns a `data.frame` with item metadata including the item ID. ``` -------------------------------- ### List Fields Metadata Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Retrieves a data.frame containing metadata for all fields in a FeatureLayer, Table, or ImageServer. Useful for understanding the available data attributes. ```r list_fields(x) ``` -------------------------------- ### get_layer_estimates Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Returns estimation information for a layer, such as the feature count and extent. This provides insights into the data size and spatial coverage of the layer without retrieving all features. Requires an authentication token. ```APIDOC ## get_layer_estimates ### Description Returns estimation information for a layer (e.g., feature count, extent) as a named list. Requires an authentication token. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (layer object) - The layer for which to get estimates. - **token** (authentication token, optional) - The authentication token to use for the request. ### Response - Returns a named list with estimation information. ``` -------------------------------- ### get_layer Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Extracts a single FeatureLayer or Table from a FeatureServer, MapServer, or GroupLayer by its numeric ID or character name. ```APIDOC ## get_layer(x, id = NULL, name = NULL, token = arc_token()) ### Description Extracts a single `FeatureLayer` or `Table` from a `FeatureServer`, `MapServer`, or `GroupLayer` by numeric `id` or character `name`. ### Parameters #### Path Parameters - **x** (FeatureServer, MapServer, or GroupLayer) - Required - The server or group layer object. #### Query Parameters - **id** (numeric) - Optional - The numeric ID of the layer or table. - **name** (string) - Optional - The character name of the layer or table. - **token** (function) - Optional - An authentication token. ``` -------------------------------- ### encode_field_values Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Replaces or labels column values using coded value domains from the layer definition. Supports replacing codes with descriptions or applying value labels. ```APIDOC ## encode_field_values(.data, .layer, field = NULL, codes = c("replace", "replace-valid", "label"), call) ### Description Replaces or labels column values using coded value domains from the layer definition. `"replace"` substitutes codes with descriptions (non-coded values become `NA`); `"replace-valid"` keeps non-coded values in place; `"label"` applies value labels compatible with the `haven` package. ### Parameters #### Path Parameters - **.data** (data.frame) - Required - The data frame containing values to encode. - **.layer** (FeatureLayer or Table) - Required - The layer object containing coded value domain definitions. #### Query Parameters - **field** (string) - Optional - The field to encode values for. If NULL, applies to all fields with coded value domains. - **codes** (character vector) - Optional - Encoding method: "replace", "replace-valid", or "label". Defaults to c("replace", "replace-valid", "label"). - **call** (call) - Internal use. ``` -------------------------------- ### prepare_spatial_filter Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Converts geometry objects (sfc, sfg, or bbox) into the named list of Esri JSON parameters required for spatial filtering in ArcGIS queries. Supports various spatial predicates like 'intersects', 'contains', and 'within'. ```APIDOC ## prepare_spatial_filter ### Description Converts an `sfc`, `sfg`, or `bbox` object into the named list of Esri JSON parameters needed for spatial filtering. Valid predicates: `"intersects"`, `"contains"`, `"crosses"`, `"overlaps"`, `"touches"`, `"within"`. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **filter_geom** (geometry object) - The geometry to use for spatial filtering. - **crs** (CRS object) - The Coordinate Reference System of the geometry. - **predicate** (string) - The spatial relationship predicate. - **error_call** (call object) - The call object for error reporting. ### Response - Returns a named list of Esri JSON parameters for spatial filtering. ``` -------------------------------- ### arc_raster Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Exports a region of an ImageServer as a terra::SpatRaster. Requires bounding box coordinates and supports server-side raster function application. ```APIDOC ## arc_raster(x, xmin, xmax, ymin, ymax, bbox_crs = NULL, crs = sf::st_crs(x), width = NULL, height = NULL, format = "tiff", ..., raster_fn = NULL, token = arc_token()) ### Description Exports a region of an `ImageServer` as a `terra::SpatRaster`. Bounding box coordinates are required. `raster_fn` applies a named server-side raster function. ### Parameters #### Path Parameters - **x** (ImageServer) - Required - The ImageServer object. - **xmin** (numeric) - Required - Minimum x-coordinate of the bounding box. - **xmax** (numeric) - Required - Maximum x-coordinate of the bounding box. - **ymin** (numeric) - Required - Minimum y-coordinate of the bounding box. - **ymax** (numeric) - Required - Maximum y-coordinate of the bounding box. #### Query Parameters - **bbox_crs** (CRS object) - Optional - Coordinate reference system of the bounding box coordinates. - **crs** (CRS object) - Optional - Coordinate reference system for the output raster. Defaults to the CRS of `x`. - **width** (numeric) - Optional - Width of the output raster in pixels. - **height** (numeric) - Optional - Height of the output raster in pixels. - **format** (string) - Optional - Output format. Defaults to "tiff". - **raster_fn** (string) - Optional - Name of a server-side raster function to apply. - **token** (function) - Optional - An authentication token. ``` -------------------------------- ### Work with Coded Domain Values Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Decode field values based on coded domains defined in the layer. This is useful for translating domain codes into human-readable values. ```r data <- arc_select(fl) data <- encode_field_values(data, fl) ``` -------------------------------- ### publish_layer Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt A high-level function to publish an `sf` or `data.frame` object as a hosted feature service in ArcGIS. It handles adding the object as a portal item and publishing it in one step. Returns metadata of the published service. ```APIDOC ## publish_layer ### Description High-level function that adds an `sf` or `data.frame` as a portal item and publishes it as a hosted feature service in one step. Returns published service metadata. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (`sf` or `data.frame` object) - The spatial data to publish. - **title** (string) - The title for the published service. - **publish_params** (list, optional) - Parameters for publishing. Defaults to `.publish_params(title, target_crs = sf::st_crs(x))`. - **token** (authentication token, optional) - The authentication token to use for the request. - **...** (additional arguments) ### Response - Returns published service metadata. ``` -------------------------------- ### refresh_layer Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Re-fetches metadata from the remote service for a given layer object. This ensures that the local layer object reflects the current state of the remote service, while preserving any stored query parameters. ```APIDOC ## refresh_layer ### Description Re-fetches metadata from the remote service, returning an updated layer object while preserving any stored query parameters. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (layer object) - The layer object to refresh. ### Response - Returns an updated layer object with fresh metadata. ``` -------------------------------- ### update_attachments Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Replaces existing attachments identified by their attachment ID for a given feature in a FeatureLayer. It requires the FeatureLayer object, feature ID, attachment ID, and the path to the new file. Progress tracking and authentication token are optional. ```APIDOC ## update_attachments ### Description Replaces existing attachments identified by `attachment_id`. Returns a `data.frame` of update status. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (`FeatureLayer` object) - The FeatureLayer containing the attachment to update. - **feature_id** (ID) - The object ID of the feature associated with the attachment. - **attachment_id** (ID) - The ID of the attachment to replace. - **path** (string) - The file path of the new attachment. - **.progress** (boolean, optional) - Whether to show a progress indicator. Defaults to TRUE. - **token** (authentication token, optional) - The authentication token to use for the request. ### Response - Returns a `data.frame` of update status. ``` -------------------------------- ### Publishing R Analysis as ArcGIS Services Source: https://github.com/r-arcgis/arcgislayers/blob/main/README.md Publish an R analysis, such as a modified sf object, as a feature service on ArcGIS. This requires authentication and allows others to access your results. ```r # Publish an sf object as a feature service (requires authentication) my_analysis <- large_counties | dplyr::mutate(density_category = ifelse(pop_sqmi > 100, "Dense", "Sparse")) publish_layer( my_analysis, title = "County Population Density Analysis", description = "Counties categorized by population density" ) ``` -------------------------------- ### Filter Features by Bounding Box Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Apply a spatial filter to select features within a specified bounding box. The bounding box can be generated from an sf object. ```r bbox <- sf::st_bbox(my_polygon) result <- arc_select(fl, filter_geom = bbox) ``` -------------------------------- ### query_layer_attachments Source: https://github.com/r-arcgis/arcgislayers/blob/main/llms.txt Queries metadata for attachments associated with features in a FeatureLayer. It allows filtering by definition expressions, object IDs, global IDs, attachment types, and keywords. Returns a data.frame with attachment information. ```APIDOC ## query_layer_attachments ### Description Queries attachment metadata from a `FeatureLayer`. Returns a `data.frame` with attachment info including IDs, names, sizes, and content types. ### Method Not specified (assumed to be a function call in an SDK) ### Parameters - **x** (`FeatureLayer` object) - The FeatureLayer to query attachments from. - **definition_expression** (string, optional) - An SQL-like expression to filter features. Defaults to "1=1". - **attachments_definition_expression** (string, optional) - An expression to filter attachments. - **object_ids** (vector of IDs, optional) - Filter attachments for specific object IDs. - **global_ids** (vector of GUIDs, optional) - Filter attachments for specific global IDs. - **attachment_types** (vector of strings, optional) - Filter attachments by content type. - **keywords** (vector of strings, optional) - Filter attachments by keywords. - **return_metadata** (boolean, optional) - Whether to return metadata. Defaults to TRUE. - **...** (additional arguments) - **token** (authentication token, optional) - The authentication token to use for the request. ### Response - Returns a `data.frame` with attachment info including IDs, names, sizes, and content types. ```