### Initialize and Start Geoprocessing Job Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Demonstrates how to create input points, initialize a geoprocessing job using the defined `trace_downstream` function, and start the asynchronous job. ```r # create input points input_points <- st_sfc( st_point(c(-159.548936, 21.955888)), crs = 4326 ) # initialze an empty job job <- trace_downstream( input_points, token = auth_user() ) # start the job job$start() #> #> Job ID: j89b6513d04f44037b39748e8d931cb31 #> Status: esriJobExecuting #> Resource: /TraceDownstream #> Params: #> • InputPoints #> • Generalize #> • f ``` -------------------------------- ### Install arcgisutils Package Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Install the arcgisutils package from CRAN. For most users, installing the 'arcgis' metapackage is recommended. ```r install.packages("arcgis") ``` ```r install.packages("arcgisutils") ``` -------------------------------- ### Install Development Version of arcgisutils Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Install the development version of the arcgisutils package using the 'pak' package manager. ```r pak::pak("r-arcgis/arcgisutils") ``` -------------------------------- ### Async Geoprocessing Job Workflow Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Manage asynchronous geoprocessing jobs in R. This includes creating a job object, starting the job, polling its status, awaiting completion, and canceling if necessary. It also shows how to reconnect to an existing job using its URL. ```r # 1. Create a job object job <- new_gp_job( base_url = "https://logistics.arcgis.com/arcgis/rest/services/World/ServiceAreas/GPServer/GenerateServiceAreas", params = list(f = "json", travelMode = "..."), token = arc_token() ) # 2. Submit job$start() # 3. Poll status (makes an HTTP request each access) job$status # 4. Wait for completion and return results results <- job$await(interval = 0.5, verbose = TRUE) # 5. Cancel if needed job$cancel() # Reconnect to an existing job by URL job <- gp_job_from_url("https://.../GPServer/ToolName/jobs/j1234abcd") ``` -------------------------------- ### Get ArcGIS Portal Item Details Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Retrieve detailed information for a specific ArcGIS portal item using its ID. This function returns a PortalItem object. ```r # Get detailed item information for a portal item arc_item(crime_items$id[1]) #> > #> id: ea0cfecdb1de416884e6b0bf08a9e195 #> title: Neighbourhood Crime Rates Open Data #> owner: TorontoPoliceService ``` -------------------------------- ### Parameter Documentation Inheritance Source: https://github.com/r-arcgis/arcgisutils/blob/main/CLAUDE.md Use `@inheritParams` to avoid duplicating parameter documentation. Point to a function that already documents the parameters. ```r # Correct #' @inheritParams arc_base_req # Wrong: do not copy-paste param descriptions #' @param token an object of class `httr2_token`... ``` -------------------------------- ### Build Base HTTP Request Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Use `arc_base_req` to initiate an HTTP request, setting the User-Agent header and authorization token. Chain `httr2` verbs for further request modification and execution. ```r req <- arc_base_req( url = "https://services.arcgis.com/.../FeatureServer/0", token = arc_token(), path = c("query"), query = list(f = "json") ) # Chain httr2 verbs, then perform resp <- req | httr2::req_body_form(where = "1=1", outFields = "*") | httr2::req_perform() ``` -------------------------------- ### Fetch and Download Item Metadata and Data Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Retrieve metadata for a specific content item using its ID, and download the raw data associated with that item. ```r # Fetch item metadata by ID item <- arc_item("9df5e769bfe8412b8de36a2e618c7672") # Returns a PortalItem: item$id, item$title, item$type, item$owner, ... # Download the raw data backing an item raw <- arc_item_data(item) ``` -------------------------------- ### Access Users, Groups, and Content Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Retrieve information about specific users, groups, their content, and portal-wide resources. ```r arc_user("esri_en") arc_group("group_id") arc_user_content("username") arc_group_content("group_id") arc_portal_users() arc_portal_resources(id = "portal_id") ``` -------------------------------- ### Error Message Formatting with cli Source: https://github.com/r-arcgis/arcgisutils/blob/main/CLAUDE.md Employ `cli::cli_abort()` for error messages, using `call = error_call` or `call = rlang::caller_env()`. Utilize cli inline markup for clarity. ```r Use `cli::cli_abort()` with `call = error_call` (or `call = rlang::caller_env()`). Use cli inline markup: `{.arg x}`, `{.cls ClassName}`, `{.fn function_name}`, `{.val value}`, `{.code expr}`. ``` -------------------------------- ### Set Multiple Named ArcGIS Tokens Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Set ArcGIS tokens for multiple environments using key-value pairs. Fetch tokens by name using arc_token(). ```r set_arc_token("production" = prod_token, "development" = dev_token) ``` ```r arc_token("production") ``` -------------------------------- ### Content Items Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Fetch metadata for content items by their ID and download the raw data backing an item. ```APIDOC ### Content items Fetch item metadata by ID: ```r # Fetch item metadata by ID item <- arc_item("9df5e769bfe8412b8de36a2e618c7672") # Returns a PortalItem: item$id, item$title, item$type, item$owner, ... ``` Download the raw data backing an item: ```r # Download the raw data backing an item raw <- arc_item_data(item) ``` ``` -------------------------------- ### Authenticate with ArcGIS using a Key Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Authenticate using a key and set the ArcGIS token globally. This is recommended for non-interactive environments. ```r library(arcgisutils) #> #> Attaching package: 'arcgisutils' #> The following object is masked from 'package:base': #> #> %|| ``` ```r key <- auth_key() set_arc_token(key) ``` -------------------------------- ### Users, Groups, and Content Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Retrieve information about users, groups, and their associated content within the portal. ```APIDOC ### Users, groups, and content Get information about a specific user: ```r arc_user("esri_en") ``` Get information about a specific group: ```r arc_group("group_id") ``` Get a user's content: ```r arc_user_content("username") ``` Get a group's content: ```r arc_group_content("group_id") ``` Get all users in the portal: ```r arc_portal_users() ``` Get portal resources by ID: ```r arc_portal_resources(id = "portal_id") ``` ``` -------------------------------- ### View Portal Self Information Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Use these functions to view metadata about the portal, the authenticated user, registered service URLs, and federated servers. ```r # View the portal as the current user/app arc_portal_self() # Authenticated user's own metadata (credits, groups, email, etc.) arc_user_self() # Organization's registered service URLs arc_portal_urls() # Federated ArcGIS Enterprise servers arc_portal_servers() ``` -------------------------------- ### Search for Content Items Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Search for items within the portal based on various criteria such as query, item type, owner, and tags. Results can be sorted and paginated. ```r results <- search_items( query = "crime", item_type = "Feature Service", owner = "esri", tags = c("police", "public safety"), sort_field = "numviews", sort_order = "desc", page_size = 50, max_pages = 3 ) # Returns a data.frame of matching items ``` -------------------------------- ### Create Feature Collections for Web Maps Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Convert R spatial data (sf objects) into the JSON structures required to add them as feature collections to a web map. ```r layer_def <- as_layer_definition(my_sf, name = "my_layer", object_id_field = "OBJECTID") layer <- as_layer(my_sf, name = "my_layer", title = "My Layer Title") fc <- as_feature_collection(layers = list(layer)) ``` -------------------------------- ### Create Prototype Data Frame from Fields List Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Use `fields_as_ptype_df` to create an empty prototype data.frame from a list of ArcGIS field definitions. ```r # Create an empty prototype data.frame from a fields list fields_as_ptype_df(fields) ``` -------------------------------- ### Handle Paginated Requests Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Employ `arc_paginate_req` to automatically handle cursor-based pagination for portal endpoints. This function simplifies retrieving all pages of results. ```r req <- arc_base_req(host, token, path = c("sharing", "rest", "search"), query = c(f = "json", q = "crime")) responses <- arc_paginate_req( req, page_size = 50, max_pages = Inf, .progress = TRUE ) # Returns a list of httr2_response objects ``` -------------------------------- ### Displaying Parsed Date Fields Source: https://github.com/r-arcgis/arcgisutils/blob/main/tests/testthat/_snaps/date-parsing.md Shows the output of a spatial data object after date fields have been parsed. This is useful for verifying date formats and values. ```text Code res Output Simple feature collection with 120 features and 2 fields Geometry type: POINT Dimension: XY Bounding box: xmin: 3218461 ymin: 1336355 xmax: 3221347 ymax: 1339741 Projected CRS: NAD83 / Colorado Central (ftUS) First 10 features: datemodified datecreated geometry 1 2003-12-05 2002-02-11 POINT (3218466 1337879) 2 2003-12-05 2002-02-11 POINT (3218461 1337450) 3 2003-12-05 2002-02-11 POINT (3219487 1336481) 4 2012-01-11 2002-02-11 POINT (3219289 1336355) 5 2011-12-08 2002-02-11 POINT (3220772 1339674) 6 2011-12-08 2002-02-11 POINT (3221029 1339672) 7 2011-12-06 2002-02-11 POINT (3218986 1339649) 8 2011-12-08 2002-02-11 POINT (3221324 1339617) 9 2011-12-06 2002-02-11 POINT (3218830 1339545) 10 2011-12-06 2002-02-11 POINT (3218597 1339519) ``` -------------------------------- ### Search Items Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Search for content items within the portal based on various criteria such as query, item type, owner, and tags. Results can be sorted and paginated. ```APIDOC ### Search Search for items with specified criteria: ```r results <- search_items( query = "crime", item_type = "Feature Service", owner = "esri", tags = c("police", "public safety"), sort_field = "numviews", sort_order = "desc", page_size = 50, max_pages = 3 ) # Returns a data.frame of matching items ``` ``` -------------------------------- ### Convert Esri Envelope to sf bbox Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Converts an Esri Envelope list object to an sf bounding box representation. ```r # Convert Esri Envelope list to sf bbox from_envelope(list(xmin = -122.4, ymin = 37.3, xmax = -122.0, ymax = 37.8, spatialReference = list(wkid = 4326L))) ``` -------------------------------- ### R Authentication Flows Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Demonstrates various authentication methods for ArcGIS services, including interactive and non-interactive OAuth2, API keys, username/password, and ArcGIS Pro integration. Credentials are read from environment variables by default. ```r # Interactive OAuth2: opens browser, prompts for code token <- auth_code() # Non-interactive OAuth2 client credentials token <- auth_client(expiration = 120) # minutes # Static API key token <- auth_key() # Legacy username/password (generateToken endpoint) token <- auth_user() # ArcGIS Pro via arcgisbinding token <- auth_binding() # Shiny application OAuth2 (requires shinyOAuth package) client <- auth_shiny() ``` -------------------------------- ### Create Esri JSON FeatureSet from sf object Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Use `as_esri_featureset()` to convert an `sf` object into an Esri JSON FeatureSet string. Ensure the `sf` object is loaded and processed before conversion. ```r library(sf) # load the NC SIDS dataset and extract centroids # of the first few rows nc <- system.file("shape/nc.shp", package = "sf") |> st_read(quiet = TRUE) |> st_centroid() # convert to json nc_json <- as_esri_featureset(nc[1:2, 1:3]) jsonify::pretty_json(nc_json) ``` -------------------------------- ### Check Geoprocessing Job Status Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Shows how to check the current status of an asynchronous geoprocessing job using the `job$status` attribute. ```r job$status #> #> @ status: chr "esriJobExecuting" ``` -------------------------------- ### Create Base ArcGIS Request Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Create a standardized httr2 request object using arc_base_req(). This function handles setting the user agent and authorization token. Defaults to arcgis.com. ```r # defaults to arcgis.com host <- arc_host() req <- arc_base_req(host) req #> #> GET https://www.arcgis.com #> Body: empty #> Options: #> * useragent: "arcgisutils v0.4.0.9001" ``` -------------------------------- ### Define Trace Downstream Geoprocessing Function Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Defines a function to call the Trace Downstream geoprocessing service. It prepares parameters using `as_esri_featureset` and creates an `arc_gp_job` object. ```r trace_downstream <- function( input_points, point_id_field = NULL, resolution = NULL, generalize = FALSE, token = arc_token() ) { # create a list of parameters params <- compact(list( InputPoints = as_esri_featureset(input_points), PointIdField = point_id_field, DataSourceResolution = resolution, Generalize = as.character(generalize), f = "json" )) service_url <- "https://hydro.arcgis.com/arcgis/rest/services/Tools/Hydrology/GPServer/TraceDownstream" arc_gp_job$new( base_url = service_url, params = params, result_fn = parse_gp_feature_record_set, token ) } ``` -------------------------------- ### Fetch Layer Metadata Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Fetches metadata for a specific layer from an ArcGIS service URL. Requires an authentication token if the service is secured. ```r # Fetch layer metadata from a service URL meta <- fetch_layer_metadata("https://.../FeatureServer/0", token = arc_token()) ``` -------------------------------- ### Feature Collections Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Build JSON structures to add R data to a web map as a feature collection. This includes creating layer definitions and feature collection objects. ```APIDOC ## Feature Collections (Web Map layers) Build the JSON structures required to add R data to a web map as a feature collection. Create a layer definition: ```r layer_def <- as_layer_definition(my_sf, name = "my_layer", object_id_field = "OBJECTID") ``` Create a layer object: ```r layer <- as_layer(my_sf, name = "my_layer", title = "My Layer Title") ``` Create a feature collection: ```r fc <- as_feature_collection(layers = list(layer)) ``` ``` -------------------------------- ### Convert R Spatial Data to EsriJSON FeatureSet Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Generate a complete EsriJSON FeatureSet, including features, fields, and spatialReference, from R spatial objects using `as_featureset` or its equivalent `as_esri_featureset`. The output is a JSON string ready for API request bodies. ```r # Returns a JSON string ready for use in a request body as_featureset(my_sf) as_esri_featureset(my_sf) # equivalent ``` -------------------------------- ### Check if a String is a URL Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Checks if a given string is a valid URL. ```r # Check if a string is a URL is_url("https://example.com") # TRUE ``` -------------------------------- ### NULL Coalescing Operator Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Provides a NULL coalescing operator (`%||%`) to return a default value if the left-hand side is NULL. ```r # NULL coalescing NULL %||% "default" ``` -------------------------------- ### Convert R Spatial Data to EsriJSON Features Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Convert R spatial objects (sf or data.frame) into a list of EsriJSON feature objects using `as_features`. For sfc objects, `as_esri_features` creates a JSON string of feature array. ```r # sf or data.frame to list of feature objects as_features(my_sf) # sf or sfc to JSON string of feature array as_esri_features(my_sfc) ``` -------------------------------- ### Retrieve and Plot Geoprocessing Job Results Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Retrieves the results of a completed geoprocessing job and plots the resulting geometry. The results are stored in `job$results`. ```r job$results #> $param_name #> [1] "OutputTraceLine" #> #> $data_type #> [1] "GPFeatureRecordSetLayer" #> #> $geometry #> Simple feature collection with 1 feature and 6 fields #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 438895 ymin: 2422310 xmax: 443325 ymax: 2428045 #> Projected CRS: NAD83 / UTM zone 4N + Unknown VCS #> OBJECTID PourPtID Description DataResolution LengthKm #> 1 1 1 NED 10m processed by Esri 10.0 9.489823 #> Shape_Length geometry #> 1 9489.823 MULTILINESTRING ((443325 24... # store and view the results res <- job$results res #> $param_name #> [1] "OutputTraceLine" #> #> $data_type #> [1] "GPFeatureRecordSetLayer" #> #> $geometry #> Simple feature collection with 1 feature and 6 fields #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 438895 ymin: 2422310 xmax: 443325 ymax: 2428045 #> Projected CRS: NAD83 / UTM zone 4N + Unknown VCS #> OBJECTID PourPtID Description DataResolution LengthKm #> 1 1 1 NED 10m processed by Esri 10.0 9.489823 #> Shape_Length geometry #> 1 9489.823 MULTILINESTRING ((443325 24... # plot the resultant geometry plot(st_geometry(res$geometry)) ``` -------------------------------- ### Search for ArcGIS Portal Items Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Search for feature services containing 'crime' data across your ArcGIS organization. Results are returned as a data frame. ```r # Search for feature services containing "crime" data crime_items <- search_items( query = "crime", item_type = "Feature Service", max_pages = 1 ) crime_items #> # A data frame: 50 × 46 #> id owner created modified guid name title type #> * #> 1 ea0cfe… Toro… 2023-03-28 15:02:39 2026-02-02 17:45:21 NA Neig… Neig… Feat… #> 2 64691a… Temp… 2024-01-17 20:01:43 2024-01-17 20:04:45 NA hate… Hate… Feat… #> 3 5e055d… JASo… 2023-04-04 17:36:59 2023-09-07 19:05:06 NA Sher… Feat… #> 4 30644d… MyCi… 2025-03-14 14:55:06 2025-08-20 13:55:24 NA HPD_… HPD … Feat… #> 5 c749e3… open… 2024-02-23 19:36:34 2026-01-09 18:36:21 NA Crim… Feat… #> 6 e0992d… balt… 2023-07-31 20:27:01 2025-01-22 21:21:01 NA Part… Part… Feat… #> 7 2cb53d… KASU… 2019-12-10 19:06:39 2019-12-10 19:14:27 NA Viol… Viol… Feat… #> 8 5dc4e6… iwat… 2023-06-23 22:07:21 2023-08-09 15:33:46 NA Prop… Feat… #> 9 ab92f5… KASU… 2019-12-09 16:16:13 2019-12-10 18:55:20 NA Prop… Prop… Feat… #> 10 94bc33… admi… 2023-08-11 20:09:35 2026-01-09 17:03:25 NA Crim… Feat… #> # ℹ 40 more rows #> # ℹ 38 more variables: typeKeywords , description , tags , #> # snippet , thumbnail , documentation , extent , #> # categories , spatialReference , accessInformation , #> # classification , licenseInfo , culture , properties , #> # advancedSettings , url , proxyFilter , access , #> # size , subInfo , appCategories , industries , … ``` -------------------------------- ### Remove NULL List Elements Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Removes elements that are NULL from a list. ```r # Remove NULL list elements compact(list(a = 1, b = NULL, c = 3)) ``` -------------------------------- ### R Token Management Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Provides functions to manage authentication tokens for ArcGIS services. Tokens can be set for the current session, retrieved by name, unset, and validated or refreshed before use. ```r # Store a token in the session (default name: "ARCGIS_TOKEN") set_arc_token(token) # Store multiple named tokens set_arc_token(org_a = token_a, org_b = token_b) # Retrieve the default token arc_token() # Retrieve a named token arc_token("org_a") # Remove tokens unset_arc_token() unset_arc_token(c("org_a", "org_b")) # Validate or refresh before use validate_or_refresh_token(token) ``` -------------------------------- ### Standalone Parameter Validation Checks Source: https://github.com/r-arcgis/arcgisutils/blob/main/CLAUDE.md Utilize rlang standalone checks for parameter validation in functions. These checks ensure data integrity and type correctness. ```r check_string(x, allow_empty = FALSE) check_bool(x) check_number_whole(x, min = 1, max = 100) check_number_decimal(x) check_character(x, allow_null = TRUE) check_data_frame(x) check_function(x) obj_check_token(token) # validates httr2_token with arcgis_host check_token_has_user(token) # additionally checks for username field ``` -------------------------------- ### Parse ArcGIS Service URL Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Parses a given ArcGIS service URL into its constituent components, such as scheme, hostname, path, and service type. ```r # Parse an ArcGIS service URL into components arc_url_parse("https://services.arcgisonline.com/arcgis/rest/services/USA_Topo_Maps/MapServer/0") # Returns a list with: scheme, hostname, path, url, type ("MapServer"), layer ("0") ``` -------------------------------- ### Convert Esri SpatialReference to sf CRS Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Converts an Esri SpatialReference list object to an sf Coordinate Reference System (CRS) object. ```r # Convert Esri SpatialReference list to sf CRS from_spatial_reference(list(wkid = 4326L)) ``` -------------------------------- ### Detect ArcGIS Service Type from URL Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Detects the service type (e.g., FeatureServer, MapServer) from an ArcGIS service URL. ```r # Detect service type from URL arc_url_type("https://.../FeatureServer/0") # "FeatureServer" ``` -------------------------------- ### Coerce to tbl Class Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Coerces data to a tibble-style data frame for printing, without requiring the 'tibble' package. ```r # Coerce to tbl class (tibble-style printing without tibble dependency) data_frame(x) ``` -------------------------------- ### Convert R Point to EsriJSON Geometry Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Use `as_esri_geometry` to convert an R spatial point object into EsriJSON geometry format, specifying the Coordinate Reference System (CRS). ```r pt <- sf::st_point(c(-122.4, 37.8)) as_esri_geometry(pt, crs = sf::st_crs(4326)) ``` -------------------------------- ### Portal Self Information Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Retrieve information about the ArcGIS portal and the authenticated user. This includes portal details, user metadata, registered service URLs, and federated servers. ```APIDOC ## Portal API All functions default to `host = arc_host()` and `token = arc_token()`. ### Portal self View the portal as the current user/app: ```r arc_portal_self() ``` Get authenticated user's own metadata (credits, groups, email, etc.): ```r arc_user_self() ``` Get organization's registered service URLs: ```r arc_portal_urls() ``` Get federated ArcGIS Enterprise servers: ```r arc_portal_servers() ``` ``` -------------------------------- ### Geoprocessing Parameter Type Conversions Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Convert R data types to ArcGIS geoprocessing parameter types. This includes linear units, areas, feature record sets, record sets, dates, and spatial references. It also covers parsing GP responses for these types. ```r # Linear distance dist <- gp_linear_unit(distance = 100, units = "esriMeters") as_gp_linear_unit(dist) # Area area <- gp_areal_unit(area = 500, units = "esriSquareMeters") as_gp_areal_unit(area) # Feature record set (accepts sf, data.frame, PortalItem, FeatureLayer) as_gp_feature_record_set(my_sf) # Record set (tabular, no geometry) as_record_set(my_data_frame) # Date (converts to milliseconds since epoch) as_gp_date(Sys.time()) # Spatial reference as_spatial_reference(sf::st_crs(4326)) # Parsing GP responses parse_gp_feature_record_set(json) parse_gp_linear_unit(json) parse_gp_areal_unit(json) parse_gp_date(json) parse_spatial_reference(json) ``` -------------------------------- ### Parse EsriJSON to R Spatial Object or Data Frame Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Use `parse_esri_json` to convert an EsriJSON string into an R object. It returns an sf object if geometry is present, otherwise a data.frame. ```r # Converts featureSet JSON string to data.frame or sf result <- parse_esri_json(json_string) # Returns sf when geometry is present, data.frame otherwise ``` -------------------------------- ### Infer Esri Field Definitions from Data Frame Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt Use `as_fields` to infer ArcGIS field definitions from an R data.frame. The function returns a data.frame with columns for name, type, alias, nullable, and editable. ```r # Infer Esri field definitions from a data.frame fields <- as_fields(my_data) # Returns data.frame with columns: name, type, alias, nullable, editable ``` -------------------------------- ### Parse Esri JSON FeatureSet to sf object Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Use `parse_esri_json()` to convert an Esri JSON FeatureSet string back into an `sf` object. This is useful for reading data from ArcGIS services. ```r parse_esri_json(nc_json) ``` -------------------------------- ### Parse ArcGIS REST API Response with Error Detection Source: https://github.com/r-arcgis/arcgisutils/blob/main/llms.txt After parsing the response body string, use `detect_errors` to check for errors embedded within the JSON response, as ArcGIS REST API often returns HTTP 200 even for errors. ```r result <- httr2::resp_body_string(resp) | RcppSimdJson::fparse() | detect_errors() ``` -------------------------------- ### Convert CRS to ArcGIS spatialReference JSON Source: https://github.com/r-arcgis/arcgisutils/blob/main/README.md Use `validate_crs()` to convert an R CRS object into an ArcGIS `spatialReference` JSON object. This JSON can then be further processed with libraries like `jsonify`. ```r crs <- validate_crs(27700) jsonify::pretty_json(crs, unbox = TRUE) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.