我正在嘗試從有關醫院壓力的 CDC/HHS 資料中轉換空間資料,可從此處下載:
https://healthdata.gov/Hospital/COVID-19-Reported-Patient-Impact-and-Hospital-Capa/anag-cw7u
這是資料的片段:
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)
進入:
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"
))
我正在嘗試將其作為 CSV 匯入,對其進行轉換,然后將其轉換為 shapefile。該檔案有一個名為 geocoded_hospital_address 的欄位,我試圖用它來轉換資料集。它采用 POINT(經度,緯度)格式,例如“POINT (-100.01382, 37.441504)”。我習慣于在 coords 選項下使用兩個變數(經度/緯度),我無法讓“sf_column_name”選項為我作業或將欄位分解為兩部分:
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
有任何想法嗎?
uj5u.com熱心網友回復:
我認為問題是你有 NAgeocoded_hospital_address. 洗掉它們將解決您的問題。
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")
uj5u.com熱心網友回復:
這是一個荒謬的解決方案,但這是我所擁有的最好的解決方案,因為 shapefile 不可下載。
library(tidyverse)
library(sf)
x <- read_csv('COVID-19_Reported_Patient_Impact_and_Hospital_Capacity_by_Facility.csv')
# alter geometry column to get just coordinates
# remove 'POINT', parentheses, and whitespace
x$coords <- x$geocoded_hospital_address %>%
str_remove('POINT') %>%
str_remove('\\(') %>%
str_remove('\\)') %>%
str_trim()
# remove NA coords, then separate 'coords' into x & y, transform to an 'sf' object
x_sf <- x %>%
filter(!is.na(coords)) %>%
separate(coords, into = c('x','y'), sep = ' ') %>%
st_as_sf(coords = c('x','y'))
head(x_sf)
#> Simple feature collection with 6 features and 128 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -108.616 ymin: 24.71104 xmax: -80.21099 ymax: 39.10636
#> CRS: NA
#> # A tibble: 6 × 129
#> hospital_pk collecti…1 state ccn hospi…2 address city zip hospi…3 fips_…?
#> <chr> <date> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 060054 2020-06-05 CO 0600… COMMUN… 2351 '… GRAN… 81505 Short … 08077
#> 2 100156 2020-06-19 FL 1001… HCA FL… 340 NW… LAKE… 32055 Short … 12023
#> 3 101312 2020-05-15 FL 1013… FISHER… 3301 O… MARA… 33050 Critic… 12087
#> 4 102001 2020-06-12 FL 1020… SELECT… 955 NW… MIAMI 33128 Long T… 12086
#> 5 102013 2020-06-26 FL 1020… KINDRE… 4801 N… TAMPA 33603 Long T… 12057
#> 6 102028 2020-05-01 FL 1020… SELECT… 5050 C… OXFO… 34484 Long T… 12119
#> # … with 119 more variables: is_metro_micro <lgl>, total_beds_7_day_avg <dbl>,
#> # all_adult_hospital_beds_7_day_avg <dbl>,
#> # all_adult_hospital_inpatient_beds_7_day_avg <dbl>,
#> # inpatient_beds_used_7_day_avg <dbl>,
#> # all_adult_hospital_inpatient_bed_occupied_7_day_avg <dbl>,
#> # inpatient_beds_used_covid_7_day_avg <dbl>,
#> # total_adult_patients_hospitalized_confirmed_and_suspected_covid_7_day_avg <dbl>, …
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/529055.html
標籤:r空间的科幻
