Линии растворения в SF - PullRequest
       92

Линии растворения в SF

0 голосов
/ 05 августа 2020

Есть ли способ слить строки по определенному столбцу в SF? Это такая простая задача в QGIS или ArcGIS. Я пробовал приведенный ниже код, но он создает как строковые, так и многострочные типы. Я хочу свести это к шагу writeVECT из rgrass7. Однако мне не удалось выполнить приведенный ниже код.

библиотека (tidyverse) библиотека (osmdata) библиотека (sf) библиотека (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'
)

1 Ответ

0 голосов
/ 05 августа 2020
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"])

введите описание изображения здесь

...