MyNixOS website logo
Description

Geocoding with the 'ArcGIS' REST API Service.

Lite interface for finding locations of addresses or businesses around the world using the 'ArcGIS' REST API service <https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm>. Address text can be converted to location candidates and a location can be converted into an address. No API key required.

arcgeocoder arcgeocoder website

CRANstatus CRANresults Downloads R-CMD-check codecov r-universe CodeFactor Project Status: Active – The project has reached a stable, usablestate and is being activelydeveloped. DOI status

The goal of arcgeocoder is to provide a light interface for geocoding addresses and reverse geocoding location trough the ArcGIS REST API Geocoding Service.

Full site with examples and vignettes on https://dieghernan.github.io/arcgeocoder/

Why arcgeocoder?

arcgeocoder is a package that provides a lightweight interface for geocoding and reverse geocoding with the ArcGIS REST API service. The goal of arcgeocoder is to access the ArcGIS REST API with fewer dependencies, such as curl. In some situations, curl may not be available or accessible, so arcgeocoder uses base functions to overcome this limitation.

The interface of apigeocoder is built with the aim of easing the access to all the features provided by the API. The API endpoints used by arcgeocoder are findAddressCandidates and reverseGeocode, which can be accessed without the need for an API key.

Recommended packages

There are other packages much more complete and mature than arcgeocoder, that presents similar features:

Installation

Install arcgeocoder from CRAN with:

install.packages("arcgeocoder")

You can install the developing version of arcgeocoder with:

remotes::install_github("dieghernan/arcgeocoder")

Alternatively, you can install arcgeocoder using the r-universe:

# Install arcgeocoder in R:
install.packages("arcgeocoder",
  repos = c(
    "https://dieghernan.r-universe.dev",
    "https://cloud.r-project.org"
  )
)

Usage

Geocoding and reverse geocoding

Note: examples adapted from tidygeocoder package

In this first example we will geocode a few addresses using the arc_geo() function. Note that arcgeocoder works straight away, and you don’t need to provide any API key to start geocoding!

library(arcgeocoder)
library(dplyr)

# create a dataframe with addresses
some_addresses <- tribble(
  ~name,                  ~addr,
  "White House",          "1600 Pennsylvania Ave NW, Washington, DC",
  "Transamerica Pyramid", "600 Montgomery St, San Francisco, CA 94111",
  "Willis Tower",         "233 S Wacker Dr, Chicago, IL 60606"
)

# geocode the addresses
lat_longs <- arc_geo(some_addresses$addr, lat = "latitude", long = "longitude")
#>   |                                                          |                                                  |   0%  |                                                          |=================                                 |  33%  |                                                          |=================================                 |  67%  |                                                          |==================================================| 100%

Only a few fields are returned from the geocoder service in this example, but full_results = TRUE can be used to return all of the data from the geocoder service.

querylatitudelongitudeaddressscorexyxminyminxmaxymaxwkidlatestWkid
1600 Pennsylvania Ave NW, Washington, DC38.89768-77.036551600 Pennsylvania Ave NW, Washington, District of Columbia, 20500100-77.0365538.89768-77.0375538.89668-77.0355538.8986843264326
600 Montgomery St, San Francisco, CA 9411137.79517-122.40278600 Montgomery St, San Francisco, California, 94111100-122.4027837.79517-122.4037837.79417-122.4017837.7961743264326
233 S Wacker Dr, Chicago, IL 6060641.87877-87.63580233 S Wacker Dr, Chicago, Illinois, 60606100-87.6358041.87877-87.6368041.87777-87.6348041.8797743264326

To perform reverse geocoding (obtaining addresses from geographic coordinates), we can use the arc_reverse_geo() function. The arguments are similar to the arc_geo() function, but now we specify the input data columns with the x and y arguments. The dataset used here is from the geocoder query above. The single line address is returned in a column named by the address.

reverse <- arc_reverse_geo(
  x = lat_longs$longitude,
  y = lat_longs$latitude,
  address = "address_found"
)
#>   |                                                          |                                                  |   0%  |                                                          |=================                                 |  33%  |                                                          |=================================                 |  67%  |                                                          |==================================================| 100%
xyaddress_found
-77.0365538.89768White House, 1600 Pennsylvania Ave NW, Washington, DC, 20500, USA
-122.4027837.79517Transamerica Pyramid, 600 Montgomery St, San Francisco, CA, 94111, USA
-87.6358041.87877Willis Tower, 233 S Wacker Dr, Chicago, IL, 60606, USA

It is possible also to search for specific locations within or near a reference are or location using category filtering. See more information in the documentation of the data base arc_categories.

In the following example we would look for POIs related with food (i.e. Restaurants, Coffee Shops, Bakeries) near the Eiffel Tower in France.

library(ggplot2) # For plotting

# Step 1: Locate Eiffel Tower, using multifield query

eiffel_tower <- arc_geo_multi(
  address = "Tour Eiffel",
  city = "Paris",
  countrycode = "FR",
  langcode = "FR",
  custom_query = list(outFields = "LongLabel")
)

# Display results
eiffel_tower %>%
  select(lon, lat, LongLabel)
#> # A tibble: 1 × 3
#>     lon   lat LongLabel                                                         
#>   <dbl> <dbl> <chr>                                                             
#> 1  2.29  48.9 Tour Eiffel, 5 Avenue Anatole France, 75007, 7e Arrondissement, P…


# Use lon,lat to boots the search and using category = Food
food_eiffel <- arc_geo_categories("Food",
  x = eiffel_tower$lon,
  y = eiffel_tower$lat,
  limit = 50, full_results = TRUE
)

# Plot by Food Type
ggplot(eiffel_tower, aes(x, y)) +
  geom_point(shape = 17, color = "red", size = 4) +
  geom_point(data = food_eiffel, aes(x, y, color = Type)) +
  labs(
    title = "Food near the Eiffel Tower",
    subtitle = "Using arcgecoder",
    color = "Type of place",
    x = "",
    y = "",
    caption = "Data from ArcGIS REST API services"
  )

arcgeocoder and r-spatial

It is straightforward to convert the results of arcgeocoder to an sf object (geospatial format):

library(sf)

food_eiffel_sf <- st_as_sf(food_eiffel,
  coords = c("lon", "lat"),
  # The CRS of the resulting coords is here
  crs = eiffel_tower$wkid
)

food_eiffel_sf
#> Simple feature collection with 50 features and 75 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 2.29211 ymin: 48.85416 xmax: 2.30085 ymax: 48.86252
#> Geodetic CRS:  WGS 84
#> # A tibble: 50 × 76
#>    q_category   q_x   q_y q_bbox_xmin q_bbox_ymin q_bbox_xmax q_bbox_ymax
#>  * <chr>      <dbl> <dbl> <lgl>       <lgl>       <lgl>       <lgl>      
#>  1 Food        2.29  48.9 NA          NA          NA          NA         
#>  2 Food        2.29  48.9 NA          NA          NA          NA         
#>  3 Food        2.29  48.9 NA          NA          NA          NA         
#>  4 Food        2.29  48.9 NA          NA          NA          NA         
#>  5 Food        2.29  48.9 NA          NA          NA          NA         
#>  6 Food        2.29  48.9 NA          NA          NA          NA         
#>  7 Food        2.29  48.9 NA          NA          NA          NA         
#>  8 Food        2.29  48.9 NA          NA          NA          NA         
#>  9 Food        2.29  48.9 NA          NA          NA          NA         
#> 10 Food        2.29  48.9 NA          NA          NA          NA         
#> # ℹ 40 more rows
#> # ℹ 69 more variables: address <chr>, score <int>, x <dbl>, y <dbl>,
#> #   Loc_name <chr>, Status <chr>, Score <int>, Match_addr <chr>,
#> #   LongLabel <chr>, ShortLabel <chr>, Addr_type <chr>, Type <chr>,
#> #   PlaceName <chr>, Place_addr <chr>, Phone <chr>, URL <chr>, Rank <int>,
#> #   AddBldg <chr>, AddNum <chr>, AddNumFrom <chr>, AddNumTo <chr>,
#> #   AddRange <chr>, Side <chr>, StPreDir <chr>, StPreType <chr>, …

ggplot(food_eiffel_sf) +
  geom_sf(aes(color = Type)) +
  coord_sf(crs = 3035)

See additional articles showing how arcgeocoder can be use in combination with leaflet to create dynamic maps and with sf and terra to create static maps.

Citation

Hernangómez D (2024). arcgeocoder: Geocoding with the ArcGIS REST API Service. doi:10.5281/zenodo.10495365, https://dieghernan.github.io/arcgeocoder/.

A BibTeX entry for LaTeX users is

@Manual{R-arcgeocoder,
  title = {{arcgeocoder}: Geocoding with the {ArcGIS} {REST} {API} Service},
  author = {Diego Hernangómez},
  year = {2024},
  version = {0.2.0},
  doi = {10.5281/zenodo.10495365},
  url = {https://dieghernan.github.io/arcgeocoder/},
  abstract = {Lite interface for finding locations of addresses or businesses around the world using the ArcGIS REST API service <https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm>. Address text can be converted to location candidates and a location can be converted into an address. No API key required.},
}

References

Cambon, Jesse, Diego Hernangómez, Christopher Belanger, and Daniel Possenriede. 2021. “tidygeocoder: An R Package for Geocoding.” Journal of Open Source Software 6 (65): 3544. https://doi.org/10.21105/joss.03544.

Hernangómez, Diego. 2024. nominatimlite: Interface with Nominatim API Service (version 0.2.1). https://doi.org/10.5281/zenodo.5113195.

Metadata

Version

0.2.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows