mapbox/turf-swift

Add method to slice LineString between two distances

ShanMa1991 opened this issue · 1 comments

Right now in Turf.js, there's a method to slice a LineString based on the start and end distance, as TurfMisc.lineSliceAlong(line: startDist: stopDist: options).

And right now in Turf.swift, we have the LineString.trimmed(from:distance) to slice a LineString based on the start coordinate and the distance.

So is there any way to slice a LineString based on the start and end distance? Right now I'm implementing the following method to do so, but not sure whether it would get the same result as TurfMisc.lineSliceAlong(line: lineString, startDist: startDistance, stopDist: stopDistance)

if let midPoint = lineString.coordinateFromStart(distance: startDistance) {
    let slicedLine = lineString.trimmed(from: midPoint, distance: stopDistance - startDistance)
}
1ec5 commented

The code above is how you’d implement the same behavior. I don’t know if Turf.js’s line-slice-along originally did the same thing as LineString.trimmed(from:distance:) does today, but nowadays it takes a starting distance instead of a starting coordinate. We should add a variant of trimmed(from:to:) that takes two distances instead of a coordinate and distance.