diff --git a/lib/src/line_slice.dart b/lib/src/line_slice.dart index 8f41051..17059fb 100644 --- a/lib/src/line_slice.dart +++ b/lib/src/line_slice.dart @@ -6,6 +6,9 @@ import 'package:turf/src/invariant.dart'; /// and returns a subsection of the line in-between those points. /// The start & stop points don't need to fall exactly on the line. /// +/// If [startPt] and [stopPt] resolve to the same point on [line], null is returned +/// as the resolved line would only contain one point which isn't supported by LineString. +/// /// This can be useful for extracting only the part of a route between waypoints. Feature lineSlice( Point startPt, Point stopPt, Feature line) { @@ -16,6 +19,10 @@ Feature lineSlice( final startVertex = nearestPointOnLine(coords, startPt); final stopVertex = nearestPointOnLine(coords, stopPt); + if (startVertex['index'] == stopVertex['index']) { + // LineString do not allow 1 point lines + return null; + } late final List> ends; if (startVertex.properties!['index'] <= stopVertex.properties!['index']) { ends = [startVertex, stopVertex];