Turf.jsHelper

turf.multiLineString

What is turf.multiLineString?

turf.multiLineString wraps an array of LineString coordinate arrays into a valid Feature<MultiLineString>. It is the correct constructor when a single logical feature consists of several disconnected line segments.

JavaScript
turf.multiLineString(coordinates, properties?, options?) → Feature<MultiLineString>

Options include:

  • bbox — bounding box [minX, minY, maxX, maxY]
  • id — identifier for the feature

When would you use turf.multiLineString?

Use turf.multiLineString for features whose geometry is intrinsically multipart — a river with a dammed middle section, a metro line with several disjoint branches under one route_id, or the union of several LineStrings returned by turf.lineIntersect that you want to keep under one record.

It is also the output type of several Turf transformations (for example the result of turf.isolines). Use it when the parts share a single set of properties; otherwise prefer a FeatureCollection of individual LineStrings.

JavaScript
1const highway = turf.multiLineString(
2  [
3    [[-122.42, 37.77], [-122.41, 37.78]],
4    [[-122.40, 37.80], [-122.39, 37.81]]
5  ],
6  { route: 'I-280' }
7);

FAQs

How do I install Turf.js to use this function?

Install the helpers package: npm install @turf/helpers, then import { multiLineString } from '@turf/helpers'. The full @turf/turf bundle also exposes it.

What is the coordinate nesting depth?

Three levels: an array of LineStrings (array of positions). Each position is [lng, lat]. The outer array can contain any number of inner LineStrings.

Should I use MultiLineString or a FeatureCollection of LineStrings?

Use MultiLineString when the parts belong to one logical feature with shared properties (one route_id). Use a FeatureCollection when each segment needs its own properties — many GIS tools also visualise individual features more predictably.

Can I turn a MultiLineString back into separate LineStrings?

Yes, pass it to turf.flatten. Each sub-LineString becomes its own Feature in the resulting FeatureCollection, inheriting the parent's properties.