*These are updates. Original version from Corey Sparks, Ph.D. can be found here.

install.packages("censusxy")

Setup

In this example, we will geocode addresses using the Census Bureau’s batch geocoding service. The work will be done by the censusxy package.

Read in the address data

We will use the from the CSV created in the Lab 3 exercise.

library(readr)
library(data.table)
addr<-read.csv("https://raw.githubusercontent.com/jkwolf21/2023-DEM-5093-7093/main/Code/wic_west_side.csv") #Note this is the RAW data* 
head(addr)
addr<-addr[c(6, 12:14)]
names(addr)<-c("street", "city", "st", "zip")
head(addr)
library(censusxy)
results<-cxy_geocode(addr,
                     street = "street",
                     city = "city",
                     state ="st",
                     zip = "zip",
                     class="sf",
                     output = "simple")
## 5 rows removed to create an sf object. These were addresses that the geocoder could not match.

Basic interactive map of the points

library(mapview)
mapview(results, layer.name="WIC Services")

Save the results if you want

We can write the results out to a shapefile now

library(sf)
st_write(results,dsn="C:/Users/.../GIS Class/Lab 3", layer="westside_wic", driver = "ESRI Shapefile",delete_layer = T, append=T)