DallasGeocodeR is an R package for interfacing with the City of Dallas's public geocoding services, a set of REST APIs powered by ArcGIS. The DallasGeocodeR package provides convenient wrapper functions for several key operations:

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

devtools::load_all()

Usage

Geocoding addresses

Let's begin by creating some sample addresses.

library(DallasGeocodeR)

addresses <- data.frame(
  street = c('8525 Garland Rd', '1500 Marilla St', '3809 Grand Avenue'),
  city = c('Dallas', 'Dallas', 'Dallas'),
  zip = c(75218, 75201, 75210)
)
addresses

From here, geocoding is a simple function call:

coords <- geocode_addresses(addresses$street, addresses$city, addresses$zip)
print(coords)

The function does not actually need the city and zip parameters to run. ArcGIS's API can geocode using street addresses alone.

geocode_addresses(addresses$street)

Note the #> [1] "Processing batch 1 of 1" line in both of the above examples. ArcGIS's geocoding API can only process 1000 addresses in a single request. The geocode_addresses function automatically breaks up addresses into batches of 1000, then submits requests to the API for each batch in succession.

Accuracy

Using the DallasAreaRoads Feature Server, we can plot our geocoded address coordinates onto a map of the city's major highways.

# remotes::install_github("yonghah/esri2sf")
library(esri2sf)
library(ggplot2)

url <- "https://services2.arcgis.com/rwnOSbfKSwyTBcwN/ArcGIS/rest/services/DallasAreaRoads/FeatureServer/0"
dallas <- esri2sf(url)
#> [1] "Feature Layer"
#> [1] "esriGeometryPolyline"
#> [1] "Coordinate Reference System: 2276"

ggplot() +
  geom_sf(data = dallas) +  # Dallas map layer
  geom_point(data = coords,  # Overlay geocoded coordinates
             mapping = aes(x = longitude, y = latitude),
             color = "red") +
  coord_sf()

{width=99%}

Reverse geocoding

With the reverse_geocode function, the API can find street addresses and intersections from a given set of coordinates.

reverse_geocode(coords$latitude, coords$longitude)

reverse_geocode(coords$latitude, coords$longitude, intersection = T)

Finding address candidates

The find_address_candidates function takes in a single address as input and returns a list of likely City of Dallas addresses, ordered by matching score.

find_address_candidates(addresses$street)


log-linear/DallasGeocodeR documentation built on Dec. 21, 2021, 11:45 a.m.