Week 07 Assignment Task Overview

  1. Set up a R project for the R-Spatial section. (Completed in RStudio.)
  2. Read the NYC postal areas in Shapefiles into sf objects.
  3. Read and process the NYS health facilities spreadsheet data. Create sf objects from geographic coordinates.
  4. Read and process the NYS retail food stores data. Create sf objects from geographic coordinates for NYC.
  5. Use simple mapping method such as mapview with a basemap to verify the above datasets in terms of their geometry locations.
  6. Save the three sf objects in a RData file or in a single GeoPackage file/database.

Task 2:

Read NYC postal areas in Shapefiles into sf objects

nycPostal_sf <- st_read("data/nyc/nyc_acs_tracts.shp")
## Reading layer `nyc_acs_tracts' from data source 
##   `/Users/ellabayer/Documents/Hunter College/DataVisR/R-spatial/data/nyc/nyc_acs_tracts.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 2166 features and 113 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -74.25559 ymin: 40.49612 xmax: -73.70001 ymax: 40.91553
## Geodetic CRS:  NAD83

Task 3:

Read and process NYS health facilities spreadsheet data. Create sf objects from geographic coordinates.

nysHealthFac <- read.csv("./R-Spatial_I_Lab/NYS_Health_Facility.csv", stringsAsFactors = FALSE)

nysHealthFac %>%
  tidyr::drop_na("Facility.Longitude", "Facility.Latitude") %>%
  sf::st_as_sf(coords = c("Facility.Longitude", "Facility.Latitude")) %>%
  st_set_crs(4326) -> nysHealthFac_sf

Task 4:

Read and process NYS retail food stores data. Create sf objects from geographic coordinates for NYC.

nysRetailFood <- read.csv("./R-Spatial_I_Lab/NYS_Retail_Food_Stores.csv", stringsAsFactors = FALSE)

nysRetailFood %>%
  dplyr::filter(County == c('Bronx', 'Kings', 'New York', 'Queens', 'Richmond') ) %>% 
  tidyr::extract(Location, into = c('Lat', 'Long'), regex = "(\\d+.\\d+),[ ]*([-]\\d+.\\d+)") %>%
  dplyr::mutate(Lat = as.numeric(Lat), Long = as.numeric(Long)) %>%
  tidyr::drop_na(Lat, Long) %>%
  sf::st_as_sf(coords = c('Long', 'Lat')) %>%
  st_set_crs(4326) -> nysRetailFoodNYC_sf
## Warning: There was 1 warning in `dplyr::filter()`.
## ℹ In argument: `County == c("Bronx", "Kings", "New York", "Queens",
##   "Richmond")`.
## Caused by warning in `County == c("Bronx", "Kings", "New York", "Queens", "Richmond")`:
## ! longer object length is not a multiple of shorter object length

Task 5:

Use simple mapping method such as mapview with a basemap to Verify the above datasets in terms of their geometry locations

NYC Postal Areas
mapview(nycPostal_sf)
NYS Health Facilities Spreadsheet Data
mapview(nysHealthFac_sf)
Retail Food Stores in NYC
mapview(nysRetailFoodNYC_sf)

Task 6:

Save the three sf objects in a RData file or in a single GeoPackage file/database.

# Save data to RData file
save(nycPostal_sf, nysHealthFac_sf, nysRetailFoodNYC_sf,  
     file = './data/nyc/RSpatial_Week07.RData')