15  Geocoding

15.1 Call Libraries

Code
library(tidygeocoder) # geocoding

library(dplyr) # for %>% operator

library(readr) # import CSV

library(DT) # nice tables

15.2 Get Data To Be Geocoded

Code
simulated_address_data <- read_csv("simulated-address-data/simulated-address-data.csv")

DT::datatable(simulated_address_data,
              extensions = 'Buttons', 
              options = list(
                dom = 'Bfrtip',
                buttons = c('copy', 
                            'csv', 
                            'print'))) # nice table

15.3 Concatenate Addresses

Code
simulated_address_data$address <- paste(simulated_address_data$street,
                                        ", ",
                                        simulated_address_data$city,
                                        ", ",
                                        simulated_address_data$state)

DT::datatable(simulated_address_data,
              extensions = 'Buttons', 
              options = list(
                dom = 'Bfrtip',
                buttons = c('copy', 
                            'csv', 
                            'print'))) # nice table

15.4 Geocode

ArcGIS geocoding has LOW success rate with this data

You will want to find a process with HIGH success rate

You could also try batchgeo -> KML -> Latitude/Longitude

Code
geocoded_data <- simulated_address_data %>% 
  tidygeocoder::geocode(address, 
                        method = 'arcgis', 
                        lat = latitude, 
                        long = longitude)
Passing 3 addresses to the ArcGIS single address geocoder
Query completed in: 0.6 seconds
Code
DT::datatable(geocoded_data,
              extensions = 'Buttons', 
              options = list(
                dom = 'Bfrtip',
                buttons = c('copy', 
                            'csv', 
                            'print'))) # nice table
Geocoding Can Make Errors!

NB that for whatever reason, the geocoder has made a mistake: Agency Z has been placed in the Southern Hemisphere. Geocoding can be an error prone process and requires careful inspection of your tabular and mapped data.

A geocoder may also be unable to geocode some of your data. Low success rates are not uncommon, and you may have to work hard to ensure that the majority, or all, of your data are geocoded.

Geocoded data can then be mapped using procedures outlined in Section 14.1.