#1. Creating data from AtoZ database.
#2.Using dataset geocoding in R
#Step1: Downloaded WIC services and grocery stores zipcodes from AtoZ database which was accesed trough UTSA library.Then Used Naic code 445110 for the grocery store and downloaded results into csv file format to load here. And I used three zip codes, 78201, 78204, and 78207
#Step2: Sorted and deleted any row with missing physical address.
#Step3: Load the CSV file into R.
addr <- read.csv("C:/Users/sarah/Google Drive/MSc Demography/Spring 2020/GIS 5093/gis_class/Homework3/dem5093_wic&gstore.csv")
addr <- addr[c(6, 12:14)]
names(addr) <- c("street", "city", "st", "zip")
head(addr)
## street city st zip
## 1 6800 W Interstate 10 Ste 200 San Antonio TX 78201
## 2 4522 Fredericksburg Rd San Antonio TX 78201
## 3 8234 Agora Pkwy San Antonio TX 78201
## 4 3485 Fredericksburg Rd San Antonio TX 78201
## 5 1302 Gardina St San Antonio TX 78201
## 6 814 West Ave San Antonio TX 78201
#Step4: Creating map by censusxy
library(censusxy)
results <- cxy_geocode(addr, address=street, city=city, state=st, zip=zip, output="sf")
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 44 rows [1, 3, 5,
## 7, 9, 15, 16, 18, 23, 24, 25, 26, 27, 33, 34, 35, 36, 38, 41, 42, ...].
mapview::mapview(results, layer="WIC Services & Grocery Stores")
#Step5: save file
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
st_write(results, dsn="`/.", layer="WIC Services & Grocery Stores", driver="ESRI Shapefile", delete_layer = T, update = T)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Deleting layer `WIC Services & Grocery Stores' using driver `ESRI Shapefile'
## Updating layer `WIC Services & Grocery Stores' to data source ``/.' using driver `ESRI Shapefile'
## Writing 100 features with 7 fields and geometry type Point.
add <- read.csv("C:/Users/sarah/Google Drive/MSc Demography/Spring 2020/GIS 5093/gis_class/Homework3/dem5093_Gstore.csv")
add <- add[c(6, 12:14)]
names(add) <- c("street", "city", "st", "zip")
head(add)
## street city st zip
## 1 1545 S San Marcos San Antonio TX 78207
## 2 4522 Fredericksburg Rd San Antonio TX 78201
## 3 8234 Agora Pkwy San Antonio TX 78201
## 4 2902 Guadalupe St San Antonio TX 78207
## 5 1200 El Paso St San Antonio TX 78207
## 6 516 S Flores St San Antonio TX 78204
#Creating map by censusxy
library(censusxy)
results <- cxy_geocode(add, address=street, city=city, state=st, zip=zip, output="sf")
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 25 rows [1, 3, 5,
## 7, 9, 14, 18, 21, 22, 26, 27, 28, 29, 31, 34, 43, 45, 46, 50, 51, ...].
mapview::mapview(results, layer="Grocery Stores")
library(sf)
st_write(results, dsn="`/.", layer="Grocery Stores", driver="ESRI Shapefile", delete_layer = T, update = T)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Deleting layer `Grocery Stores' using driver `ESRI Shapefile'
## Updating layer `Grocery Stores' to data source ``/.' using driver `ESRI Shapefile'
## Writing 37 features with 7 fields and geometry type Point.
#Results: 59% of of the locations are geocoded.
addw <- read.csv("C:/Users/sarah/Google Drive/MSc Demography/Spring 2020/GIS 5093/gis_class/Homework3/Dem5093_WIC.csv")
addw <- addw[c(6, 12:14)]
names(addw) <- c("street", "city", "st", "zip")
head(addw)
## street city st zip
## 1 6800 W Interstate 10 Ste 200 San Antonio TX 78201
## 2 1410 Guadalupe St Ste 222 San Antonio TX 78207
## 3 527 N Leona St San Antonio TX 78207
## 4 1131 Babcock Rd Ste 125 San Antonio TX 78201
## 5 121 S Leona St San Antonio TX 78207
## 6 2903 W Salinas St San Antonio TX 78207
library(censusxy)
results <- cxy_geocode(addw, address=street, city=city, state=st, zip=zip, output="sf")
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 22 rows [3, 6, 8,
## 9, 13, 16, 22, 24, 27, 31, 33, 37, 38, 42, 43, 49, 50, 51, 54, 56, ...].
mapview::mapview(results, layer="WIC Services")
library(sf)
st_write(results, dsn="`/.", layer="WIC Services", driver="ESRI Shapefile", delete_layer = T, update = T)
## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Deleting layer `WIC Services' using driver `ESRI Shapefile'
## Updating layer `WIC Services' to data source ``/.' using driver `ESRI Shapefile'
## Writing 62 features with 7 fields and geometry type Point.
#Results: 61% of of the locations are geocoded.