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 R-universe 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
fieldsfor 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.
library(arcgisutils) library(arcgisplaces) # Authenticate with a Developer Account API Key token <- auth_key() set_arc_token(token)
Place search
You can search for places near a location with near_point().
coffee <- near_point( x = -122.3408, y = 47.62045, search_text = "Coffee" ) coffee
#> Simple feature collection with 192 features and 5 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -122.3538 ymin: 47.61173 xmax: -122.3298 ymax: 47.6289 #> Geodetic CRS: WGS 84 #> # A data frame: 192 × 6 #> place_id name distance categories icon geometry #> * <chr> <chr> <dbl> <I<list>> <chr> <POINT [°]> #> 1 5544867893cfb98075… Evok… 81.6 <df> <NA> (-122.3398 47.62078) #> 2 bce59758cec5dbd411… Café… 92.9 <df> <NA> (-122.34 47.6211) #> 3 c8598254f103cda53e… HEYT… 135. <df> <NA> (-122.3395 47.61957) #> 4 578b8f99b987065bf4… Heyt… 136. <df> <NA> (-122.3395 47.6196) #> 5 a54982e9d33423bb0c… Toas… 138. <df> <NA> (-122.3426 47.62014) #> 6 2976ac85a217254827… Herk… 147. <df> <NA> (-122.3396 47.62151) #> 7 42f3e72e7e4a3e96e9… Papa… 150. <df> <NA> (-122.3397 47.62156) #> 8 08b5207a065fc6df28… Yell… 172. <df> <NA> (-122.3386 47.62094) #> 9 dd32a24cfb739f6a33… Mi T… 174. <df> <NA> (-122.3388 47.62129) #> 10 81e1117c45a9b070e6… Male… 196. <df> <NA> (-122.3392 47.62186) #> # ℹ 182 more rows
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 geos.
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 fiew possible fields for places details use arcgisplaces::fields.
details <- place_details( coffee$place_id, requested_fields = "all" ) details[c("name", "website")]
#> Simple feature collection with 192 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -122.3538 ymin: 47.61173 xmax: -122.3298 ymax: 47.6289 #> Geodetic CRS: WGS 84 #> # A data frame: 192 × 3 #> name website location #> * <chr> <chr> <POINT [°]> #> 1 Evoke Coffee Co https://evokeespresso.com (-122.3398 47.62078) #> 2 Café An'Claire <NA> (-122.34 47.6211) #> 3 HEYTEA <NA> (-122.3395 47.61957) #> 4 Heytea <NA> (-122.3395 47.6196) #> 5 Toast To Toast <NA> (-122.3426 47.62014) #> 6 Herkimer Coffee <NA> (-122.3396 47.62151) #> 7 Papa Poy-yo http://cafes.compass-usa.com/… (-122.3397 47.62156) #> 8 Yellow Dot Cafe http://www.yellowdotcafe.com (-122.3386 47.62094) #> 9 Mi Tea <NA> (-122.3388 47.62129) #> 10 Maleng Building Café <NA> (-122.3392 47.62186) #> # ℹ 182 more rows
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.
coffee_shops <- within_extent( -70.356, 43.588, -70.176, 43.7182, category_id = "4bf58dd8d48988d1e0931735" ) coffee_shops[c("name")]
#> Simple feature collection with 86 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 #> # A data frame: 86 × 2 #> name geometry #> * <chr> <POINT [°]> #> 1 Starbucks (-70.25563 43.63533) #> 2 Udder Place (-70.29315 43.6869) #> 3 Moonday Coffee + Thicket Jewelry (-70.25243 43.66651) #> 4 Husky Brew (-70.27501 43.66279) #> 5 Gloria Jean's Coffees (-70.33649 43.63414) #> 6 Starbucks (-70.28865 43.70276) #> 7 Arabica Coffee (-70.25722 43.65708) #> 8 Higher Grounds (-70.2546 43.65568) #> 9 Dunkin' (-70.32597 43.70399) #> 10 Dunkin' (-70.27953 43.6547) #> # ℹ 76 more rows