/// <summary>
        ///
        /// </summary>
        /// <param name="inputPt"></param>
        /// <param name="minIndex"></param>
        /// <returns></returns>
        private LinearLocation IndexOfFromStart(ICoordinate inputPt, LinearLocation minIndex)
        {
            double minDistance       = Double.MaxValue;
            int    minComponentIndex = 0;
            int    minSegmentIndex   = 0;
            double minFrac           = -1.0;

            LineSegment seg = new LineSegment();

            foreach (LinearIterator.LinearElement element in new LinearIterator(linearGeom))
            {
                if (!element.IsEndOfLine)
                {
                    seg.P0 = element.SegmentStart;
                    seg.P1 = element.SegmentEnd;
                    double segDistance = seg.Distance(inputPt);
                    double segFrac     = SegmentFraction(seg, inputPt);

                    int candidateComponentIndex = element.ComponentIndex;
                    int candidateSegmentIndex   = element.VertexIndex;
                    if (segDistance < minDistance)
                    {
                        // ensure after minLocation, if any
                        if (minIndex == null ||
                            minIndex.CompareLocationValues(candidateComponentIndex, candidateSegmentIndex, segFrac) < 0)
                        {
                            // otherwise, save this as new minimum
                            minComponentIndex = candidateComponentIndex;
                            minSegmentIndex   = candidateSegmentIndex;
                            minFrac           = segFrac;
                            minDistance       = segDistance;
                        }
                    }
                }
            }

            LinearLocation loc = new LinearLocation(minComponentIndex, minSegmentIndex, minFrac);

            return(loc);
        }
Beispiel #2
0
        /// <summary>
        /// Assumes input is valid
        /// (e.g. <paramref name="start" /> minor or equals to <paramref name="end" />).
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private IGeometry ComputeLinear(LinearLocation start, LinearLocation end)
        {
            LinearGeometryBuilder builder = new LinearGeometryBuilder(line.Factory);

            builder.FixInvalidLines = true;

            if (!start.IsVertex)
            {
                builder.Add(start.GetCoordinate(line));
            }

            LinearIterator it = new LinearIterator(line, start);

            foreach (LinearIterator.LinearElement element in it)
            {
                int compare = end.CompareLocationValues(element.ComponentIndex, element.VertexIndex, 0.0);
                if (compare < 0)
                {
                    break;
                }

                ICoordinate pt = element.SegmentStart;
                builder.Add(pt);
                if (element.IsEndOfLine)
                {
                    builder.EndLine();
                }
            }

            if (!end.IsVertex)
            {
                builder.Add(end.GetCoordinate(line));
            }

            return(builder.GetGeometry());
        }