knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Access ArcGIS online API enpoints with R
aarapir provides an R interface for querying and downloading publically accessible ArcGIS Online feature layers. The primary goal is to provide R users with an easy way to download features from ArcMap Online. I don't not anticipate this to be a full-fledged API to ArcGIS Online and Enterprise. See the ArcGIS Python API for a more robust access to the ArcGIS API. This is super experimental and likely to change. This project is not associated with or supported by ESRI.
[x] Return mapservice information
[x] Return feature layer information
[x] Return full feature layers (will loop requests if the maximum number of records is limited)
[x] Pass user query so only needed records are returned
[ ] Return image service information
[ ] Provide interface for image or tile data
Download a point feature layer:
library(aarapir) ## Start with a mapserver url, these typically end in "/MapServer" ## Some examples here: https://sampleserver6.arcgisonline.com/arcgis/rest/services url <- "https://sampleserver6.arcgisonline.com/arcgis/rest/services/WindTurbines/MapServer" ## This returns a list with information from the Map Service webserver <- service_info(url) ## We can see what feature layers are available to download webserver$layers ## This returns a list with information about the feature layer ## id 0 layerinfo <- layer_info(webserver, 0) ## This downloads the entire feature layer and reads it into a ## simple feature dataframe dat <- layer_download(layerinfo) dat ## If you want to return only objects from a query: dat <- layer_download(layerinfo, query = "notes = 'test'") ## note query support might vary by server, but generally standard query functions ## work. more info: https://gisweb.tceq.texas.gov/arcgis/sdk/rest/index.html#/Query_Map_Service_Layer/02ss0000000r000000/ ## enter the query in quoted plain text, the function will do the proper URI encoding dat
Downloading mosaiced images works. I'm having difficulty finding maps that allow downloading source rasters even though it is supported by the API. This is definately going to change.
url <- "https://landsat2.arcgis.com/arcgis/rest/services/Landsat8_Views/ImageServer" webserver <- service_info(url) r1 <- image_download(webserver, size = "800,500",) r1 raster::plotRGB(r1, r = 4, g = 3, b = 2, stretch = "lin", bgalpha = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.