I am trying to convert spatial data from a CDC/HHS data on hospital strain, as downloadable from here:
https://healthdata.gov/Hospital/COVID-19-Reported-Patient-Impact-and-Hospital-Capa/anag-cw7u
Here's a snippet of the data:
hospital_name hospital_pk geocoded_hospital_address
TRIHEALTH EVENDALE HOSPITAL 360362 POINT (-84.420098 39.253934)
KANE COUNTY HOSPITAL 461309 POINT (-112.52859 37.054324)
CRAIG HOSPITAL 062011 POINT (-104.978247 39.654008)
For entry:
structure(list(hospital_name = c("TRIHEALTH EVENDALE HOSPITAL",
"KANE COUNTY HOSPITAL", "CRAIG HOSPITAL", "JAY HOSPITAL", "HARRISON COUNTY COMMUNITY HOSPITAL"
), geocoded_hospital_address = c("POINT (-84.420098 39.253934)",
"POINT (-112.52859 37.054324)", "POINT (-104.978247 39.654008)",
"POINT (-87.151673 30.950024)", "POINT (-94.025425 40.26528)"
)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"
))
I'm trying to import it as an CSV, transform it, and then turn it into a shapefile. The file has a field, termed geocoded_hospital_address, that I am trying to use to convert the dataset. It is in POINT(longitude, latitude) format e.g., "POINT (-100.01382, 37.441504)". I am used to using two variables (longitude/latitude) under the coords option, and I cannot get the "sf_column_name" option to work for me or decompose the field into two parts:
test_sf<-COVID_19_Reported_Patient_Impact_and_Hospital_Capacity_by_Facility%>%
+ st_as_sf(sf_column_name="geocoded_hospital_address", crs=4326)
Error in st_sf(x, ..., agr = agr, sf_column_name = sf_column_name) :
no simple features geometry column present
Any ideas?
I think the problem is you have NA in geocoded_hospital_address
. Remove them will fix your problem.
library(sf)
df_0 <- COVID_19_Reported_Patient_Impact_and_Hospital_Capacity_by_Facility %>%
filter(!is.na(geocoded_hospital_address))
test_sf = st_as_sf(df_0,crs=4326, wkt = "geocoded_hospital_address")