gpt4 book ai didi

r - 导入包含空间数据的 CSV

转载 作者:行者123 更新时间:2023-12-05 02:25:45 26 4
gpt4 key购买 nike

我正在尝试从 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(longitude, latitude) 格式,例如“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

有什么想法吗?

最佳答案

我认为问题是您在 geocoded_hospital_address 中有 NA。删除它们将解决您的问题。

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")

关于r - 导入包含空间数据的 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74354924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com