task 2: Read the NYC Postal Areas Shapefiles into sf objects.
nyc_zip <- st_read("C:/Users/clair/OneDrive/Documents/R_Spatial/Data/ZIP_CODE_040114/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source
## `C:\Users\clair\OneDrive\Documents\R_Spatial\Data\ZIP_CODE_040114\ZIP_CODE_040114.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 263 features and 12 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: 913129 ymin: 120020.9 xmax: 1067494 ymax: 272710.9
## Projected CRS: NAD83 / New York Long Island (ftUS)
nyc_zip %>% mapview ::mapview()
Task 3: Read and process the NYS health facities spreadsheet
data.
NYS_Health_Facility <- read.csv("C:/Users/clair/OneDrive/Documents/R_Spatial/Data/NYS_Health_Facility.csv")
NYS_Health_Facility <- NYS_Health_Facility %>%
filter(!is.na(`Facility.Longitude`), !is.na(`Facility.Latitude`))
NYS_Health_Facility_sf <- st_as_sf(NYS_Health_Facility, coords = c("Facility.Longitude", "Facility.Latitude"), crs = 4326)
mapview(head(NYS_Health_Facility_sf, n=30), zcol = "Facility.Location", layer.name = "Facility Location")
Task 4: Read and process the NYS retail food stores data
NYS_Retail_Food_Stores <-read_csv("C:/Users/clair/OneDrive/Documents/R_Spatial/Data/nys_retail_food_store_xy.csv",
show_col_types = FALSE,
lazy = FALSE)
NYS_Retail_Food_Clean <- NYS_Retail_Food_Stores %>% drop_na('Y') %>% drop_na('X')
NYS_Retail_Food_Stores_sf <- st_as_sf(NYS_Retail_Food_Clean, coords = c("X", "Y"), crs = 4326)
url = 'https://cbilicki.github.io/G38520/L7/'
knitr::include_url(url, height='450px')
Task 5: Save to gpkg
st_write(nyc_zip,
dsn = "./nyc_data.gpkg",
layer='nyc_zipcode',
delete_layer = T)
## Deleting layer `nyc_zipcode' using driver `GPKG'
## Writing layer `nyc_zipcode' to data source `./nyc_data.gpkg' using driver `GPKG'
## Writing 263 features with 12 fields and geometry type Polygon.
st_write(NYS_Health_Facility_sf,
dsn = "./nyc_data.gpkg",
layer='NYS_Health_Facilities',
delete_layer = T)
## Deleting layer `NYS_Health_Facilities' using driver `GPKG'
## Writing layer `NYS_Health_Facilities' to data source
## `./nyc_data.gpkg' using driver `GPKG'
## Writing 3848 features with 34 fields and geometry type Point.
st_write(NYS_Retail_Food_Stores_sf,
dsn = "./nyc_data.gpkg",
layer='NYS_Retail_Food',
delete_layer = T)
## Deleting layer `NYS_Retail_Food' using driver `GPKG'
## Writing layer `NYS_Retail_Food' to data source `./nyc_data.gpkg' using driver `GPKG'
## Writing 23972 features with 16 fields and geometry type Point.