TransWikia.com

How to "split" a single MULTILINESTRING into multiple MULTILINESTRINGs that intersect?

Geographic Information Systems Asked by Daniel Ferreira on February 12, 2021

I’m trying to solve this problem using the R sf package, but I assume that an answer in PostGIS could also help me get to an answer in R.

Basically, I have a shapefile with the following columns: "Census area", "Street Name", and a MULTILINESTRING that represents the street segment within that "Census area" spatially. Usually, streets are straight lines that run across multiple "census areas", so I want to get rid of the "Census area" part and just collapse these "mini-street-segments" within Census areas into a single MULTILINESTRING for every single street.

In a world where there were no street name duplicates, this would be trivial. I’d just get all geometries that have the same street names and dissolve them into a single LINESTRING or MULTILINESTRING. In R sf/dplyr syntax:

df %>% group_by(street_name) %>% summarize()

However, we do have duplicate street names. We may have:

  • A street named C Street that crosses contiguous census areas 1, 2 and 3. This C Street could trivially be joined into a single, continuous MULTILINESTRING.
  • Another street also named C Street that crosses contiguous census areas 11, 12 and 13. This C Street could also trivially be joined into a single, continuous MULTILINESTRING.
  • But if I try joining ALL geometries that form C Street into a single MULTILINESTRING, we’d get a MULTILINESTRING with two line segments that don’t intersect.

What I want to do is separate such a "non-contiguous" MULTILINESTRING into two or more MULTILINESTRINGS that represent the two or more C streets. How should I go about that?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP