Still many geographic data is delivered through ESRI’s ArcGIS Server. It is not easy to utilize the geographic data in the GIS servers from data analysis platform like R or Pandas. This package enables users to use vector data in ArcGIS Server from R through the server’s REST API. It download geographic features from ArcGIS Server and saves it as Simple Features.
Git repository is here https://github.com/yonghah/esri2sf
This program sends a request to an ArcGIS Server and gets json responses containing coordinates of geometries. Unfortunately, ESRI’s json format is not the same as geojson. So it converts the json into WKT strings first; then creates simple feature geometries from the strings. Then it combines attribute data to the geometries to create sf dataframe. Often ArcGIS servers limits the maximum number of rows in the result set. So this program creates 500 features per request and send requests until it gets all features.
I recommend devtools to install this package.This package has dependency on dplyr, sf, httr, jsonlite
devtools::install_github("yonghah/esri2sf")## Downloading GitHub repo yonghah/esri2sf@master
## from URL https://api.github.com/repos/yonghah/esri2sf/zipball/master
## Installing esri2sf
## '/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore \
## --quiet CMD INSTALL \
## '/tmp/RtmpKwFmdK/devtools2fb564571962/yonghah-esri2sf-b5135a4' \
## --library='/usr/local/lib/R/site-library' --install-tests
##
library("esri2sf")What you need is the URL of REST service you want. You can get the URL by asking GIS admin or looking at javascript code creating feature layer.
url <- "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
df <- esri2sf(url)## [1] "Feature Layer"
## [1] "esriGeometryPoint"
plot(df)## Warning: plotting the first 9 out of 56 attributes; use max.plot = 56 to
## plot all
You can filter output fields. This may take a minute since it gets 18000 polylines.
url <- "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Florida_Annual_Average_Daily_Traffic/FeatureServer/0"
outFields <- c("AADT", "DFLG")
df <- esri2sf(url, outFields)## [1] "Feature Layer"
## [1] "esriGeometryPolyline"
plot(df)You can filter rows as well by giving where condition.
url <- "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3"
where <- "STATE_NAME = 'Michigan'"
df <- esri2sf(url, where=where, outFields=c("POP2000", "pop2007", "POP00_SQMI", "POP07_SQMI"))## [1] "Feature Layer"
## [1] "esriGeometryPolygon"
plot(df)