【发布时间】:2020-01-05 21:26:54
【问题描述】:
以下是可重复使用的数据:
structure(list(countyfp10 = c(1, 1, 1, 1, 3, 3, 3, 3, 5, 5, 5,
5, 7, 7, 7, 7), id = c(7417, 7418, 7419, 7420, 7421, 7422, 7423,
7424, 7425, 7426, 7427, 7428, 7429, 7430, 7431, 7432), lat = c(39.4797245,
39.5544678, 39.4681687, 39.199806, 39.4017623, 39.3093943, 39.4272021,
39.5618129, 39.7934997, 39.4835134, 39.4989196, 39.4819145, 39.4727694,
39.4675515, 39.4693146, 39.4644503), long = c(-118.7908571, -118.8095638,
-118.8195712, -118.5429041, -118.754186, -118.8861865, -118.9729817,
-117.9418517, -118.9516281, -118.8487913, -119.0205114, -118.7695846,
-118.7938896, -118.76011, -118.7778707, -118.7902103)), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -16L), spec = structure(list(
cols = list(countyfp10 = structure(list(), class = c("collector_double",
"collector")), id = structure(list(), class = c("collector_double",
"collector")), lat = structure(list(), class = c("collector_double",
"collector")), long = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1), class = "col_spec"))
目前存储为data.frame,但我想将其转换为SpatialPolygonsDataFrame。最好的方法是什么?
【问题讨论】:
-
必须是
SpatialPolygonsDataFrame,还是可以是一个简单的特征对象(sf),是sp的继承者? -
而且,与其“打印”您的数据,不如使用
dput(df)的输出。这样我们都可以简单地复制和粘贴您的数据。 -
@SymbolixAU 谢谢,刚刚编辑。我猜它不需要是 SpatialPolygonsDataFrame,如果
sf完成同样的事情?只要可以被leaflet()函数读取
标签: r leaflet geospatial sp