Title: | Create Simple Features from ArcGIS Server REST API |
---|---|
Description: | This package enables you to scrape geographic features directly from ArcGIS servers REST API into R as simple features. |
Authors: | Hwang Yongha [aut, cre], Kevin Cazelles [aut, ctb], Jacob Peterson [aut, ctb], Eli Pousson [aut, ctb] |
Maintainer: | Eli Pousson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0.9000 |
Built: | 2024-10-26 04:42:18 UTC |
Source: | https://github.com/elipousson/esri2sf |
Uses the esrimeta function to get information about the field domains in the returned dataframe and joins the domain information to the dataframe. This is especially important for the codedValue type domains that are essentially factors and you loose information without replacing the data.
addDomainInfo(df, url, token = NULL, call = caller_env())
addDomainInfo(df, url, token = NULL, call = caller_env())
df |
The returned (sf) df from esri2sf/esri2df. |
url |
The url for the Map/Feature server layer/table. |
token |
string for authentication token (if needed). |
call |
The execution environment of a currently
running function, e.g. |
An sf dataframe
A reference table with links to information on the ArcGIS REST API version: https://developers.arcgis.com/rest/services-reference/enterprise/what-s-new.htm
esri_version_ref
esri_version_ref
A data frame with 19 rows and 2 variables:
version
version number
url
url for "What's New" documentation
Additional information on REST API versioning: https://developers.arcgis.com/rest/services-reference/enterprise/rest-api-versioning.htm
See the ArcGIS REST API documentation for more information on the exportImage API https://developers.arcgis.com/rest/services-reference/enterprise/export-image.htm
esri2rast( url, bbox = NULL, token = NULL, format = "jpgpng", adjustAspectRatio = FALSE, ... )
esri2rast( url, bbox = NULL, token = NULL, format = "jpgpng", adjustAspectRatio = FALSE, ... )
url |
ImageServer url |
bbox |
Bounding box for image to return; defaults to |
token |
defaults to |
format |
defaults to "jpgpng". Options include "jpgpng", "png", "png8", "png24", "jpg", "bmp", "gif", "tiff", "png32", "bip", "bsq", and "lerc" |
adjustAspectRatio |
defaults to |
SpatRaster object from terra::rast
These functions are the interface to the user.
esri2sf( url, outFields = NULL, where = NULL, geometry = NULL, bbox = NULL, token = NULL, crs = getOption("esri2sf.crs", 4326), progress = FALSE, geomType = NULL, spatialRel = NULL, replaceDomainInfo = FALSE, .name_repair = "check_unique", quiet = FALSE, ... ) esri2df( url, outFields = NULL, where = NULL, token = NULL, progress = FALSE, replaceDomainInfo = FALSE, .name_repair = "check_unique", quiet = FALSE, ... ) esrigroup( url, layerInfo = NULL, outFields = NULL, where = NULL, geometry = NULL, bbox = NULL, token = NULL, crs = getOption("esri2sf.crs", 4326), progress = TRUE, geomType = NULL, spatialRel = NULL, replaceDomainInfo = FALSE, .name_repair = "check_unique", quiet = FALSE, .fn = esri2sf, ..., call = caller_env() )
esri2sf( url, outFields = NULL, where = NULL, geometry = NULL, bbox = NULL, token = NULL, crs = getOption("esri2sf.crs", 4326), progress = FALSE, geomType = NULL, spatialRel = NULL, replaceDomainInfo = FALSE, .name_repair = "check_unique", quiet = FALSE, ... ) esri2df( url, outFields = NULL, where = NULL, token = NULL, progress = FALSE, replaceDomainInfo = FALSE, .name_repair = "check_unique", quiet = FALSE, ... ) esrigroup( url, layerInfo = NULL, outFields = NULL, where = NULL, geometry = NULL, bbox = NULL, token = NULL, crs = getOption("esri2sf.crs", 4326), progress = TRUE, geomType = NULL, spatialRel = NULL, replaceDomainInfo = FALSE, .name_repair = "check_unique", quiet = FALSE, .fn = esri2sf, ..., call = caller_env() )
url |
A service url, e.g. https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2 or an ArcGIS Online item url if the item contains a single feature or table layer. |
outFields |
vector of fields you want to include. default is |
where |
string for where condition. Default is |
geometry |
An |
bbox |
bbox class object from |
token |
string for authentication token. defaults to |
crs |
coordinate reference system (see |
progress |
Show progress bar from |
geomType |
string specifying the layer geometry ('esriGeometryPolygon'
or 'esriGeometryPoint' or 'esriGeometryPolyline' - if |
spatialRel |
Spatial relationship applied to the input |
replaceDomainInfo |
If |
.name_repair |
Treatment of problematic column names:
This argument is passed on as |
quiet |
If |
... |
additional named parameters to pass to the query. (e.g.
|
simple feature (esri2sf
) or tibble (esri2df
) or list or
tibble (esrimeta
).
esri2sf()
: Retrieve spatial object
esri2df()
: Retrieve table object (no spatial data).
When accessing services with multiple layers, the layer number must be specified at the end of the service url (e.g., https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2). #' The list of layers and their respective id numbers can be found by viewing the service's url in a web browser and viewing the "Layers" heading.
baseURL <- "https://sampleserver6.arcgisonline.com/arcgis/rest/" url <- paste0(baseURL, "services/Census/MapServer/2") outFields <- c("POP2007", "POP2000") where <- "STATE_NAME = 'Michigan'" df <- esri2sf(url, outFields = outFields, where = where) plot(df)
baseURL <- "https://sampleserver6.arcgisonline.com/arcgis/rest/" url <- paste0(baseURL, "services/Census/MapServer/2") outFields <- c("POP2007", "POP2000") where <- "STATE_NAME = 'Michigan'" df <- esri2sf(url, outFields = outFields, where = where) plot(df)
The Catalog resource from the ArcGIS REST API represents a catalog of folders and services published on the host. More information: https://developers.arcgis.com/rest/services-reference/enterprise/catalog.htm
esriCatalog( url, f = "json", token = NULL, option = NULL, outSR = NULL, ..., call = caller_env() ) esricatalog( url, f = "json", token = NULL, option = NULL, outSR = NULL, ..., call = caller_env() )
esriCatalog( url, f = "json", token = NULL, option = NULL, outSR = NULL, ..., call = caller_env() ) esricatalog( url, f = "json", token = NULL, option = NULL, outSR = NULL, ..., call = caller_env() )
url |
A folder, service, or layer URL that can be used with the ArcGIS REST API. |
f |
Format to use for request. Supported options include "json", "sitemap", or "geositemap"; "html" and "kmz" are not currently supported. |
token |
String for authentication token; defaults to |
option |
If |
outSR |
Output spatial reference of the geometry returned in footprints;
only supported when |
... |
Additional parameters passed to httr2::req_url_query |
call |
The execution environment of a currently
running function, e.g. |
This function allows the use of an ArcGIS GeocodeServer url to support the Find Address Candidates and Reverse Geocode REST APIs. Provide an address parameter to use Find Address Candidates or a coords parameter to use Reverse Geocode.
esrigeocode( url, address = NULL, coords = NULL, score = 0.95, n = 1, token = NULL, crs = getOption("esri2sf.crs", 4326), geometry = TRUE, ..., call = caller_env() )
esrigeocode( url, address = NULL, coords = NULL, score = 0.95, n = 1, token = NULL, crs = getOption("esri2sf.crs", 4326), geometry = TRUE, ..., call = caller_env() )
url |
A GeocodeServer service url. Required. |
address |
Single line address passed at the "SingleLine" parameter to
the ArcGIS REST API. Specific format may depend on specific server
configuration, Default: |
coords |
Numeric vector with longitude, latitude coordinates or a sf
object where the centroid is used as the coordinates. Default: |
score |
Accuracy score, if provided only return results with provided accuracy score or greater Default: 0.95 |
n |
Number of candidates to return, Default: 1 |
token |
Token, Default: |
crs |
Coordinate reference system to return. |
geometry |
If |
... |
Additional parameters passed to |
call |
The execution environment of a currently
running function, e.g. |
Get a feed in a DCAT US, DCAT AP, RSS, or OGC Definitions format of the public data or other content published on an ArcGIS Hub site.
esrihub( url, format = c("dcat-us", "dcat-ap", "rss", "ogc"), simplifyVector = TRUE, call = caller_env() )
esrihub( url, format = c("dcat-us", "dcat-ap", "rss", "ogc"), simplifyVector = TRUE, call = caller_env() )
url |
A url for an ArcGIS Hub site |
format |
Format of data to return, See
https://doc.arcgis.com/en/hub/content/federate-data-with-external-catalogs.htm
for more information. Default: |
simplifyVector |
Passed to |
call |
The execution environment of a currently
running function, e.g. |
A list of metadata for the public content on the ArcGIS Hub site.
Recurse over a ArcGIS Server url or folder url to return a data frame index
of folders, services, layers, and tables. This function returns additional
information than esriCatalog()
using f = "sitemap"
or f = "geositemap"
.
esriIndex( url, folderPath = NULL, serviceName = NULL, recurse = FALSE, token = NULL, ... ) esriIndexLayers(url, folderPath = NULL, serviceName = NULL, token = NULL, ...) esriindex( url, folderPath = NULL, serviceName = NULL, recurse = FALSE, token = NULL, ... )
esriIndex( url, folderPath = NULL, serviceName = NULL, recurse = FALSE, token = NULL, ... ) esriIndexLayers(url, folderPath = NULL, serviceName = NULL, token = NULL, ...) esriindex( url, folderPath = NULL, serviceName = NULL, recurse = FALSE, token = NULL, ... )
url |
URL for ArcGIS server, folder, or service. |
folderPath , serviceName
|
Name of parent folder or service; only used internally (not intended for user). |
recurse |
If |
token |
String for authentication token; defaults to |
... |
Additional parameters passed to |
Return server info, service item info, metadata, or thumbnail. The magick package is required to return a thumbnail.
esriInfo(url, info = NULL, format = NULL, token = NULL, ...)
esriInfo(url, info = NULL, format = NULL, token = NULL, ...)
url |
A folder, service, or layer URL that can be used with the ArcGIS REST API. |
info |
Info service to use. Options include "info", "item", "metadata", or "thumbnail". If info = "info" (default) basic server information is displayed and the body of the response is returned invisibly. |
format |
If |
token |
String for authentication token; defaults to |
... |
Additional parameters passed to httr2::req_url_query |
Additional documentation: https://developers.arcgis.com/rest/services-reference/enterprise/info.htm
esriitem()
provides partial support from the ArcGIS Content API.
esriitem( url, type = "data", destfile = tempfile(fileext = "pdf"), simplifyVector = TRUE, ... )
esriitem( url, type = "data", destfile = tempfile(fileext = "pdf"), simplifyVector = TRUE, ... )
type |
"data", "info", "metadata", "config" (app URLs only) |
destfile |
Destination file used to download item if data is a PDF file. |
simplifyVector |
Should JSON arrays containing only primitives (i.e. booleans, numbers, and strings) be caused to atomic vectors? |
... |
Arguments passed on to
|
A list, a xml document, or the response object from the request.
Retrieve JSON for all layers and tables as specified in https://si-pweb-vecmap.si.edu/vectormap/sdk/rest/index.html#/All_Layers_and_Tables/02ss0000005t000000/. Service type must either be a MapServer or FeatureServer. Performs a request towards the server url in one of the following the forms:
https://<host>/<instance>/rest/services/<folderName>/serviceName>/MapServer/layers
https://<host>/<instance>/rest/services/serviceName>/MapServer/layers
https://<host>/<instance>/rest/services/<folderName>/serviceName>/FeatureServer/layers
https://<host>/<instance>/rest/services/serviceName>/FeatureServer/layers
esriLayers( url, token = NULL, returnUpdates = NULL, returnDomainNames = TRUE, ..., call = caller_env() )
esriLayers( url, token = NULL, returnUpdates = NULL, returnDomainNames = TRUE, ..., call = caller_env() )
url |
The url for the Map/Feature server. If given a url specifying a layer or table ID it will truncate it. |
token |
String for authentication token; defaults to |
returnUpdates |
If |
returnDomainNames |
If |
... |
Additional parameters passed to httr2::resp_body_json |
call |
The execution environment of a currently
running function, e.g. |
A list from the JSON return.
Retrieve layer metadata
esrimeta(url, token = NULL, fields = FALSE, ..., call = caller_env())
esrimeta(url, token = NULL, fields = FALSE, ..., call = caller_env())
url |
url to retrieve metadata for. |
token |
String for authentication token; defaults to |
fields |
|
... |
Additional parameters passed to httr2::req_url_query |
call |
The execution environment of a currently
running function, e.g. |
This function is primarily useful for the development of new functions to access the ArcGIS REST API. Most users do not need to use this function directly.
esriRequest( url, append = NULL, f = NULL, format = NULL, objectIds = NULL, token = NULL, .perform = TRUE, .cache = FALSE, .max_seconds = 3, .is_error = TRUE, .body_form = FALSE, ..., call = caller_env() )
esriRequest( url, append = NULL, f = NULL, format = NULL, objectIds = NULL, token = NULL, .perform = TRUE, .cache = FALSE, .max_seconds = 3, .is_error = TRUE, .body_form = FALSE, ..., call = caller_env() )
url |
A folder, service, or layer URL that can be used with the ArcGIS REST API. |
append |
String to append to url using httr2::req_url_path_append;
defaults to |
f , format
|
Return format to use as query parameter with httr2::req_url_query; defaults to "json". |
objectIds |
Parameter used for layer query requests. The addition of objectIds to the query often leads the url length to exceed the 2048 character maximum. In those cases, the query is added to the body of the request with httr2::req_body_form |
token |
String for authentication token; defaults to |
.perform |
If |
.cache |
If |
.max_seconds |
Passed to max_seconds parameter of httr2::req_retry |
.is_error |
If |
.body_form |
If objectIds is |
... |
Additional parameters passed to httr2::req_url_query |
call |
The execution environment of a currently
running function, e.g. |
Use a query or bounding box to search for items on ArcGIS Online or on an ArcGIS Enterprise Server. See https://developers.arcgis.com/rest/users-groups-and-items/search.htm for more information on the Search endpoint for the Portal Directory API (also known as the Sharing API). A query or bbox argument must be provided.
esrisearch( query = NULL, bbox = NULL, url = NULL, num = 50, start = 1, category_filter = NULL, sort = NULL, desc = FALSE, quiet = FALSE )
esrisearch( query = NULL, bbox = NULL, url = NULL, num = 50, start = 1, category_filter = NULL, sort = NULL, desc = FALSE, quiet = FALSE )
query |
Search terms, Default: |
bbox |
A |
url |
ArcGIS Enterprise request URL (e.g.
"https://machine.domain.com/webadaptor/") or ArcGIS Online organization url
(e.g. "https://org.arcgis.com"). If |
num |
Maximum number of results to return, Default: 50 (must be between 1 and 100). |
start |
Start number for returned results, Default: 1 (returns results starting from the first result). |
category_filter |
Terms to use in searching for items with matching
categories. Only 3 or less terms currently supported, Default: |
sort |
Field to use for results sort order. Options include "modified",
"title", "created", "type", "owner", "avgrating", "numratings",
"numcomments", "numviews". Default: |
desc |
If |
quiet |
If |
A tibble data.frame with results from the item search.
## Not run: if (interactive()) { esrisearch(query = "park") esrisearch(query = c("ocean", "basemap")) nc <- sf::st_read(system.file("shape/nc.shp", package = "sf")) esrisearch(bbox = nc) } ## End(Not run)
## Not run: if (interactive()) { esrisearch(query = "park") esrisearch(query = c("ocean", "basemap")) nc <- sf::st_read(system.file("shape/nc.shp", package = "sf")) esrisearch(bbox = nc) } ## End(Not run)
A collection of functions that pull select parts out of a ESRI Service URL. All urls should be a form similar to:
https://<host>/<instance>/rest/services/<folderPath>/serviceName>/<serviceType>/<featureID>
http://<host>/<instance>/rest/services/serviceName>/<serviceType>
<host>/<instance>/rest/services/<folderPath>/serviceName>/<serviceType>
https://<host>/<instance>/rest/services/serviceName>/<serviceType>/<featureID>
https://<host>/<instance>/rest/services/<folderPath>
https://<host>/<instance>/rest/services
And having these rules:
The scheme: https://
or http://
part is optional
The host
part is the domain of the url.
The instance
is the first subpage after the domain in the url.
The /rest/services
is the second and third subpage in the url. These are
standard for all ESRI REST Services.
The folderPath
part is optional and indicates the file structure in the
REST Service. It consists of all subpages between /rest/services/
and the
serviceName
part (if available).
The serviceName
part is the last subpage betore the <serviceType>
in
the url.
The serviceType
specifies the type of service. Currently this package
works to manage the following serviceTypes: 'MapServer', 'FeatureServer',
'GPServer', 'GeocodeServer', 'GeometryServer', 'ImageServer'.
The featureID
is optional and specifies the layer or table in the map
service.
esriUrl_isValid(url, token = NULL, displayReason = FALSE) esriUrl_isValidRoot(url, token = NULL, displayReason = FALSE) esriUrl_isValidFolder(url, token = NULL, displayReason = FALSE) esriUrl_isValidService(url, token = NULL, displayReason = FALSE) esriUrl_isValidID(url, token = NULL, displayReason = FALSE) esriUrl_isValidFeature(url, token = NULL, displayReason = FALSE) esriUrl_ServerUrl(url, token = NULL) esriUrl_serviceUrl(url, token = NULL, call = caller_env()) esriUrl_parseUrl(url, token = NULL, call = caller_env())
esriUrl_isValid(url, token = NULL, displayReason = FALSE) esriUrl_isValidRoot(url, token = NULL, displayReason = FALSE) esriUrl_isValidFolder(url, token = NULL, displayReason = FALSE) esriUrl_isValidService(url, token = NULL, displayReason = FALSE) esriUrl_isValidID(url, token = NULL, displayReason = FALSE) esriUrl_isValidFeature(url, token = NULL, displayReason = FALSE) esriUrl_ServerUrl(url, token = NULL) esriUrl_serviceUrl(url, token = NULL, call = caller_env()) esriUrl_parseUrl(url, token = NULL, call = caller_env())
url |
The url for a Map/Feature server or for a layer/table in a Map/Feature Server. |
token |
String for authentication token (if needed). |
displayReason |
Should the reason for why a url is not valid be displayed. |
Character string of the request part of the url.
esriUrl_isValid()
: Check if url is valid for an ESRI REST Service. General
to include potential layer id too.
esriUrl_isValidRoot()
: Check if url is valid for the root of an ESRI REST
Server.
esriUrl_isValidFolder()
: Check if url is valid for a folder of an ESRI REST
Server.
esriUrl_isValidService()
: Check if url is valid for a Service of an ESRI REST
Server. No feature ID.
esriUrl_isValidID()
: DEPRECATED Use esriUrl_isValidFeature
esriUrl_isValidFeature()
: Check if url is valid for a feature of an ESRI REST
Service.
esriUrl_ServerUrl()
: DEPRECATED Use esriUrl_serviceUrl
esriUrl_serviceUrl()
: Retrieve Map/Feature Server URL
esriUrl_parseUrl()
: Parse Url into parts.
Get ArcGIS Online user information
esriuser(url = NULL, user_id = NULL)
esriuser(url = NULL, user_id = NULL)
url |
An ArcGIS Online community URL with a user ID. Optional if user_id is supplied. |
user_id |
An ArcGIS Online user ID. Optional if url is supplied. |
extract_esri_item_id()
extract a id or appid value from a URL. If a group
url is supplied a group ID is extracted.
extract_esri_user_id()
extracts a user id from a profile URL or owner id
from a search URL.
extract_esri_item_id( url, pattern = c("(?<=id=)[A-Za-z0-9]+", "(?<=appid=)[A-Za-z0-9]+"), collapse = "|" ) extract_esri_user_id( url, pattern = c("(?<=user=)[A-Za-z0-9\\._\\-]+", "(?<=owner%3A%22)[A-Za-z0-9\\._\\-]+"), collapse = "|" )
extract_esri_item_id( url, pattern = c("(?<=id=)[A-Za-z0-9]+", "(?<=appid=)[A-Za-z0-9]+"), collapse = "|" ) extract_esri_user_id( url, pattern = c("(?<=user=)[A-Za-z0-9\\._\\-]+", "(?<=owner%3A%22)[A-Za-z0-9\\._\\-]+"), collapse = "|" )
POSIXct
datesfmt_epoch_date()
converts a single numeric epoch data value to a POSIXct
class object. fmt_epoch_dates()
converts a numeric vector to POSIXct
dates.
fmt_epoch_date(x, tz = "") fmt_epoch_dates(x, tz = "")
fmt_epoch_date(x, tz = "") fmt_epoch_dates(x, tz = "")
x |
Numeric value corresponding to epoch date. |
tz |
a character string. The time zone specification to be used
for the conversion, if one is required. System-specific (see
time zones), but |
Generate tokens for accessing credentialed ArcGIS REST Servers.
generateToken()
can create a token from the public token endpoint
https://<host>:\<port\>/\<site\>/tokens/generateToken
or the admin endpoint
https://\<host\>:\<port\>/\<site\>/admin/generateToken
for ArcGIS REST
Servers. See https://developers.arcgis.com/rest/services-reference/enterprise/generate-token.htm
or https://developers.arcgis.com/rest/services-reference/enterprise/generate-admin-token.htm
respectively for more information.
If server
is NULL
and url
is provided the endpoint is
https://\<url\>/sharing/generateToken
. See
https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm
for more information.
generateOAuthToken()
can create an OAuth token for ArcGIS Online Services.
See https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/accessing-arcgis-online-services/
or https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/
for more information.
generateToken( server = NULL, url = NULL, uid, pwd = NULL, type = NULL, client = "requestip", expiration = 5000, referer = NULL, ip = NULL, ... ) generateOAuthToken(clientId, clientSecret, expiration = 5000, ...)
generateToken( server = NULL, url = NULL, uid, pwd = NULL, type = NULL, client = "requestip", expiration = 5000, referer = NULL, ip = NULL, ... ) generateOAuthToken(clientId, clientSecret, expiration = 5000, ...)
server |
The ArcGIS REST Server you want to connect to:
|
url |
The url to connect to using
|
uid |
The user id (username) of the account used to create the token connection to the server |
pwd |
The password of the account used to create the token connection to
the server. If |
type |
Either 'tokens' or 'admin'. Specify the endpoint you use to create the token. Defaults to 'tokens' if server is provided. |
client |
"requestip" (default), "referer", or "ip" |
expiration |
Set an expiration limit on the token in minutes. Max expiration date may be controlled by the server. |
referer , ip
|
Additional parameters required if client is "referer" or "ip" |
... |
Additional parameters passed to |
clientId |
Client ID |
clientSecret |
Client Secret |
Character string with the token
generateToken()
: Create ArcGIS REST Service Token
generateOAuthToken()
: Create ArcGIS OAuth Token
Helpers for creating ANSI SQL queries
glue_ansi_sql(..., .con = DBI::ANSI(), .envir = parent.frame()) glue_sql_bbox(bbox, coords = c("longitude", "latitude"), crs = 4326)
glue_ansi_sql(..., .con = DBI::ANSI(), .envir = parent.frame()) glue_sql_bbox(bbox, coords = c("longitude", "latitude"), crs = 4326)
... |
Additional parameters passed to |
.con |
[ |
.envir |
[ |
bbox |
A |
coords |
Column names with longitude and latitude values. |
crs |
Coordinate reference system used for coordinate values. |
values <- c("a", "b", "c") glue_ansi_sql("letter", " IN ({values*})")
values <- c("a", "b", "c") glue_ansi_sql("letter", " IN ({values*})")
Is URL an ESRI content url?
is_esri_content_url(x) is_esri_item_url(x) is_esri_app_url(x)
is_esri_content_url(x) is_esri_item_url(x) is_esri_app_url(x)