/// <summary> /// /// </summary> /// <param name="length"></param> /// <returns></returns> private LinearLocation GetLocationForward(double length) { if (length <= 0.0) { return(new LinearLocation()); } var totalLength = 0.0; var it = new LinearIterator(_linearGeom); while (it.HasNext()) { /** * Special handling is required for the situation when the * length references exactly to a component endpoint. * In this case, the endpoint location of the current component * is returned, * rather than the startpoint location of the next component. * This produces consistent behaviour with the project method. */ if (it.IsEndOfLine) { if (totalLength == length) { int compIndex = it.ComponentIndex; int segIndex = it.VertexIndex; return(new LinearLocation(compIndex, segIndex, 0.0)); } } else { var p0 = it.SegmentStart; var p1 = it.SegmentEnd; var segLen = p1.Distance(p0); // length falls in this segment if (totalLength + segLen > length) { var frac = (length - totalLength) / segLen; var compIndex = it.ComponentIndex; var segIndex = it.VertexIndex; return(new LinearLocation(compIndex, segIndex, frac)); } totalLength += segLen; } it.Next(); } // length is longer than line - return end location return(LinearLocation.GetEndLocation(_linearGeom)); }
/// <summary> /// Find the nearest <see cref="LinearLocation" /> along the linear <see cref="Geometry" /> /// to a given <see cref="Geometry" /> after the specified minimum <see cref="LinearLocation" />. /// If possible the location returned will be strictly greater than the <paramref name="minIndex" />. /// If this is not possible, the value returned will equal <paramref name="minIndex" />. /// (An example where this is not possible is when <paramref name="minIndex" /> = [end of line] ). /// </summary> /// <param name="inputPt">The coordinate to locate.</param> /// <param name="minIndex">The minimum location for the point location.</param> /// <returns>The location of the nearest point.</returns> public LinearLocation IndexOfAfter(Coordinate inputPt, LinearLocation minIndex) { if (minIndex == null) { return(IndexOf(inputPt)); } // sanity check for minLocation at or past end of line var endLoc = LinearLocation.GetEndLocation(_linearGeom); if (endLoc.CompareTo(minIndex) <= 0) { return(endLoc); } var closestAfter = IndexOfFromStart(inputPt, minIndex); /* * Return the minDistanceLocation found. * This will not be null, since it was initialized to minLocation */ Assert.IsTrue(closestAfter.CompareTo(minIndex) >= 0, "computed location is before specified minimum location"); return(closestAfter); }