【问题标题】:Dissolving lines in SFSF中的溶解线
【发布时间】:2020-08-04 21:28:01
【问题描述】:

有什么办法可以在 SF 中按某列解散行吗?这在 QGIS 或 ArcGIS 中是如此简单的任务。我已经尝试了下面的代码,但它同时创建了线串和多线串类型。我想把它归结为 rgrass7 的 writeVECT 步骤。但是,我使用下面的代码没有成功。

图书馆(tidyverse) 库(osmdata) 图书馆(旧金山) 图书馆(rgrass7)

muenster <- opq(bbox =  c(7.61, 51.954, 7.636, 51.968)) %>% 
  add_osm_feature(key = 'highway') %>% 
  osmdata_sf() %>% 
  osm_poly2line()

#muenster_center <- muenster$osm_lines %>% 
#  select(highway)

muenster_center <- roads$osm_lines %>% 
  select(highway, geometry)

muenster_center <- (st_cast(st_cast(muenster_center, "MULTILINESTRING"),"LINESTRING"))

muenster_center <- muenster_center %>% 
  group_by(highway) %>% 
  summarize(geometry = st_union(geometry))

muenster_center

writeVECT(
  SDF = muenster_center, 
  vname = 'muenster_center', 
  v.in.ogr_flags = 'overwrite'
)

【问题讨论】:

  • 在示例中,只有一种公路类别是线串,这是因为它只有一个特征。它会阻止你做你想做的事情吗?
  • 是的,我会更新
  • 是的,但问题是什么?它在writeVECT 函数中吗?你能用st_write代替吗?

标签: r sf grass


【解决方案1】:
library(tidyverse)
library(osmdata)
library(sf)

roads <- opq(bbox =  c(7.61, 51.954, 7.636, 51.968)) %>% 
  add_osm_feature(key = 'highway') %>% 
  osmdata_sf() %>% 
  osm_poly2line()

roads <- roads$osm_lines %>% 
  select(highway, geometry)

roads.out <- roads %>% 
  group_by(highway) %>% 
  summarize(geometry = st_union(geometry))

roads.out

Simple feature collection with 15 features and 1 field
geometry type:  GEOMETRY
dimension:      XY
bbox:           xmin: 7.603762 ymin: 51.94823 xmax: 7.641418 ymax: 51.97241
geographic CRS: WGS 84
# A tibble: 15 x 2
   highway                                                                                                    geometry
   <chr>                                                                                                <GEOMETRY [°]>
 1 corridor                                                          LINESTRING (7.620506 51.96262, 7.620577 51.96269)
 2 cycleway       MULTILINESTRING ((7.61525 51.96736, 7.615165 51.96744, 7.615148 51.96745), (7.634265 51.96084, 7....
 3 footway        MULTILINESTRING ((7.628247 51.96557, 7.628331 51.96564, 7.628421 51.96573, 7.628483 51.9658, 7.62...
 4 path           MULTILINESTRING ((7.613703 51.96041, 7.613721 51.96046, 7.613766 51.96048, 7.614 51.96051, 7.6141...
 5 pedestrian     MULTILINESTRING ((7.634264 51.95679, 7.634123 51.95682, 7.633995 51.95685), (7.628404 51.96261, 7...
 6 residential    MULTILINESTRING ((7.630898 51.95573, 7.63084 51.95567, 7.63048 51.95524), (7.63048 51.95524, 7.63...
 7 secondary      MULTILINESTRING ((7.624554 51.95561, 7.624838 51.95562, 7.624961 51.95563, 7.625074 51.95564, 7.6...
 8 secondary_link MULTILINESTRING ((7.617578 51.96654, 7.617345 51.96655, 7.617244 51.96655, 7.617111 51.96655, 7.6...
 9 service        MULTILINESTRING ((7.63275 51.9603, 7.631843 51.96061), (7.629093 51.96529, 7.628891 51.96537, 7.6...
10 steps          MULTILINESTRING ((7.627696 51.96534, 7.62765 51.96534), (7.618848 51.95797, 7.618832 51.95801, 7....
11 tertiary       MULTILINESTRING ((7.616402 51.95762, 7.616983 51.95756, 7.617798 51.95748, 7.618428 51.95743, 7.6...
12 tertiary_link  LINESTRING (7.623719 51.96629, 7.623699 51.96623, 7.623664 51.96617, 7.623629 51.96614, 7.623592 ...
13 track          MULTILINESTRING ((7.613738 51.96494, 7.61359 51.96493, 7.613383 51.96491, 7.613148 51.96484, 7.61...
14 unclassified   MULTILINESTRING ((7.631481 51.95742, 7.631599 51.95738), (7.633004 51.9605, 7.633471 51.96026, 7....
15 NA             MULTILINESTRING ((7.634316 51.95678, 7.634236 51.95668, 7.634184 51.95662, 7.633811 51.95632, 7.6...

还有一个情节:

plot(roads.out["highway"])

【讨论】:

    猜你喜欢
    • 2021-09-26
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-21
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多