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)
address<-read.csv("https://raw.githubusercontent.com/jkwolf21/2023-DEM-5093-7093/main/Code/wic_west_side.csv") #Note this is the RAW data* 
head(address)
address<-address[c(6, 12:14)]
names(address)<-c("street", "city", "st", "zip")
head(address)
library(censusxy)
Wresults<-cxy_geocode(address,
                     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.

Map Info:R MAP IS TO BE SHOWN IN MAPVIEW WHICH CURRENTLY DOESN’T ALLOW FOR TITLES, ETC. In your R Markdown, add the following in the text before the chunk of code for the map: Title Name Data Source

#Title: WIC Services Locations
#Name: Jules Gonzalez
#Data Source: A to Z Database
#AtoZdatabases. (n.d.). AtoZ Databases. UTSA Libraries. https://www-atozdatabases-com.libweb.lib.utsa.edu/search

Basic interactive map of the points

library(mapview)
mapview(Wresults, 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="/Users/juliegonzalez/Library/CloudStorage/OneDrive-UniversityofTexasatSanAntonio/Spring 2023 GIS", layer="westside_wic", driver = "ESRI Shapefile",delete_layer = T, append=T)

Longitude and Latitude

From Dr. Sparks’ RPubs

library(sf)
library(dplyr)
latlong<-read.csv(url("https://raw.githubusercontent.com/jkwolf21/2023-DEM-5093-7093/main/Code/wic_west_side.csv"))
resultsWIC <- st_as_sf(latlong, coords=c("Longitude", "Latitude"), crs=4269,agr="constant")
resultsWIC.proj<-st_transform(resultsWIC,
                           crs = 2278)

Map Info:R MAP IS TO BE SHOWN IN MAPVIEW WHICH CURRENTLY DOESN’T ALLOW FOR TITLES, ETC. In your R Markdown, add the following in the text before the chunk of code for the map: Title Name Data Source

#Title: WIC Services Locations
#Name: Jules Gonzalez
#Data Source: A to Z Database
#AtoZdatabases. (n.d.). AtoZ Databases. UTSA Libraries. https://www-atozdatabases-com.libweb.lib.utsa.edu/search
mapview(resultsWIC.proj)

Now repeat the same steps but geocoding grocery stores.

Read in the data for Groceries from AtoZ Database

library(readr)
library(data.table)
food<-read.csv("/Users/juliegonzalez/Library/CloudStorage/OneDrive-UniversityofTexasatSanAntonio/Spring 2023/groceries.csv")
head(food)
food<-food[c(6, 12:14)]
names(food)<-c("street", "city", "st", "zip")
head(food)
library(censusxy)
results<-cxy_geocode(food,
                     street = "street",
                     city = "city",
                     state ="st",
                     zip = "zip",
                     class="sf",
                     output = "simple")
## 4 rows removed to create an sf object. These were addresses that the geocoder could not match.

Map Info:R MAP IS TO BE SHOWN IN MAPVIEW WHICH CURRENTLY DOESN’T ALLOW FOR TITLES, ETC. In your R Markdown, add the following in the text before the chunk of code for the map: Title Name Data Source

#Title: Grocery Locations
#Name: Jules Gonzalez
#Data Source: A to Z Database
#AtoZdatabases. (n.d.). AtoZ Databases. UTSA Libraries. https://www-atozdatabases-com.libweb.lib.utsa.edu/search

Basic Interactive map of the points

library(mapview)
mapview(results, layer.name="Grocery Locations")

We can write the results out to a shapefile now

library(sf)
st_write(results,dsn="/Users/juliegonzalez/Library/CloudStorage/OneDrive-UniversityofTexasatSanAntonio/Spring 2023 GIS", layer="groceries layer", driver = "ESRI Shapefile",delete_layer = T, append=T)

Longitude and Latitude

From Dr. Sparks’ RPubs

library(sf)
library(dplyr)
latlongg<-read.csv("/Users/juliegonzalez/Library/CloudStorage/OneDrive-UniversityofTexasatSanAntonio/Spring 2023/groceries.csv")
resultsGROCERIES <- st_as_sf(latlong, coords=c("Longitude", "Latitude"), crs=4269,agr="constant")
resultsGROCERIES.proj<-st_transform(resultsWIC,
                           crs = 2278)

Map Info:R MAP IS TO BE SHOWN IN MAPVIEW WHICH CURRENTLY DOESN’T ALLOW FOR TITLES, ETC. In your R Markdown, add the following in the text before the chunk of code for the map: Title,Name,Data Source

#Title: WIC Services Locations
#Name: Jules Gonzalez
#Data Source: A to Z Database
#AtoZdatabases. (2023). AtoZ Databases. UTSA Libraries. https://www-atozdatabases-com.libweb.lib.utsa.edu/search
mapview(resultsGROCERIES.proj)

Extra Credit

mapview(list(Wresults, resultsWIC.proj,results,resultsGROCERIES.proj),
        layer.name = c("WIC Locations", "WIC LL", "Grocery Stores", "Grocery StoresLL"), col.regions=list("brown","black", "blue", "red"),col=list("brown","black", "blue", "red"))