r - R osmdata:获取 other_tags 作为列
问题描述
我想使用 osmdata 并将 other_tags 作为显式列。
示例代码:
library(osmextract)
library(osmdata)
itsleeds = oe_get("ITS Leeds")
oe_get_keys(itsleeds)
我有兴趣从 itsleeds 数据中提取 other_tags col。
谢谢你。
解决方案
我们可以使用 tidyverse 方法将“other_tags”列拆分并重塑为两列 -select
感兴趣的列,separate_rows
通过在 处拆分来扩展数据,
,用于separate
从“other_tags”创建两列“key”、“value”,通过在这些列中拆分=>
并最终删除双引号str_remove_all
library(osmextract)
library(osmdata)
library(dplyr)
library(tidyr)
library(stringr)
itsleeds %>%
select(other_tags) %>%
separate_rows(other_tags, sep=",") %>%
separate(other_tags, into = c("key", "value"), sep="=>") %>%
mutate(across(c(key, value), str_remove_all, '"'))
-输出
Simple feature collection with 297 features and 2 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: -1.562458 ymin: 53.80471 xmax: -1.548076 ymax: 53.81105
Geodetic CRS: WGS 84
# A tibble: 297 x 3
key value geometry
* <chr> <chr> <LINESTRING [°]>
1 <NA> <NA> (-1.560083 53.80855, -1.560152 53.80865, -1.560228 53.80878, -1.560672 53.80962, -1.56...
2 bicycle designated (-1.559709 53.80815, -1.559756 53.80813, -1.559842 53.80812, -1.559919 53.80814, -1.55...
3 foot designated (-1.559709 53.80815, -1.559756 53.80813, -1.559842 53.80812, -1.559919 53.80814, -1.55...
4 website http://woodhousemooronline.com/the-cannon-destroyer/ (-1.5609 53.80851, -1.560663 53.80859, -1.560228 53.80878, -1.560025 53.80903, -1.5599...
5 access permissive (-1.552587 53.80712, -1.552541 53.8072, -1.55251 53.80725, -1.552479 53.8073, -1.55241...
6 lanes 1 (-1.552587 53.80712, -1.552541 53.8072, -1.55251 53.80725, -1.552479 53.8073, -1.55241...
7 oneway yes (-1.552587 53.80712, -1.552541 53.8072, -1.55251 53.80725, -1.552479 53.8073, -1.55241...
8 lanes 1 (-1.551771 53.8073, -1.551929 53.80727, -1.552007 53.80727, -1.552181 53.80728, -1.552...
9 oneway yes (-1.551771 53.8073, -1.551929 53.80727, -1.552007 53.80727, -1.552181 53.80728, -1.552...
10 lanes 2 (-1.552894 53.809, -1.552663 53.8089, -1.55246 53.80881, -1.552261 53.8087)
# … with 287 more rows
推荐阅读
- ios - 私人钥匙串商店
- python-3.x - Python3 Web 自动化错误 - ElementNotInteractableException:消息:元素不可交互
- php - 忽略特定的 css
- security - Veracode 有哪些非常好的和实用的替代方案
- c# - MVC 空路由 ID 将我带到 spa(angular) 而不是返回错误请求
- python - 在 Python 中为值列表执行函数
- python - Pytesseract 无法读取简单数字
- javascript - 避免 Angular 中的多个服务实例
- javascript - 如何在 jquery 中使用蛋糕元素?
- exchange-server - Exchange Online:如何通过别名而不是显示名称获取 ManagedBy 属性