Ejemplo n.º 1
0
        public static double get_Distance(IndexPoint p1, IndexPoint p2)
        {
            if (p1 == null || p2 == null)
                return double.NaN;

            return get_Distance(p1.X, p1.Y, p2.X, p2.Y);
        }
Ejemplo n.º 2
0
        public void AddPoint(IndexPoint pt)
        {
            string cell = this.get_GridCell(pt.X, pt.Y);

            this._points.Add(pt);

            ArrayList theCellContents;
            if (this._index.ContainsKey(cell) == false)
            {
                theCellContents = new ArrayList();
                theCellContents.Add(this._points.Count - 1);
                this._index.Add(cell, theCellContents);
            }
            else
            {
                theCellContents = (ArrayList)this._index[cell];
                theCellContents.Add(this._points.Count - 1);
            }
        }
Ejemplo n.º 3
0
        public ArrayList PointPairsWithinLimits(double lowLimit, double highLimit)
        {
            if (lowLimit >= highLimit)
                return null;

            ArrayList theReturn = new ArrayList();

            for (int theIndex = 0; theIndex < this._points.Count; theIndex++)
            {
                IndexPoint thePoint = (IndexPoint)this._points[theIndex];
                ArrayList theCells = this.get_GridCells(
                    thePoint.X - highLimit,
                    thePoint.Y - highLimit,
                    thePoint.X + highLimit,
                    thePoint.Y + highLimit);

                foreach (object cell in theCells)
                {
                    ArrayList theCellContents = (ArrayList)this._index[cell];
                    if (theCellContents != null)
                    {
                        for (int j = 0; j < theCellContents.Count; j++)
                        {
                            int theOtherIndex = (int)theCellContents[j];
                            // If theIndex is equal to theOtherIndex, it's the same point
                            // If theIndex is less than theOtherIndex, it's already been done
                            if (theOtherIndex > theIndex)
                            {
                                IndexPoint theOtherPoint = (IndexPoint)this._points[theOtherIndex];
                                double distance = get_Distance(thePoint, theOtherPoint);
                                if (lowLimit <= distance && distance <= highLimit)
                                {
                                    // If the two points are from the same error feature (likely),
                                    // check that they are at least two vertexes apart
                                    bool bSpurious = false;

                                    if (thePoint.SourceFeatureID == theOtherPoint.SourceFeatureID)
                                    {
                                        if (Math.Abs(thePoint.SourcePointIndex - theOtherPoint.SourcePointIndex) < 3)
                                        {
                                            bSpurious = true;
                                        }
                                        else
                                        {
                                            // The only case that we will accept is if theOtherPoint is closer to
                                            // thePoint than the point immediately before it. i.e. the line has
                                            // looped back and is approaching the original point
                                            IndexPoint thePreviousPoint = (IndexPoint)this._points[theOtherIndex - 1];
                                            double previousDistance = get_Distance(thePoint, thePreviousPoint);
                                            if (previousDistance < distance)
                                            {
                                                bSpurious = true;
                                            }
                                        }
                                    }
                                    if (bSpurious == false)
                                    {
                                        /* Format of the result is IndexPoint[6]
                                         * [0] - thePoint
                                         * [1] - theOtherPoint
                                         * [2] - point preceding thePoint in source feature shape
                                         * [3] - point following thePoint in source feature shape
                                         * [4] - point preceding theOtherPoint in source feature shape
                                         * [5] - point following theOtherPoint in source feature shape
                                         */
                                        IndexPoint[] thePair = new IndexPoint[6];
                                        thePair[0] = thePoint;
                                        thePair[1] = theOtherPoint;

                                        if (theIndex > 0 && ((IndexPoint)this._points[theIndex-1]).SourceFeatureID == thePoint.SourceFeatureID)
                                            thePair[2] = (IndexPoint)this._points[theIndex-1];
                                        if (theIndex < this._points.Count - 1 && ((IndexPoint)this._points[theIndex+1]).SourceFeatureID == thePoint.SourceFeatureID)
                                            thePair[3] = (IndexPoint)this._points[theIndex+1];

                                        if (theOtherIndex > 0 && ((IndexPoint)this._points[theOtherIndex-1]).SourceFeatureID == theOtherPoint.SourceFeatureID)
                                            thePair[4] = (IndexPoint)this._points[theOtherIndex-1];
                                        if (theOtherIndex < this._points.Count - 1 && ((IndexPoint)this._points[theOtherIndex+1]).SourceFeatureID == theOtherPoint.SourceFeatureID)
                                            thePair[5] = (IndexPoint)this._points[theOtherIndex+1];

                                        theReturn.Add(thePair);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return theReturn;
        }