Turf: Along doesn't work with MultiLineString

Created on 19 May 2019  路  6Comments  路  Source: Turfjs/turf

Please provide the following when reporting an issue:

  • [x] GeoJSON data as a gist file or geojson.io (filename extension must be .geojson).
  • [x] Snippet of source code or for complex examples use jsfiddle.

Hi guys, thx for your awesome work!

I'd like to ask if you are planning to add MultiLineString support to turf.along()?

Currently, it doesn't work, I'm getting error messages like:
angular.js:14961 TypeError: Cannot read property '1' of undefined

Uncaught Error: Coordinate is not a valid Point

This would be important to implement, since currently turf.along() fails with antimeridian cases. GeoJSON standard says antimeridian geometries should be MultiLineString type:
https://tools.ietf.org/html/rfc7946#section-3.1.9

Reproduced:

https://jsfiddle.net/8h16u93j/

https://raw.githubusercontent.com/Turfjs/turf/master/packages/turf-length/test/in/multi-linestring.geojson

Most helpful comment

@csimpi morganherlocker said it well. The multi-parts are in an array so, yes, they have an order but not necessarily a meaningful order across users and data sets.

However, even if this feature request doesn't make it in Turf, think of this as an opportunity. There may be a user appetite for a new library with advanced geospatial processing built on top of Turf that allows for more complex algorithms. A turf-toolbox if you will. There are a few packages currently in Turf that would probably qualify but they are already in.

All 6 comments

JSON list order is not guaranteed, so I'm not sure this is a good idea. The user can implement deterministic along iteration as needed with the existing API.

Agreed that order is not guaranteed, also using MultiLineStrings with along is not clear what to do in all cases. For example, what if there is a gap between LineStrings? Ignore it and jump to next LineString? Connect them somehow?

However, if you want a simple implementation with the existing API that supports MultiLineStrings, traverses the lines in the order provided, and ignores jumps between lines, checkout this jsfiddle.

@morganherlocker
@dpmcmlxxvi
Thank you, guys!
I don't get this part: order is not guaranteed. The coordinates of the different lines are in an array with indexes, so the order is static, one line comes after the previous, what part that I don't understand?

The along can go through each line, and yes, if there's a gap it jumps to the next, that's why its name is along() we go along a Line or (in this case) Lines.

Don't get me wrong but this feels finding good excuses to me so far. How can be better an ugly Javascript error message than implementing a not perfect but _good enough_ solution?

I don't really see any real dealbreaker problem with supporting MultiLineString also.

Here is my playground that demonstrates the problem,
I use the same solution as you do with turf.length() and MultiLineString.

https://jsfiddle.net/bw1rxs5h/3/

If that's better I can change my original question:

How should I use along with antimeridian cases? Antimeridian is always a painful point but we have to handle it some way. There are no perfect solutions but there are workarounds, I'm looking for that ;)

I don't get this part: order is not guaranteed. The coordinates of the different lines are in an array with indexes, so the order is static, one line comes after the previous, what part that I don't understand?

I stand corrected! I had mixed up the fact that JSON does not guarantee Object key order, but it does, in fact maintain array order as you say.

I am still skeptical of this design though, since there is nothing about MultiLineString that suggests the data has a logical order or connection between parts. We would need to carefully define how the coordinates would be traversed, and we generally avoid algorithms that are non-obvious given the inputs and operation with very few exceptions. Should this algorithm ignore gaps between lines? Should it add the distance between linestrings to the running total? I can see reasonable reasons for both, which suggests to me that it may be a thing for users to decide in a helper function. I'm a little on the fence here to be honest, but I am always hesitant to introduce more complexity.

@csimpi morganherlocker said it well. The multi-parts are in an array so, yes, they have an order but not necessarily a meaningful order across users and data sets.

However, even if this feature request doesn't make it in Turf, think of this as an opportunity. There may be a user appetite for a new library with advanced geospatial processing built on top of Turf that allows for more complex algorithms. A turf-toolbox if you will. There are a few packages currently in Turf that would probably qualify but they are already in.

Thank you guys for the honest and clear opinion about my question. I hope eventually you/we'll find some better way to handle this since antimeridian cases should be handled! :)
Btw, I use along to move an icon along a flight route, that's why I want to handle antimeridian cases so bad :)

Was this page helpful?
0 / 5 - 0 ratings