DFinch
DFinch

Reputation: 139

how to dissolve a polyline in R

I have a large polyline shapefile that needs to be dissolved. However, the examples online only relate to polygons not polylines for example gUnaryUnion. I am reading in my shapefile using st_read from the sf package. Any help would be appreciated.

Upvotes: 1

Views: 977

Answers (2)

DFinch
DFinch

Reputation: 139

I manged to achieve this by using st_combine.

Upvotes: 0

nniloc
nniloc

Reputation: 4243

If I understand your question, one option is to use 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.

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

Upvotes: 1

Related Questions