Skip to content

Layers represent represent a data service hosted by ArcGIS Online, ArcGIS Enterprise, Platform, or even an ArcGIS Hub site. Layers are how you will interact with your remotely hosted data.

The {arcgis} R metapackage is able to work with the most common types of data services: feature services and image servers. The types of layers that the R-ArcGIS Bridge does not yet support are vector and map tile services.

Types of services

When working with these data services, each service type is assigned their own S3 class.

Class Description
FeatureLayer Represents vector data. Can contain Point, MultiPoint, Polyline, or Polygon data
Table A type of FeatureLayer in which there is no geometry present. Represents tabular data.
ImageServer Provides access to raster imagery.
FeatureServer A collection of FeatureLayer and Tables.
GroupLayer A collection of FeatureLayer and Tables.
MapServer A collection arbitrary data service types.

Accessing data services

The R package {arcgislayers} provides access to services. Working with data services follows a pattern:

  • first, create a reference to a remote data service
  • query the data service and bring the results back into R

Creating data service objects

Using {arcgislayers}, the function arc_open() will create a reference to a service based on its url.

library(arcgis)

# feature service url
furl <- "https://services3.arcgis.com/ZvidGQkLaDJxRSJ2/arcgis/rest/services/PLACES_LocalData_for_BetterHealth/FeatureServer/4"

# feature layer
flayer <- arc_open(furl)
flayer
#> <FeatureLayer>
#> Name: ZCTAs
#> Geometry Type: esriGeometryPolygon
#> CRS: 3785
#> Capabilities: Query,Extract

Querying feature services

To bring data from the service into memory in R, you must use arc_select().

Always bring as little data as possible into memory. Utilize the fields and where arguments.

arc_select(
  flayer,
  where = "TotalPopulation > 100000",
  fields = c("objectid", "totalpopulation", "zcta5")
)
#> Warning in CPL_crs_from_input(x): GDAL Message 1: CRS EPSG:3785 is deprecated.
#> Its non-deprecated replacement EPSG:3857 will be used instead. To use the
#> original CRS, set the OSR_USE_NON_DEPRECATED configuration option to NO.

#> Simple feature collection with 23 features and 3 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -13584730 ymin: 3464367 xmax: -8218961 ymax: 5130154
#> Projected CRS: WGS 84 / Pseudo-Mercator
#> First 10 features:
#>    OBJECTID TotalPopulation ZCTA5                       geometry
#> 1      8993          135256 08701 POLYGON ((-8266867 4879638,...
#> 2     10364          100594 92336 POLYGON ((-13081670 4043105...
#> 3     11777          117110 11368 POLYGON ((-8223418 4976558,...
#> 4     11806          109808 77084 POLYGON ((-10655546 3479254...
#> 5     13769          102891 90650 POLYGON ((-13148126 4018344...
#> 6     16570          103660 10467 POLYGON ((-8225085 4996136,...
#> 7     17020          100687 11236 POLYGON ((-8228926 4961496,...
#> 8     17041          103447 11219 POLYGON ((-8239056 4957777,...
#> 9     17068          100883 11385 POLYGON ((-8229187 4970250,...
#> 10    22940          105150 79936 POLYGON ((-11836698 3742458...

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.