Exemplo n.º 1
0
        public static List <ICoordinate> GetShape(this GeometricGraph graph, GeometricEdge geometricEdge, uint vertex, float maxDistance)
        {
            List <ICoordinate> coordinateList = new List <ICoordinate>();

            if (geometricEdge.Shape == null)
            {
                return(coordinateList);
            }
            if ((int)geometricEdge.From == (int)vertex)
            {
                ICoordinate location1 = (ICoordinate)graph.GetVertex(vertex);
                float       num       = 0.0f;
                IEnumerator <ICoordinate> enumerator = geometricEdge.Shape.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ICoordinate current = enumerator.Current;
                    num += (float)GeoCoordinate.DistanceEstimateInMeter(location1, current);
                    if ((double)num < (double)maxDistance)
                    {
                        coordinateList.Add(current);
                        location1 = current;
                    }
                    else
                    {
                        break;
                    }
                }
                return(coordinateList);
            }
            if ((int)geometricEdge.To == (int)vertex)
            {
                ShapeBase   shapeBase = geometricEdge.Shape.Reverse();
                ICoordinate location1 = (ICoordinate)graph.GetVertex(vertex);
                float       num       = 0.0f;
                IEnumerator <ICoordinate> enumerator = shapeBase.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ICoordinate current = enumerator.Current;
                    num += (float)GeoCoordinate.DistanceEstimateInMeter(location1, current);
                    if ((double)num < (double)maxDistance)
                    {
                        coordinateList.Add(current);
                        location1 = current;
                    }
                    else
                    {
                        break;
                    }
                }
                return(coordinateList);
            }
            throw new ArgumentOutOfRangeException(string.Format("Vertex {0} is not part of edge {1}.", new object[2]
            {
                (object)vertex,
                (object)geometricEdge.Id
            }));
        }
Exemplo n.º 2
0
        public static float Length(this GeometricGraph graph, GeometricEdge edge)
        {
            float       num        = 0.0f;
            ICoordinate coordinate = (ICoordinate)graph.GetVertex(edge.From);
            ShapeBase   shape      = edge.Shape;

            if (shape != null)
            {
                IEnumerator <ICoordinate> enumerator = shape.GetEnumerator();
                enumerator.Reset();
                while (enumerator.MoveNext())
                {
                    ICoordinate current = enumerator.Current;
                    num       += (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate.Latitude, (double)coordinate.Longitude, (double)current.Latitude, (double)current.Longitude);
                    coordinate = current;
                }
            }
            ICoordinate vertex = (ICoordinate)graph.GetVertex(edge.To);

            return(num + (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate.Latitude, (double)coordinate.Longitude, (double)vertex.Latitude, (double)vertex.Longitude));
        }
Exemplo n.º 3
0
        public static List <ICoordinate> GetShape(this GeometricGraph graph, GeometricEdge geometricEdge)
        {
            List <ICoordinate> coordinateList = new List <ICoordinate>();

            coordinateList.Add((ICoordinate)graph.GetVertex(geometricEdge.From));
            ShapeBase shapeBase = geometricEdge.Shape;

            if (shapeBase != null)
            {
                if (geometricEdge.DataInverted)
                {
                    shapeBase = shapeBase.Reverse();
                }
                IEnumerator <ICoordinate> enumerator = shapeBase.GetEnumerator();
                enumerator.Reset();
                while (enumerator.MoveNext())
                {
                    coordinateList.Add(enumerator.Current);
                }
            }
            coordinateList.Add((ICoordinate)graph.GetVertex(geometricEdge.To));
            return(coordinateList);
        }
Exemplo n.º 4
0
        public static bool ProjectOn(this GeometricGraph graph, GeometricEdge edge, float latitude, float longitude, out float projectedLatitude, out float projectedLongitude, out float projectedDistanceFromFirst, out int projectedShapeIndex, out float distanceToProjected, out float totalLength)
        {
            distanceToProjected        = float.MaxValue;
            projectedDistanceFromFirst = 0.0f;
            projectedLatitude          = float.MaxValue;
            projectedLongitude         = float.MaxValue;
            projectedShapeIndex        = -1;
            ICoordinate coordinate1 = (ICoordinate)graph.GetVertex(edge.From);
            ShapeBase   shape       = edge.Shape;
            IEnumerator <ICoordinate> enumerator = (IEnumerator <ICoordinate>)null;

            if (shape != null)
            {
                enumerator = shape.GetEnumerator();
                enumerator.Reset();
            }
            float num1 = 0.0f;
            int   num2 = -1;

            while (true)
            {
                bool        flag = true;
                ICoordinate coordinate2;
                if (enumerator != null && enumerator.MoveNext())
                {
                    coordinate2 = enumerator.Current;
                }
                else
                {
                    flag        = false;
                    coordinate2 = (ICoordinate)graph.GetVertex(edge.To);
                }
                PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate1.Latitude, (double)coordinate1.Longitude), new GeoCoordinate((double)coordinate2.Latitude, (double)coordinate2.Longitude), true, true).ProjectOn((PointF2D) new GeoCoordinate((double)latitude, (double)longitude));
                if (pointF2D != (PointF2D)null)
                {
                    double num3 = GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude);
                    if (num3 < (double)distanceToProjected)
                    {
                        distanceToProjected        = (float)num3;
                        projectedLatitude          = (float)pointF2D[1];
                        projectedLongitude         = (float)pointF2D[0];
                        projectedDistanceFromFirst = num1 + (float)GeoCoordinate.DistanceEstimateInMeter((double)projectedLatitude, (double)projectedLongitude, (double)coordinate1.Latitude, (double)coordinate1.Longitude);
                        projectedShapeIndex        = num2 + 1;
                    }
                }
                if (flag)
                {
                    num1 += (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate1.Latitude, (double)coordinate1.Longitude, (double)coordinate2.Latitude, (double)coordinate2.Longitude);
                    ++num2;
                    coordinate1 = coordinate2;
                }
                else
                {
                    break;
                }
            }
            GeoCoordinateSimple vertex = graph.GetVertex(edge.To);

            totalLength = num1 + (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate1.Latitude, (double)coordinate1.Longitude, (double)vertex.Latitude, (double)vertex.Longitude);
            return((double)distanceToProjected != 3.40282346638529E+38);
        }
Exemplo n.º 5
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.º 6
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);
        }