*These are updates. Original version from Corey Sparks, Ph.D. can be found here.
install.packages("censusxy")
In this example, we will geocode addresses using the Census Bureau’s
batch geocoding service. The work will be done by the
censusxy package.
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.
library(mapview)
mapview(results, layer.name="WIC Services")
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)
From Dr. Sparks’ RPubs
library(sf)
library(dplyr)
addrLL<-read.csv(url("https://raw.githubusercontent.com/jkwolf21/2023-DEM-5093-7093/main/Code/wic_west_side.csv"))
resultsWIC <- st_as_sf(addrLL, coords=c("Longitude", "Latitude"), crs=4269,agr="constant")
resultsWIC.proj<-st_transform(resultsWIC,
crs = 2278)
mapview(resultsWIC.proj)