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:
{arcgisutils}
: developer-oriented utilities powering interactions between R and ArcGIS, including authorization and data conversion.{arcgislayers}
: functions for reading, writing, publishing, and managing data in ArcGIS Online, ArcGIS Enterprise, and ArcGIS Platform.
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:
- Authorize with ArcGIS Online, ArcGIS Enterprise, and ArcGIS Platform
- Read data from ArcGIS services
- Publish data to ArcGIS services
- Edit features in ArcGIS services
- Overwrite features in ArcGIS services
- And more!
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:
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:
Now assign the URL to an object, furl
, and use arc_open()
to retrieve the metadata for the National Park Service Trails FeatureServer:
This FeatureServer just contains one layer. You can access that layer by its ID (0
) using 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:
You can also construct a SQL query to filter the park name field (UNITNAME
) to only return trails in Zion National Park:
Now use these objects to load a subset of the feature layer’s trail data:
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!
Article Discussion: