Skip to content

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 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:

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.

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)

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 188 features and 5 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -122.3538 ymin: 47.61173 xmax: -122.3298 ymax: 47.62903
#> Geodetic CRS:  WGS 84
#> # A data frame: 188 × 6
#>    place_id   name  distance categories
#>  * <chr>      <chr>    <dbl> <I<list>> 
#>  1 554486789… Evok…     81.6 <df>      
#>  2 bce59758c… Café…     92.9 <df>      
#>  3 a54982e9d… Toas…    138.  <df>      
#>  4 2976ac85a… Herk…    147.  <df>      
#>  5 42f3e72e7… Papa…    150.  <df>      
#>  6 08b5207a0… Yell…    172.  <df>      
#>  7 dd32a24cf… Mi T…    174.  <df>      
#>  8 81e1117c4… Male…    196.  <df>      
#>  9 f3858c5ae… Star…    209   <df>      
#> 10 175270370… Cafe…    210.  <df>      
#> # ℹ 178 more rows
#> # ℹ 2 more variables: icon <chr>,
#> #   geometry <POINT [°]>

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 188 features and 2 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -122.3538 ymin: 47.61173 xmax: -122.3298 ymax: 47.62903
#> Geodetic CRS:  WGS 84
#> # A data frame: 188 × 3
#>    name                 website        
#>  * <chr>                <chr>          
#>  1 Evoke Coffee Co      https://evokee…
#>  2 Café An'Claire       <NA>           
#>  3 Toast To Toast       <NA>           
#>  4 Herkimer Coffee      <NA>           
#>  5 Papa Poy-yo          http://cafes.c…
#>  6 Yellow Dot Cafe      http://yellowd…
#>  7 Mi Tea               <NA>           
#>  8 Maleng Building Café <NA>           
#>  9 Starbucks            https://www.st…
#> 10 Cafe Moby in Roxanne <NA>           
#> # ℹ 178 more rows
#> # ℹ 1 more variable:
#> #   location <POINT [°]>

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 80 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: 80 × 2
#>    name                   geometry
#>  * <chr>               <POINT [°]>
#>  1 Middle St… (-70.25169 43.65877)
#>  2 HiFi       (-70.25785 43.65712)
#>  3 Speckled …  (-70.24799 43.6598)
#>  4 Yordprom … (-70.26945 43.65291)
#>  5 Buzz Coff… (-70.25361 43.65695)
#>  6 Coffee By… (-70.25674 43.66608)
#>  7 Aroma Joe… (-70.30434 43.62121)
#>  8 Mister Ba…  (-70.3328 43.63843)
#>  9 Starbucks  (-70.33097 43.59148)
#> 10 Scratch B… (-70.23063 43.63929)
#> # ℹ 70 more rows

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.