R Spatial Lab Assignment # 1
task 1: Postal Codes into sf Objects
ZIP_sf <- st_read("~/R-Spatial/R-Spatial_I_Lab/ZIP_CODE_040114/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source
## `/Users/mariaosorio/R-Spatial/R-Spatial_I_Lab/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)
task 2: NYS Health Facilities Data into sf Objects
#Read Data
NYS_health_facility_df <- read_csv("~/R-Spatial/R-Spatial_I_Lab/NYS_Health_Facility.csv")
## Rows: 3990 Columns: 36
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (28): Facility Name, Short Description, Description, Facility Open Date,...
## dbl (8): Facility ID, Facility Phone Number, Facility Fax Number, Facility ...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Remove missing values and set range for coordinates (There were two points in another continent)
NYS_health_facility_sf <- NYS_health_facility_df %>%
filter(!is.na(`Facility Longitude`) & !is.na(`Facility Latitude`)) %>%
filter(
`Facility Longitude` >= -80,
`Facility Longitude` <= -71,
`Facility Latitude` >= 40,
`Facility Latitude` <= 46
) %>%
st_as_sf(coords = c("Facility Longitude", "Facility Latitude"), crs = 4326)
str(NYS_health_facility_sf)
## sf [3,843 × 35] (S3: sf/tbl_df/tbl/data.frame)
## $ Facility ID : num [1:3843] 204 620 1156 2589 3455 ...
## $ Facility Name : chr [1:3843] "Hospice at Lourdes" "Charles T Sitrin Health Care Center Inc" "East Side Nursing Home" "Wellsville Manor Care Center" ...
## $ Short Description : chr [1:3843] "HSPC" "NH" "NH" "NH" ...
## $ Description : chr [1:3843] "Hospice" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" ...
## $ Facility Open Date : chr [1:3843] "06/01/1985" "02/01/1989" "08/01/1979" "02/01/1989" ...
## $ Facility Address 1 : chr [1:3843] "4102 Old Vestal Road" "2050 Tilden Avenue" "62 Prospect St" "4192A Bolivar Road" ...
## $ Facility Address 2 : chr [1:3843] NA NA NA NA ...
## $ Facility City : chr [1:3843] "Vestal" "New Hartford" "Warsaw" "Wellsville" ...
## $ Facility State : chr [1:3843] "New York" "New York" "New York" "New York" ...
## $ Facility Zip Code : chr [1:3843] "13850" "13413" "14569" "14895" ...
## $ Facility Phone Number : num [1:3843] 6.08e+09 3.16e+09 5.86e+09 5.86e+09 7.17e+09 ...
## $ Facility Fax Number : num [1:3843] NA NA NA NA NA ...
## $ Facility Website : chr [1:3843] NA NA NA NA ...
## $ Facility County Code : num [1:3843] 3 32 60 2 14 ...
## $ Facility County : chr [1:3843] "Broome" "Oneida" "Wyoming" "Allegany" ...
## $ Regional Office ID : num [1:3843] 3 3 1 1 1 7 1 7 5 7 ...
## $ Regional Office : chr [1:3843] "Central New York Regional Office" "Central New York Regional Office" "Western Regional Office - Buffalo" "Western Regional Office - Buffalo" ...
## $ Main Site Name : chr [1:3843] NA NA NA NA ...
## $ Main Site Facility ID : num [1:3843] NA NA NA NA NA ...
## $ Operating Certificate Number: chr [1:3843] "0301501F" "3227304N" "6027303N" "0228305N" ...
## $ Operator Name : chr [1:3843] "Our Lady of Lourdes Memorial Hospital Inc" "Charles T Sitrin Health Care Center, Inc" "East Side Nursing Home Inc" "Wellsville Manor LLC" ...
## $ Operator Address 1 : chr [1:3843] "169 Riverside Drive" "Box 1000 Tilden Avenue" "62 Prospect Street" "4192a Bolivar Road" ...
## $ Operator Address 2 : chr [1:3843] NA NA NA NA ...
## $ Operator City : chr [1:3843] "Binghamton" "New Hartford" "Warsaw" "Wellsville" ...
## $ Operator State : chr [1:3843] "New York" "New York" "New York" "New York" ...
## $ Operator Zip Code : chr [1:3843] "13905" "13413" "14569" "14897" ...
## $ Cooperator Name : chr [1:3843] NA NA NA NA ...
## $ Cooperator Address : chr [1:3843] NA NA NA NA ...
## $ Cooperator Address 2 : chr [1:3843] NA NA NA NA ...
## $ Cooperator City : chr [1:3843] NA NA NA NA ...
## $ Cooperator State : chr [1:3843] "New York" "New York" "New York" "New York" ...
## $ Cooperator Zip Code : chr [1:3843] NA NA NA NA ...
## $ Ownership Type : chr [1:3843] "Not for Profit Corporation" "Not for Profit Corporation" "Business Corporation" "LLC" ...
## $ Facility Location : chr [1:3843] "(42.097095, -75.975243)" "(43.05497, -75.228828)" "(42.738979, -78.12867)" "(42.126461, -77.967834)" ...
## $ geometry :sfc_POINT of length 3843; first list element: 'XY' num [1:2] -76 42.1
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
## ..- attr(*, "names")= chr [1:34] "Facility ID" "Facility Name" "Short Description" "Description" ...
Task 3: NYS Retail Food Store Data into sf Objects
#Read Data
NYS_Retail_Food_df<- read_csv("~/R-Spatial/R-Spatial_I_Lab/NYS_Retail_Food_Stores.csv")
## Rows: 29389 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): County, License Number, Operation Type, Establishment Type, Entity...
## dbl (1): Zip Code
## num (1): Square Footage
## lgl (2): Address Line 2, Address Line 3
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Extract coordinates
NYS_Retail_Food_df <- NYS_Retail_Food_df %>%
filter(County %in% c("Bronx", "Kings", "New York", "Queens", "Richmond")) %>%
mutate(
Latitude = str_extract(Location, "(?<=\\()[-0-9.]+"),
Longitude = str_extract(Location, "(?<=, )[-0-9.]+(?=\\))"),
Latitude = as.numeric(Latitude),
Longitude = as.numeric(Longitude) )
#Remove missing Values and set coordinate system
NYS_Retail_Food_sf <- NYS_Retail_Food_df %>%
filter(!is.na(Longitude) & !is.na(Latitude)) %>%
st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326)
#Limit view to NYC
NYS_Retail_Food_sf <- st_transform(NYS_Retail_Food_sf, st_crs(ZIP_sf))
NYS_Retail_Food_sf <- st_filter(NYS_Retail_Food_sf, ZIP_sf)
Task 4: MAPVIEW
mapview(ZIP_sf, layer.name = "NYC ZIP Areas")
mapview(NYS_health_facility_sf, layer.name = "Health Facilities", col.regions = "red")