2

Is it possible to use shapely or some other Python software to merge a LineString with a MultiLineString?

Shapely's ops.linemerge fails here.

I am attempting to merge segments of the same road, represented in different rows of the NYC streets dataset, some as LineStrings and others as MultiLineStrings. Specifically, I am using the DCM_StreetCenterLine from: https://www1.nyc.gov/site/planning/data-maps/open-data/dwn-digital-city-map.page

2 Answers 2

2

The shapely manual seems to suggest that you can merge LineString and MultiLineString. An approach that may work (untested) is to explode the MultiLinestring into its constituent LineStrings, you then run the merge on just all Linestrings? How to explode a MultiLineString is discussed in several ways in this Q&A.

0

An approach that works for me, based on the answer of @hornbydd, is:

merged = MultiLineString([linestring for linestring in multilinestring.geoms] + [candidate])

…where candidate is a LineString.

But, it feels wrong to write a list-comprehension when I just want to something like:

newmultilinestring = oldmultilinestring + candidate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.