arcgisplaces is an R package to interface with ArcGIS Places Service.
The places service is a ready-to-use location service that can search for businesses and geographic locations around the world. It allows you to find, locate, and discover detailed information about each place.
In order to use {arcgisplaces} you will need an ArcGIS Developers
account. Get started
here.
You can install a binary of the development version of arcgisplaces from r-universe with:
install.packages("arcgisplaces", repos = "https://r-arcgis.r-universe.dev")
You will also need the development version of
{arcgisutils}
if (!requireNamespace("pak")) install.packages("pak")
pak::pak("r-arcgis/arcgisutils")
Or, you can install the development version from GitHub. Note the development version requires an installation of Rust. See rustup for instructions to install Rust.
if (!requireNamespace("pak")) install.packages("pak")
pak::pak("r-arcgis/arcgisplaces")
Finding places:
near_point(): search for places near a location.within_extent(): search for places within an extent.place_details(): get detailed information about the places returned
from near_point() or within_extent().
fields for the possible attributes to return for place
details.Understanding categories:
categories(): find categories by name or ID.
category_details(): get detailed information about the categories
returned from categories().
Find place attributes such as name, address, description, opening hours, price ratings, user ratings, and social links.
{arcgisutils} is needed for authentication. The Places API supports
either using an API key via auth_key() or one generated via OAuth2
using either auth_client() or auth_code(). See the Places API
documentation
for more.
library(arcgisutils)
library(arcgisplaces)
# Authenticate with a Developer Account API Key
token <- auth_key()
set_arc_token(token)
You can search for places near a location with near_point().
coffee <- near_point(x = -122.334, y = 47.655, search_text = "Coffee")
coffee
Locations are returned as an sf object with the place ID, the place name, distance from the search point, a character vector of categories.
[!TIP]
arcgisplaceswill return an sf object, but the sf package is not required to work with the package. Thesfprint method will not be used unless the package is loaded. If package size is a consideration—i.e. deploying an app in a Docker container—consider usingwkorrsgeo.
Details for the places can be fetched using place_details(). The
possible fields are documented
online
as well as contained in the exported vector fields. Because pricing is
dependent upon which fields are requested, it is a required argument.
To get the add requested_fields = "hours". Note, that the other
possible fields will still be present in the result, but completely
empty.
details <- place_details(
coffee$place_id,
requested_fields = "rating",
.progress = FALSE # remove progress bar
)
details[c("price", "user")]
Or, you can search for places within a bounding box using
within_extent(). This could be quite handy for searching within
current map bounds, for example.
bakeries <- within_extent(
-70.356, 43.588, -70.176, 43.7182,
category_id = "13002"
)
bakeries[c("name")]