R Spatial Lab Assignment # 1
Task 2:
nyc_zip_sf <- st_read("C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source
## `C:\Users\rsaya\Downloads\GEOG 39300\Section_3\Lecture_7\Data\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)
Task 3:
nys_health <- read_csv("C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/NYS_Health_Facility.csv",
show_col_types = FALSE) %>%
clean_names()
nys_health_cleaned <- nys_health %>%
filter(!is.na(facility_latitude) & !is.na(facility_longitude)
& (facility_latitude > 0 & facility_longitude != 0))
nys_health_sf <- st_as_sf(nys_health_cleaned,
coords = c("facility_longitude",
"facility_latitude"), crs = 4326)
nys_health_sf
## Simple feature collection with 3843 features and 34 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -79.6299 ymin: 40.51677 xmax: -72.17 ymax: 44.97849
## Geodetic CRS: WGS 84
## # A tibble: 3,843 × 35
## facility_id facility_name short_description description facility_open_date
## * <dbl> <chr> <chr> <chr> <chr>
## 1 204 Hospice at Lour… HSPC Hospice 06/01/1985
## 2 620 Charles T Sitri… NH Residentia… 02/01/1989
## 3 1156 East Side Nursi… NH Residentia… 08/01/1979
## 4 2589 Wellsville Mano… NH Residentia… 02/01/1989
## 5 3455 Harris Hill Nur… NH Residentia… 04/08/1992
## 6 3853 Garden City Sur… DTC Diagnostic… 04/07/2008
## 7 4249 Willcare CHHA Certified … 05/15/1990
## 8 4473 Good Shepherd H… HSPC Hospice 09/01/2002
## 9 6230 NYU Langone Rut… HOSP-EC Hospital E… 01/01/2006
## 10 6482 Endoscopy Cente… DTC Diagnostic… 01/20/2003
## # ℹ 3,833 more rows
## # ℹ 30 more variables: facility_address_1 <chr>, facility_address_2 <chr>,
## # facility_city <chr>, facility_state <chr>, facility_zip_code <chr>,
## # facility_phone_number <dbl>, facility_fax_number <dbl>,
## # facility_website <chr>, facility_county_code <dbl>, facility_county <chr>,
## # regional_office_id <dbl>, regional_office <chr>, main_site_name <chr>,
## # main_site_facility_id <dbl>, operating_certificate_number <chr>, …
Task 4:
nys_retail <- read_csv("C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/nys_retail_food_store_xy.csv",
show_col_types = FALSE) %>%
clean_names()
nys_retail_cleaned <- drop_na(nys_retail, "x", "y") %>%
filter(county %in% c("Bronx", "Kings", "New York", "Queens", "Richmond"))
nyc_retail_sf <- st_as_sf(nys_retail_cleaned, coords = c("x", "y"))
st_crs(nyc_retail_sf) <- 4326
nyc_retail_sf
## Simple feature collection with 11300 features and 16 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -74.2484 ymin: 40.50782 xmax: -73.67061 ymax: 40.91008
## Geodetic CRS: WGS 84
## # A tibble: 11,300 × 17
## county license_number operation_type establishment_type entity_name dba_name
## * <chr> <dbl> <chr> <chr> <chr> <chr>
## 1 Bronx 734149 Store JAC 7 ELEVEN FO… <NA>
## 2 Bronx 606221 Store JAC 1001 SAN MI… 1001 SA…
## 3 Bronx 606228 Store JAC 1029 FOOD P… 1029 FO…
## 4 Bronx 723375 Store JAC 1078 DELI G… 1078 DE…
## 5 Bronx 724807 Store JAC 1086 LUNA D… 1086 LU…
## 6 Bronx 712943 Store JAC 109 AJ DELI… 109 AJ …
## 7 Bronx 703060 Store JAC 10 NEIGHBOR… 10 NEIG…
## 8 Bronx 609065 Store JAC 1105 TINTON… 1105 TI…
## 9 Bronx 722972 Store A 1150 WEBSTE… 1150 WE…
## 10 Bronx 609621 Store JAC 1158 GROCER… 1158 GR…
## # ℹ 11,290 more rows
## # ℹ 11 more variables: street_number <chr>, street_name <chr>,
## # address_line_2 <lgl>, address_line_3 <lgl>, city <chr>, state <chr>,
## # zip_code <dbl>, square_footage <dbl>, location <chr>, coords <chr>,
## # geometry <POINT [°]>
Task 5:
nys_health_sf %>% dplyr::select("facility_id", "facility_name", "description", "facility_address_1", "facility_county") %>%
mapview::mapview()
Task 5:
nyc_retail_sf %>% dplyr::select("dba_name", "operation_type", "license_number", "location") %>%
mapview::mapview()
Task 6:
st_write(nyc_zip_sf,
dsn = 'C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/nyc/ny_data.gpkg',
layer= 'nyc_zip',
delete_layer = TRUE)
## Deleting layer `nyc_zip' using driver `GPKG'
## Writing layer `nyc_zip' to data source
## `C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/nyc/ny_data.gpkg' using driver `GPKG'
## Writing 263 features with 12 fields and geometry type Polygon.
st_write(nys_health_sf,
dsn = 'C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/nyc/ny_data.gpkg',
layer= 'nys_health',
delete_layer = TRUE)
## Deleting layer `nys_health' using driver `GPKG'
## Writing layer `nys_health' to data source
## `C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/nyc/ny_data.gpkg' using driver `GPKG'
## Writing 3843 features with 34 fields and geometry type Point.
st_write(nyc_retail_sf,
dsn = 'C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/nyc/ny_data.gpkg',
layer= 'nyc_retail',
delete_layer = TRUE)
## Deleting layer `nyc_retail' using driver `GPKG'
## Writing layer `nyc_retail' to data source
## `C:/Users/rsaya/Downloads/GEOG 39300/Section_3/Lecture_7/Data/nyc/ny_data.gpkg' using driver `GPKG'
## Writing 11300 features with 16 fields and geometry type Point.