Пример #1
0
        /// <summary>
        /// Find the nearest <see cref="LinearLocation"/> along the linear
        /// <see cref="Geometry"/> to a given <see cref="Coordinate"/>
        /// after the specified minimum <see cref="LinearLocation"/>.
        /// </summary>
        /// <param name="inputPt">the coordinate to locate
        /// </param>
        /// <param name="minLocation">the minimum location for the point location
        /// </param>
        /// <returns>The location of the nearest point.</returns>
        /// <remarks>
        /// If possible the location returned will be strictly greater than the
        /// <c>minLocation</c>.
        /// If this is not possible, the
        /// value returned will equal <c>minLocation</c>.
        /// (An example where this is not possible is when
        /// minLocation = [end of line] ).
        /// </remarks>
        public LinearLocation IndexOfAfter(Coordinate inputPt,
                                           LinearLocation minIndex)
        {
            if (minIndex == null)
            {
                return(IndexOf(inputPt));
            }

            // sanity check for minLocation at or past end of line
            LinearLocation endLoc = LinearLocation.GetEndLocation(linearGeom);

            if (endLoc.CompareTo(minIndex) <= 0)
            {
                return(endLoc);
            }

            LinearLocation closestAfter = IndexOfFromStart(inputPt, minIndex);

            // Return the minDistanceLocation found.
            // This will not be null, since it was initialized to minLocation
            Debug.Assert(closestAfter.CompareTo(minIndex) >= 0,
                         "computed location is before specified minimum location");

            return(closestAfter);
        }
Пример #2
0
        private LinearLocation GetLocationForward(double length)
        {
            if (length <= 0.0)
            {
                return(new LinearLocation());
            }

            double totalLength = 0.0;

            LinearIterator it = new LinearIterator(linearGeom);

            while (it.HasNext())
            {
                if (!it.EndOfLine)
                {
                    Coordinate p0     = it.SegmentStart;
                    Coordinate p1     = it.SegmentEnd;
                    double     segLen = p1.Distance(p0);

                    // length falls in this segment
                    if ((totalLength + segLen) > length)
                    {
                        double frac      = (length - totalLength) / segLen;
                        int    compIndex = it.ComponentIndex;
                        int    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));
        }