Developers

Announcing {arcgis}, an R package for ArcGIS Location Services

The R-ArcGIS Bridge team is excited to announce the release of {arcgis}, an open-source meta-package that facilitates interacting with ArcGIS location services from R. Now, ArcGIS users can access, modify, and publish web-based data from the comfort of R and their development environment of choice.

This new addition to the R-ArcGIS Bridge complements the existing {arcgisbinding} package – which “bridges” between R and ArcGIS Pro – by providing new ways for users to combine the powers of data science and statistical R packages with ArcGIS analytical, visualization, and data hosting capabilities.

{arcgis} overview

The {arcgis} meta-package provides a single point of access for users to install and load the associated packages, including:

Together, these packages enable data scientists, analysts, and developers to integrate the capabilities of R and ArcGIS for workflows and applications that use web-based services. Behind the scenes, {arcgis} achieves this by interacting with ArcGIS REST API endpoints.

With {arcgis}, users can:

Let’s take a look at a simple example of how {arcgis} can serve as a bridge between R and ArcGIS location services:

Get started by reading data from a public ArcGIS Online feature service into R

With {arcgis}, you can read data from ArcGIS web services including feature services, image services, and map services. In this simple example, you can use R to access attributes and geometries from a public ArcGIS Online feature service.

First, find an item of interest from the ArcGIS Living Atlas of the World. In this case, let’s use National Park Service Trails. You will need the URL in the bottom right corner of the page:

https://services2.arcgis.com/FiaPA4ga0iQKduv3/arcgis/rest/services/National_Park_Service_Trails/FeatureServer

This URL is the REST endpoint for the National Park Service Trails FeatureServer. {arcgis} performs requests against such endpoints to return metadata, associated layers, and feature data.

In your R development environment of choice, run the following code to install (if needed) and load the package:

install.packages('arcgis') library('arcgis')

Now assign the URL to an object, furl, and use arc_open() to retrieve the metadata for the National Park Service Trails FeatureServer:

arc_open()

This FeatureServer just contains one layer. You can access that layer by its ID (0) using get_layer():

get_layer

The NPS_Trails FeatureLayer allows query operations, giving you access to the underlying data. Because it is a best practice to only read in the data you need, consider limiting the fields returned and/or filtering using a SQL query.

Start by viewing the fields and selecting a relevant subset:

list_fields

You can also construct a SQL query to filter the park name field (UNITNAME) to only return trails in Zion National Park:

sqlquery

Now use these objects to load a subset of the feature layer’s trail data:

arc_select

This returns an sf object containing the Zion National Park trail features. You can use plot(ziontrails['TRLSURFACE']) to view the spatial features, symbolized by trail surface type. From here you can conduct analysis, build apps, or create visualizations in R!

A plot of the Zion trail features symbolized by trail surface type

About the authors

Martha Bass

Martha Bass is a Product Engineer on the Spatial Statistics team at Esri.

Connect:

Nick Giner is a Product Manager for Spatial Analysis and Data Science. Prior to joining Esri in 2014, he completed Bachelor’s and PhD degrees in Geography from Penn State University and Clark University, respectively. In his spare time, he likes to play guitar, golf, cook, cut the grass, and read/watch shows about history.

Connect:

Article Discussion:

0 Comments
Inline Feedbacks
View all comments

Next Article

Drawing a Blank? Understanding Drawing Alerts in ArcGIS Pro

Read this article