Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inputPt"></param>
        /// <param name="minIndex"></param>
        /// <returns></returns>
        private double IndexOfFromStart(ICoordinate inputPt, double minIndex)
        {
            double minDistance = Double.MaxValue;

            double ptMeasure = minIndex;
            double segmentStartMeasure = 0.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 segMeasureToPt = SegmentNearestMeasure(seg, inputPt, segmentStartMeasure);
                    if (segDistance < minDistance && segMeasureToPt > minIndex)
                    {
                        ptMeasure = segMeasureToPt;
                        minDistance = segDistance;
                    }
                    segmentStartMeasure += seg.Length;
                }
            }
            return ptMeasure;
        }
Ejemplo n.º 2
0
        /// <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;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pts"></param>
 /// <param name="i"></param>
 /// <param name="j"></param>
 /// <param name="maxDistance"></param>
 /// <returns></returns>
 private int FindFurthestPoint(ICoordinate[] pts, int i, int j, double[] maxDistance)
 {
     LineSegment seg = new LineSegment();
     seg.P0 = pts[i];
     seg.P1 = pts[j];
     double maxDist = -1.0;
     int maxIndex = i;
     for (int k = i + 1; k < j; k++)
     {
         ICoordinate midPt = pts[k];
         double distance = seg.Distance(midPt);
         if (distance > maxDist)
         {
             maxDist = distance;
             maxIndex = k;
         }
     }
     maxDistance[0] = maxDist;
     return maxIndex;
 }