Exemplo n.º 1
0
        public static uint[] SearchClosestEdges(this GeometricGraph graph, float latitude, float longitude, float latitudeOffset, float longitudeOffset, float maxDistanceMeter, Func <GeometricEdge, bool>[] isOks)
        {
            GeoCoordinate  geoCoordinate = new GeoCoordinate((double)latitude, (double)longitude);
            HashSet <uint> uintSet1      = graph.Search(latitude - latitudeOffset, longitude - longitudeOffset, latitude + latitudeOffset, longitude + longitudeOffset);

            uint[]   numArray1 = new uint[isOks.Length];
            double[] numArray2 = new double[isOks.Length];
            for (int index = 0; index < numArray1.Length; ++index)
            {
                numArray1[index] = uint.MaxValue;
                numArray2[index] = (double)maxDistanceMeter;
            }
            GeometricGraph.EdgeEnumerator edgeEnumerator = graph.GetEdgeEnumerator();
            foreach (uint vertex1 in uintSet1)
            {
                GeoCoordinateSimple vertex2 = graph.GetVertex(vertex1);
                double num = GeoCoordinate.DistanceEstimateInMeter((double)latitude, (double)longitude, (double)vertex2.Latitude, (double)vertex2.Longitude);
                for (int index = 0; index < isOks.Length; ++index)
                {
                    if (num < numArray2[index])
                    {
                        edgeEnumerator.MoveTo(vertex1);
                        while (edgeEnumerator.MoveNext())
                        {
                            if (isOks[index](edgeEnumerator.Current))
                            {
                                numArray2[index] = num;
                                numArray1[index] = edgeEnumerator.Id;
                                break;
                            }
                        }
                    }
                }
            }
            GeoCoordinateBox[] boxes = new GeoCoordinateBox[isOks.Length];
            for (int index = 0; index < boxes.Length; ++index)
            {
                boxes[index] = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)((double)maxDistanceMeter), DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)((double)maxDistanceMeter), DirectionEnum.SouthEast));
            }
            HashSet <uint> uintSet2 = new HashSet <uint>();

            foreach (uint vertex1 in uintSet1)
            {
                GeoCoordinateSimple vertex2 = graph.GetVertex(vertex1);
                if (edgeEnumerator.MoveTo(vertex1) && edgeEnumerator.HasData)
                {
                    while (edgeEnumerator.MoveNext())
                    {
                        if (!uintSet2.Contains(edgeEnumerator.Id))
                        {
                            uintSet2.Add(edgeEnumerator.Id);
                            bool[] flagArray = new bool[isOks.Length];
                            for (int index = 0; index < isOks.Length; ++index)
                            {
                                flagArray[index] = isOks[index] == null;
                            }
                            ICoordinate coordinate = (ICoordinate)vertex2;
                            ShapeBase   shapeBase  = edgeEnumerator.Shape;
                            if (shapeBase != null)
                            {
                                if (edgeEnumerator.DataInverted)
                                {
                                    shapeBase = shapeBase.Reverse();
                                }
                                IEnumerator <ICoordinate> enumerator = shapeBase.GetEnumerator();
                                enumerator.Reset();
                                while (enumerator.MoveNext())
                                {
                                    ICoordinate current = enumerator.Current;
                                    double      num1    = GeoCoordinate.DistanceEstimateInMeter((double)current.Latitude, (double)current.Longitude, (double)latitude, (double)longitude);
                                    for (int index = 0; index < numArray1.Length; ++index)
                                    {
                                        if (num1 < numArray2[index])
                                        {
                                            if (!flagArray[index] && isOks[index](edgeEnumerator.Current))
                                            {
                                                flagArray[index] = true;
                                            }
                                            if (flagArray[index])
                                            {
                                                numArray2[index] = num1;
                                                numArray1[index] = edgeEnumerator.Id;
                                                boxes[index]     = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.SouthEast));
                                            }
                                        }
                                    }
                                    if (boxes.AnyIntersectsPotentially((double)coordinate.Longitude, (double)coordinate.Latitude, (double)current.Longitude, (double)current.Latitude))
                                    {
                                        PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude), new GeoCoordinate((double)current.Latitude, (double)current.Longitude), true, true).ProjectOn((PointF2D)geoCoordinate);
                                        if (pointF2D != (PointF2D)null)
                                        {
                                            double num2 = GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude);
                                            for (int index = 0; index < numArray1.Length; ++index)
                                            {
                                                if (num2 < numArray2[index])
                                                {
                                                    if (!flagArray[index] && isOks[index](edgeEnumerator.Current))
                                                    {
                                                        flagArray[index] = true;
                                                    }
                                                    if (flagArray[index])
                                                    {
                                                        numArray2[index] = num2;
                                                        numArray1[index] = edgeEnumerator.Id;
                                                        boxes[index]     = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.SouthEast));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    coordinate = current;
                                }
                            }
                            ICoordinate vertex3 = (ICoordinate)graph.GetVertex(edgeEnumerator.To);
                            if (boxes.AnyIntersectsPotentially((double)coordinate.Longitude, (double)coordinate.Latitude, (double)vertex3.Longitude, (double)vertex3.Latitude))
                            {
                                PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude), new GeoCoordinate((double)vertex3.Latitude, (double)vertex3.Longitude), true, true).ProjectOn((PointF2D)geoCoordinate);
                                if (pointF2D != (PointF2D)null)
                                {
                                    double num = GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude);
                                    for (int index = 0; index < isOks.Length; ++index)
                                    {
                                        if (num < numArray2[index])
                                        {
                                            if (!flagArray[index] && isOks[index](edgeEnumerator.Current))
                                            {
                                                flagArray[index] = true;
                                            }
                                            if (flagArray[index])
                                            {
                                                numArray2[index] = num;
                                                numArray1[index] = edgeEnumerator.Id;
                                                boxes[index]     = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.SouthEast));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(numArray1);
        }
Exemplo n.º 2
0
        public static List <uint> SearchCloserThan(this GeometricGraph graph, float latitude, float longitude, float offset, float maxDistanceMeter, Func <GeometricEdge, bool> isOk)
        {
            HashSet <uint> uintSet1      = new HashSet <uint>();
            GeoCoordinate  geoCoordinate = new GeoCoordinate((double)latitude, (double)longitude);
            HashSet <uint> uintSet2      = graph.Search(latitude, longitude, offset);

            GeometricGraph.EdgeEnumerator edgeEnumerator = graph.GetEdgeEnumerator();
            foreach (uint vertex1 in uintSet2)
            {
                GeoCoordinateSimple vertex2 = graph.GetVertex(vertex1);
                if (GeoCoordinate.DistanceEstimateInMeter((double)latitude, (double)longitude, (double)vertex2.Latitude, (double)vertex2.Longitude) < (double)maxDistanceMeter)
                {
                    edgeEnumerator.MoveTo(vertex1);
                    while (edgeEnumerator.MoveNext())
                    {
                        if (isOk(edgeEnumerator.Current))
                        {
                            uintSet1.Add(edgeEnumerator.Id);
                            break;
                        }
                    }
                }
            }
            GeoCoordinateBox geoCoordinateBox = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)((double)maxDistanceMeter), DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)((double)maxDistanceMeter), DirectionEnum.SouthEast));
            HashSet <uint>   uintSet3         = new HashSet <uint>();

            foreach (uint vertex1 in uintSet2)
            {
                GeoCoordinateSimple vertex2 = graph.GetVertex(vertex1);
                if (edgeEnumerator.MoveTo(vertex1) && edgeEnumerator.HasData)
                {
                    while (edgeEnumerator.MoveNext())
                    {
                        if (!uintSet3.Contains(edgeEnumerator.Id))
                        {
                            uintSet3.Add(edgeEnumerator.Id);
                            bool        flag       = isOk == null;
                            ICoordinate coordinate = (ICoordinate)vertex2;
                            ShapeBase   shapeBase  = edgeEnumerator.Shape;
                            if (shapeBase != null)
                            {
                                if (edgeEnumerator.DataInverted)
                                {
                                    shapeBase = shapeBase.Reverse();
                                }
                                IEnumerator <ICoordinate> enumerator = shapeBase.GetEnumerator();
                                enumerator.Reset();
                                while (enumerator.MoveNext())
                                {
                                    ICoordinate current = enumerator.Current;
                                    if (GeoCoordinate.DistanceEstimateInMeter((double)current.Latitude, (double)current.Longitude, (double)latitude, (double)longitude) < (double)maxDistanceMeter)
                                    {
                                        if (!flag && isOk(edgeEnumerator.Current))
                                        {
                                            flag = true;
                                        }
                                        if (flag)
                                        {
                                            uintSet1.Add(edgeEnumerator.Id);
                                        }
                                    }
                                    if (geoCoordinateBox.IntersectsPotentially((double)coordinate.Longitude, (double)coordinate.Latitude, (double)current.Longitude, (double)current.Latitude))
                                    {
                                        PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude), new GeoCoordinate((double)current.Latitude, (double)current.Longitude), true, true).ProjectOn((PointF2D)geoCoordinate);
                                        if (pointF2D != (PointF2D)null && GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude) < (double)maxDistanceMeter)
                                        {
                                            if (!flag && isOk(edgeEnumerator.Current))
                                            {
                                                flag = true;
                                            }
                                            if (flag)
                                            {
                                                uintSet1.Add(edgeEnumerator.Id);
                                            }
                                        }
                                    }
                                    coordinate = current;
                                }
                            }
                            ICoordinate vertex3 = (ICoordinate)graph.GetVertex(edgeEnumerator.To);
                            if (geoCoordinateBox.IntersectsPotentially((double)coordinate.Longitude, (double)coordinate.Latitude, (double)vertex3.Longitude, (double)vertex3.Latitude))
                            {
                                PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude), new GeoCoordinate((double)vertex3.Latitude, (double)vertex3.Longitude), true, true).ProjectOn((PointF2D)geoCoordinate);
                                if (pointF2D != (PointF2D)null && GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude) < (double)maxDistanceMeter)
                                {
                                    if (!flag && isOk(edgeEnumerator.Current))
                                    {
                                        flag = true;
                                    }
                                    if (flag)
                                    {
                                        uintSet1.Add(edgeEnumerator.Id);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(new List <uint>((IEnumerable <uint>)uintSet1));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Moves to the given vertex.
 /// </summary>
 /// <returns></returns>
 public bool MoveTo(uint vertex)
 {
     return(_enumerator.MoveTo(vertex));
 }