MyNixOS website logo
Description

ArcGIS Utility Functions.

Developer oriented utility functions designed to be used as the building blocks of R packages that work with ArcGIS Location Services. It provides functionality for authorization, Esri JSON construction and parsing, as well as other utilities pertaining to geometry and Esri type conversions. To support 'ArcGIS Pro' users, authorization can be done via 'arcgisbinding'. Installation instructions for 'arcgisbinding' can be found at <https://r.esri.com/r-bridge-site/arcgisbinding/installing-arcgisbinding.html>.

R-CMD-check CRANstatus

arcgisutils

arcgisutils is designed as the backbone of the {arcgis} meta-package.

arcgisutils is a developer oriented package that provides the basic functions to build R packages that work with ArcGIS Location Services. It provides functionality for authorization, Esri JSON construction and parsing, as well as other utilities pertaining to geometry and Esri type conversions.

Installation

Install arcgisutils from CRAN.

install.packages("arcgisutils", repos = "https://r-arcgis.r-universe.dev")

Or, you can install the development version of arcgisutils r-universe with:

install.packages("arcgisutils", repos = "https://r-arcgis.r-universe.dev")

Authorization

Authorization tokens are provided through the functions auth_code(), auth_client(), auth_user(), and auth_binding(). Additional token validation functions are provided via refresh_token() and validate_or_refresh_token().

Tokens are managed in a session based cache using set_arc_token() and unset_arc_token(). They are fetched using arc_token(). Here is a minimal example:

library(arcgisutils)
#> 
#> Attaching package: 'arcgisutils'
#> The following object is masked from 'package:base':
#> 
#>     %||%

tkn <- auth_client()

set_arc_token(tkn)

arc_token()
#> <httr2_token>
#> token_type: bearer
#> access_token: <REDACTED>
#> expires_at: 2024-05-02 14:22:45
#> arcgis_host: https://www.arcgis.com

Alternatively, tokens can be set based on a key-value pair.

set_arc_token("A" = tkn, "B" = tkn)
#> ✔ Named tokens set: `A` and `B`
#> ℹ Access named tokens with `arc_token("name")`

And fetched based on their name via

arc_token("A")
#> <httr2_token>
#> token_type: bearer
#> access_token: <REDACTED>
#> expires_at: 2024-05-02 14:22:45
#> arcgis_host: https://www.arcgis.com

Standardized Requests

The function arc_base_req() is used to create a standardized httr2 request object. It handles authorization tokens and sets a user agent.

host <- arc_host() # use arcgis.com by default

arc_base_req(host)
#> <httr2_request>
#> GET https://www.arcgis.com
#> Body: empty
#> Options:
#> • useragent: 'arcgisutils v0.2.0.9002'

Esri JSON

There are also a number of utility functions for creating and parsing Esri JSON. For example we can create a list that represent an Esri FeatureSet using as_featurset() directly from an sf object. To convert to json, it is recommended to use jsonify::to_json(x, unbox = TRUE).

library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE

nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
nc_json <- as_featureset(nc)

str(nc_json, 1)
#> List of 3
#>  $ geometryType    : chr "esriGeometryPolygon"
#>  $ spatialReference:List of 1
#>  $ features        :List of 100

Alternatively, you can use the set of functions with the _esri_ infix to directly create the json. See the Esri geometry reference page for more on how the conversion functions work.

Additionally, sf’s crs object can be converted to a spatialReference JSON object using validate_crs().

validate_crs(27700)
#> $spatialReference
#> $spatialReference$wkid
#> [1] 27700
Metadata

Version

0.3.0

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows