library(arcgisutils)
library(arcgisplaces)
# Authenticate with a Developer Account API Key
<- auth_key()
token set_arc_token(token)
Overview
{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.
Installation
{arcgisplaces}
can be installed directly from CRAN using
install.packages("arcgisplaces")
Usage
The Places service enables you to find points of interest (POI) based on a location or a bounding box as well as filter your results based on a category or search text.
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 fromnear_point()
orwithin_extent()
.- Note: see
fields
for the possible attributes to return for place details.
- Note: see
Understanding categories:
categories()
: find categories by name or ID.category_details()
: get detailed information about the categories returned fromcategories()
.Find place attributes such as name, address, description, opening hours, price ratings, user ratings, and social links.
Examples
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 API documentation for more.
Place search
You can search for places near a location with near_point()
.
<- near_point(x = -122.334, y = 47.655, search_text = "Coffee")
coffee coffee
Simple feature collection with 8 features and 5 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -1122.334 ymin: -952.345 xmax: 877.666 ymax: 1047.655
Geodetic CRS: WGS 84
place_id name
1 f6059fc575735b5e3f558c96ab69e6f6 Irwin's Neighborhood Bakery and Cafe
2 88a10ccf031f02ef2697591f72e1e169 Fuel Coffee
3 5cc2d40bf37bff287382057c5fdf4978 Young Tea
4 a8c6da1aa0d08fe96e5d80d0f3b3de03 Friday Afternoon
5 906da2fe5164619199a2f2ba9c99a650 Starbucks
6 957c39de6e0a0eb8afeb841d456c72fc Mosaic Coffeehouse
7 4bdfa82268e67a698d0b8ea3d2df3853 A Muddy Cup
8 090286b411e3337850ec8fff6b43569b The Bounty
distance categories icon geometry
1 97.0 c("13002.... <NA> POINT (-122.3328 47.65539)
2 723.8 c("13035.... <NA> POINT (-122.3369 47.66122)
3 727.6 c("13033.... <NA> POINT (-122.3331 47.66152)
4 740.8 c("13036.... <NA> POINT (-122.342 47.65895)
5 767.3 13035, C.... <NA> POINT (-122.3361 47.66175)
6 774.0 c("13034.... <NA> POINT (-122.3276 47.66048)
7 964.2 c("13035.... <NA> POINT (-122.3255 47.66149)
8 976.2 c("13034.... <NA> POINT (-122.3426 47.66162)
Locations are returned as an sf object with the place ID, the place name, distance from the search point, a character vector of categories.
arcgisplaces
will return an sf object, but the sf package is not required to work with the package. The sf
print 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 using wk
or rsgeo
.
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.
<- place_details(
details $place_id,
coffeerequested_fields = "rating"
)
c("price", "user")] details[
Simple feature collection with 8 features and 2 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: Inf ymin: Inf xmax: -Inf ymax: -Inf
Geodetic CRS: WGS 84
price user location
1 Cheap 4.1 POINT EMPTY
2 Cheap 3.9 POINT EMPTY
3 <NA> NA POINT EMPTY
4 Moderate NA POINT EMPTY
5 Cheap 3.4 POINT EMPTY
6 Cheap 3.0 POINT EMPTY
7 Cheap 4.0 POINT EMPTY
8 <NA> NA POINT EMPTY
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.
<- within_extent(
bakeries -70.356, 43.588, -70.176, 43.7182,
category_id = "13002"
)
c("name")] bakeries[
Simple feature collection with 24 features and 1 field
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -70.356 ymin: 43.588 xmax: -70.176 ymax: 43.7182
Geodetic CRS: WGS 84
First 10 features:
name geometry
1 Panera Bread POINT (-70.32966 43.67791)
2 Crumbl Cookies POINT (-70.33067 43.67675)
3 Electric Bike Cafe POINT (-70.2864 43.63655)
4 BenReuben’s Knishery POINT (-70.25299 43.63748)
5 Two Fat Cats Bakery POINT (-70.26101 43.6327)
6 Auntie Anne's POINT (-70.33517 43.63372)
7 Lolli and Pops POINT (-70.33512 43.63377)
8 Panera Bread POINT (-70.3303 43.6367)
9 Cookie Jar Pastry Shop POINT (-70.22644 43.63367)
10 Bake Maine Pottery Cafe POINT (-70.25334 43.66708)