简体   繁体   English

如何在 R 中溶解折线

[英]how to dissolve a polyline in R

I have a large polyline shapefile that needs to be dissolved.我有一个需要溶解的大型折线 shapefile。 However, the examples online only relate to polygons not polylines for example gUnaryUnion .但是,在线示例仅涉及多边形而不是折线,例如gUnaryUnion I am reading in my shapefile using st_read from the sf package.我正在使用sf st_read中的 st_read 读取我的 shapefile。 Any help would be appreciated.任何帮助,将不胜感激。

If I understand your question, one option is to use dplyr .如果我理解您的问题,一种选择是使用dplyr

library(sf)
library(dplyr)

# get polyline road data
temp_shapefile <- tempfile()
download.file("https://www2.census.gov/geo/tiger/TIGER2017//ROADS/tl_2017_06075_roads.zip", temp_shapefile)
temp_dir <- tempdir()
unzip(temp_shapefile, exdir = temp_dir)

sf_roads <- read_sf(file.path(temp_dir,'tl_2017_06075_roads.shp'))

Use the RTTYP field to reduce the polyline from ~4000 unique segments to 6 segments.使用 RTTYP 字段将折线从约 4000 个唯一段减少到 6 个段。

sf_roads_summarized <- sf_roads %>%
  group_by(RTTYP) %>%
  summarize()

I manged to achieve this by using st_combine .我设法通过使用st_combine来实现这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM