我目前有CSV中的数据,其中有一列名为"Journeyroute"的数据.此列包含以下数据[因大小而被截断]:
{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-4.095772, 50.409393]}, "properties": {"name": "start"}}, {"type": "Feature", "geometry": null, "properties": {"name": "end"}}, {"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-4.095772, 50.409393], [-4.095781, 50.409397], [-4.095792, 50.409401], [-4.095965, 50.40971], [-4.096064, 50.410069], [-4.09597, 50.410397]]}, "properties": {"distance": 4027.4, "name": "Raw", "times": [1690900467000, 1690900520000, 1690900522000, 1690900539000, 1690900550000, 1690900569000], "duration": 4923.0}}]}
有5,000行数据.我想要做的是提取线串数据以在R中使用,但我遇到了困难.有谁能帮帮忙吗?
我try 转换为JSON,然后取消嵌套,但出现了一个错误(代码改编自使用Google Earth引擎的其他答案):
new_df <- df %>%
mutate(geo = map(Journey.Route, ~ jsonlite::fromJSON(.))) %>%
as.data.frame() %>%
unnest(geo) %>%
filter(geo != "FeatureCollection") %>%
mutate(coord = rep(c("x", "y"))) %>%
pivot_wider(names_from = coord, values_from = coordinates)
Error in `mutate()`:
ℹ In argument: `coord = rep(c("x", "y"))`.
Caused by error:
! `coord` must be size 5000 or 1, not 2.
Run `rlang::last_trace()` to see where the error occurred.
应为线串坐标的SF几何列.