{"id":32207848,"url":"https://github.com/r-arcgis/arcgisutils","last_synced_at":"2025-10-22T05:59:53.654Z","repository":{"id":215308614,"uuid":"706290083","full_name":"R-ArcGIS/arcgisutils","owner":"R-ArcGIS","description":"Developer utilities for the R-ArcGIS Bridge. Authenticate with the ArcGIS System, read and write Esri JSON, and more.","archived":false,"fork":false,"pushed_at":"2025-10-01T18:11:05.000Z","size":69866,"stargazers_count":19,"open_issues_count":26,"forks_count":5,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-10-22T05:59:49.265Z","etag":null,"topics":["arcgis","r-spatial","rstats"],"latest_commit_sha":null,"homepage":"https://developers.arcgis.com/r-bridge/api-reference/arcgisutils/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/R-ArcGIS.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-10-17T16:49:59.000Z","updated_at":"2025-10-06T09:42:37.000Z","dependencies_parsed_at":"2024-02-21T01:40:45.577Z","dependency_job_id":"2a51b8bf-084e-43e8-b8b3-1f800820b44d","html_url":"https://github.com/R-ArcGIS/arcgisutils","commit_stats":null,"previous_names":["r-arcgis/arcgisutils"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/R-ArcGIS/arcgisutils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-ArcGIS%2Farcgisutils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-ArcGIS%2Farcgisutils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-ArcGIS%2Farcgisutils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-ArcGIS%2Farcgisutils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/R-ArcGIS","download_url":"https://codeload.github.com/R-ArcGIS/arcgisutils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-ArcGIS%2Farcgisutils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280389301,"owners_count":26322507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arcgis","r-spatial","rstats"],"created_at":"2025-10-22T05:59:44.823Z","updated_at":"2025-10-22T05:59:53.649Z","avatar_url":"https://github.com/R-ArcGIS.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\nformat: gfm\n---\n# arcgisutils \u003cimg src=\"man/figures/logo.svg\" align=\"right\" height=\"139\" alt=\"\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/R-ArcGIS/arcgisutils/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/R-ArcGIS/arcgisutils/actions/workflows/R-CMD-check.yaml)\n[![CRAN status](https://www.r-pkg.org/badges/version/arcgisutils)](https://CRAN.R-project.org/package=arcgisutils)\n[![extendr](https://img.shields.io/badge/extendr-^0.8.0-276DC2)](https://extendr.rs/extendr/extendr_api/)\n\u003c!-- badges: end --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\nlibrary(pillar)\n```\n\n\narcgisutils is the foundational infrastructure package that powers the R-ArcGIS Bridge Data and Location Service ecosystem. It provides sophisticated, production-ready tools for interacting with ArcGIS Online, ArcGIS Enterprise, and ArcGIS Platform via their REST APIs.\n\n## Key Capabilities\n\n**🔐 Comprehensive Authentication**:\n\n- Multiple OAuth2 workflows (`auth_code()`, `auth_client()`) \n- API key and legacy token support\n- Automatic token refresh and validation\n- Integration with ArcGIS Pro via `arcgisbinding`\n\n**🌐 Portal Integration**: \n\n- Advanced content search with filtering, sorting, and pagination\n- User, group, and organization metadata management\n- Portal item discovery and content management workflows\n\n**⚙️ Geoprocessing Services**: \n\n- Support for the geoprocessing service framework built upon R6 and S7\n- Enables users to call their own custom geoprocessing services or build on top of existing services\n- R6-based job management (`arc_gp_job`) with real-time status tracking and built-in result parsing\n\n**📄 Esri JSON Ecosystem**: \n\n- Bidirectional conversion between R spatial data and Esri JSON formats\n- Support for FeatureSets, geometry objects, field definitions, and spatial reference systems\n- Optimized parsing with automatic `sf` integration\n\n**🛠️ Developer Utilities**: \n\n- Standardized HTTP client (`arc_base_req()`, `arc_paginate_req()`)\n- Robust error detection and user-friendly error messages\n- URL parsing, service introspection, and metadata extraction\n\n## Installation\n\n`{arcgisutils}` is part of the `{arcgis}` metapackage, which provides the complete R-ArcGIS Bridge toolkit. For most users, installing the metapackage is recommended:\n\n```r\ninstall.packages(\"arcgis\")\n```\n\nYou can also install `{arcgisutils}` individually from CRAN:\n\n```r\ninstall.packages(\"arcgisutils\")\n```\n\nTo install the development version:\n\n```r\npak::pak(\"r-arcgis/arcgisutils\")\n```\n\n### Authentication\n\nAuthorization tokens are provided through the functions `auth_code()`, `auth_client()`, `auth_user()`, `auth_key()`, and `auth_binding()`. Additional token validation functions are provided via `refresh_token()` and `validate_or_refresh_token()`. \n\n`auth_code()` can be used for integrating into Shiny applications, for example, to have individual users log in. We recommend using `auth_key()` for authenticating in non-interactive environments (for example scheduled scripts or deployments).\n\nTokens are managed using `set_arc_token()` and `unset_arc_token()`. They are fetched using `arc_token()`. `set_arc_token()` can set the token globally or set multiple named environments. Here is a minimal example:\n\n```{r, eval=TRUE}\nlibrary(arcgisutils)\n```\n\n```{r eval=FALSE}\nkey \u003c- auth_key()\nset_arc_token(key)\n```\n\nAlternatively, tokens can be set based on a key-value pair for multiple environments:\n\n```{r eval=FALSE}\nset_arc_token(\"production\" = prod_token, \"development\" = dev_token)\n```\n\nAnd fetched based on their name via\n\n```{r eval=FALSE}\narc_token(\"production\")\n```\n\n### Portal Integration\n\nSearch and discover content across your ArcGIS organization:\n\n```{r}\n# Search for feature services containing \"crime\" data\ncrime_items \u003c- search_items(\n  query = \"crime\", \n  item_type = \"Feature Service\",\n  max_pages = 1\n)\n\ncrime_items\n```\n\n```{r}\n# Get detailed item information for a portal item\narc_item(crime_items$id[1])\n```\n\n### Developer Utilities\n\nAlways use `arc_base_req()` as this will handle setting the user agent and authorization token. The function creates a standardized `httr2` request object:\n\n```{r}\n# defaults to arcgis.com\nhost \u003c- arc_host() \n\nreq \u003c- arc_base_req(host)\nreq\n```\n\nTo handle paginated services and requests use `arc_paginate_req()` to automatically handle fetching pages.\n\n\n### Esri JSON\n\nThere are also a number of utility functions for creating and parsing Esri JSON. For example we can create an Esri `FeatureSet` json string using `as_esri_featureset()` directly from an `sf` object. \n\n```{r, message=FALSE, warning = FALSE}\nlibrary(sf)\n\n# load the NC SIDS dataset and extract centroids\n# of the first few rows\nnc \u003c- system.file(\"shape/nc.shp\", package = \"sf\") |\u003e \n  st_read(quiet = TRUE) |\u003e \n  st_centroid() \n\n# convert to json\nnc_json \u003c- as_esri_featureset(nc[1:2, 1:3])\n\njsonify::pretty_json(nc_json)\n```\n\n\nFeature set json can also be parsed using `parse_esri_json()`.\n\n```{r}\nparse_esri_json(nc_json)\n```\n\n\nAdditionally, sf's `crs` object can be converted to a [`spatialReference`](https://developers.arcgis.com/documentation/common-data-types/geometry-objects.htm#GUID-DFF0E738-5A42-40BC-A811-ACCB5814BABC) JSON object using `validate_crs()`. Convert these to json with `yyjsonr` or `jsonify`.\n\n```{r}\ncrs \u003c- validate_crs(27700)\njsonify::pretty_json(crs, unbox = TRUE)\n```\n\n### Geoprocessing Services\n\nThe geoprocessing service framework is completely supported in `{arcgisutils}`. Here we combine the functionality of the geoprocessing job framework with utilities such as `as_esri_featureset()` to call the [Trace DownStream Elevation Service](https://developers.arcgis.com/rest/elevation-analysis/trace-downstream/)\n\n```{r}\ntrace_downstream \u003c- function(\n  input_points,\n  point_id_field = NULL,\n  resolution = NULL,\n  generalize = FALSE,\n  token = arc_token()\n) {\n\n  # create a list of parameters\n  params \u003c- compact(list(\n    InputPoints = as_esri_featureset(input_points),\n    PointIdField = point_id_field,\n    DataSourceResolution = resolution,\n    Generalize = as.character(generalize),\n    f = \"json\"\n  ))\n\n  service_url \u003c- \"https://hydro.arcgis.com/arcgis/rest/services/Tools/Hydrology/GPServer/TraceDownstream\"\n  arc_gp_job$new(\n    base_url = service_url,\n    params = params,\n    result_fn = parse_gp_feature_record_set,\n    token\n  )\n}\n```\n\n\nThis new function can be called to start a new job: \n\n```{r}\n# create input points\ninput_points \u003c- st_sfc(\n  st_point(c(-159.548936, 21.955888)),\n  crs = 4326\n)\n\n# initialze an empty job\njob \u003c- trace_downstream(\n  input_points,\n  token = auth_user()\n)\n\n# start the job\njob$start()\n```\n\nJobs run asynchronously so we can check the status with `job$status`\n\n```{r include = FALSE}\nSys.sleep(0.5)\n```\n\n```{r}\njob$status\n```\n\nThen, when the job is complete, we can fetch the results applying the result function which is `parse_gp_feature_record_set()` in this case. \n\n\n```{r include=FALSE}\nSys.sleep(5)\n```\n\n```{r}\njob$results\n\n# store and view the results\nres \u003c- job$results\nres\n\n# plot the resultant geometry\nplot(st_geometry(res$geometry))\n```\n\n## Learn More\n\nTo learn more about the R-ArcGIS Bridge project visit the [developer documentation](https://developers.arcgis.com/r-bridge/).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-arcgis%2Farcgisutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-arcgis%2Farcgisutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-arcgis%2Farcgisutils/lists"}