コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        private LinearLocation GetLocationForward(double length)
        {
            if (length <= 0.0)
            {
                return(new LinearLocation());
            }

            double totalLength = 0.0;

            foreach (LinearIterator.LinearElement element in new LinearIterator(linearGeom))
            {
                if (!element.IsEndOfLine)
                {
                    ICoordinate p0     = element.SegmentStart;
                    ICoordinate p1     = element.SegmentEnd;
                    double      segLen = p1.Distance(p0);
                    // length falls in this segment
                    if (totalLength + segLen > length)
                    {
                        double frac      = (length - totalLength) / segLen;
                        int    compIndex = element.ComponentIndex;
                        int    segIndex  = element.VertexIndex;
                        return(new LinearLocation(compIndex, segIndex, frac));
                    }
                    totalLength += segLen;
                }
            }
            // length is longer than line - return end location
            return(LinearLocation.GetEndLocation(linearGeom));
        }
コード例 #2
0
        /// <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(ICoordinate 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
             */
            Assert.IsTrue(closestAfter.CompareTo(minIndex) >= 0, "computed location is before specified minimum location");
            return(closestAfter);
        }