示例#1
0
        public static List <ICoordinate> GetShape(this GeometricGraph graph, GeometricEdge geometricEdge, float minDistance, float maxDistance)
        {
            List <ICoordinate> coordinateList = new List <ICoordinate>();

            if (geometricEdge.Shape == null)
            {
                return(coordinateList);
            }
            ICoordinate location1 = (ICoordinate)graph.GetVertex(geometricEdge.From);
            float       num       = 0.0f;
            IEnumerator <ICoordinate> enumerator = geometricEdge.Shape.GetEnumerator();

            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                ICoordinate current = enumerator.Current;
                num += (float)GeoCoordinate.DistanceEstimateInMeter(location1, current);
                if ((double)minDistance < (double)num && (double)num < (double)maxDistance)
                {
                    coordinateList.Add(current);
                }
                location1 = current;
            }
            return(coordinateList);
        }
示例#2
0
        public static ICoordinate LocationOnNetwork(this RouterPoint point, RouterDb db)
        {
            GeometricEdge      edge  = db.Network.GeometricGraph.GetEdge(point.EdgeId);
            List <ICoordinate> shape = db.Network.GeometricGraph.GetShape(edge);
            double             num1  = (double)db.Network.GeometricGraph.Length(edge);
            double             num2  = 0.0;
            double             num3  = num1 * ((double)point.Offset / (double)ushort.MaxValue);

            for (int index = 1; index < shape.Count; ++index)
            {
                double num4 = GeoCoordinate.DistanceEstimateInMeter(shape[index - 1], shape[index]);
                if (num4 + num2 > num3)
                {
                    double num5 = 1.0 - (num4 + num2 - num3) / num4;

                    return((ICoordinate) new GeoCoordinateSimple()
                    {
                        Latitude = (shape[index - 1].Latitude + (float)(num5 * ((double)shape[index].Latitude - (double)shape[index - 1].Latitude))),
                        Longitude = (shape[index - 1].Longitude + (float)(num5 * ((double)shape[index].Longitude - (double)shape[index - 1].Longitude)))
                    });
                }
                num2 += num4;
            }
            return(shape[shape.Count - 1]);
        }
示例#3
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
            }));
        }
        protected override void DoRun()
        {
            this._results = new List <RouterPoint>();
            List <uint> uintList = this._graph.SearchCloserThan(this._latitude, this._longitude, this._maxOffset, this._maxDistance, this._isAcceptable);

            if (uintList.Count == 0)
            {
                this.ErrorMessage = string.Format("Could not resolve point at [{0}, {1}]. Probably too far from closest road or outside of the loaded network.", new object[2]
                {
                    (object)this._latitude.ToInvariantString(),
                    (object)this._longitude.ToInvariantString()
                });
            }
            else
            {
                for (int index1 = 0; index1 < uintList.Count; ++index1)
                {
                    uint          edgeId = uintList[index1];
                    GeometricEdge edge   = this._graph.GetEdge(edgeId);
                    float         projectedLatitude;
                    float         projectedLongitude;
                    float         projectedDistanceFromFirst;
                    int           projectedShapeIndex;
                    float         distanceToProjected;
                    float         totalLength;
                    if (!this._graph.ProjectOn(edge, this._latitude, this._longitude, out projectedLatitude, out projectedLongitude, out projectedDistanceFromFirst, out projectedShapeIndex, out distanceToProjected, out totalLength))
                    {
                        List <ICoordinate> shape       = this._graph.GetShape(edge);
                        ICoordinate        coordinate1 = shape[0];
                        float num1 = 0.0f;
                        float num2 = 0.0f;
                        float num3 = (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate1.Latitude, (double)coordinate1.Longitude, (double)this._latitude, (double)this._longitude);
                        projectedLatitude  = coordinate1.Latitude;
                        projectedLongitude = coordinate1.Longitude;
                        for (int index2 = 1; index2 < shape.Count; ++index2)
                        {
                            ICoordinate coordinate2 = shape[index2];
                            num2 += (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate2.Latitude, (double)coordinate2.Longitude, (double)coordinate1.Latitude, (double)coordinate1.Longitude);
                            distanceToProjected = (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate2.Latitude, (double)coordinate2.Longitude, (double)this._latitude, (double)this._longitude);
                            if ((double)distanceToProjected < (double)num3)
                            {
                                num3 = distanceToProjected;
                                num1 = num2;
                                projectedLatitude  = coordinate2.Latitude;
                                projectedLongitude = coordinate2.Longitude;
                            }
                            coordinate1 = coordinate2;
                        }
                        projectedDistanceFromFirst = num1;
                    }
                    ushort offset = (ushort)((double)projectedDistanceFromFirst / (double)totalLength * (double)ushort.MaxValue);
                    this._results.Add(new RouterPoint(projectedLatitude, projectedLongitude, edgeId, offset));
                }
                this.HasSucceeded = true;
            }
        }
示例#5
0
        public static void SetDistanceAndTime(this RouteSegment segment, RouteSegment previous, Speed speed)
        {
            double num = GeoCoordinate.DistanceEstimateInMeter((ICoordinate) new GeoCoordinateSimple()
            {
                Latitude  = previous.Latitude,
                Longitude = previous.Longitude
            }, (ICoordinate) new GeoCoordinateSimple()
            {
                Latitude  = segment.Latitude,
                Longitude = segment.Longitude
            });

            segment.Distance = previous.Distance + num;
            segment.Time     = previous.Time + num / (double)speed.Value;
        }
        /// <summary>
        /// Calculates the distance in meter starting at lat1/lon1 along the coordinates to lat2/lon2
        /// </summary>
        /// <param name="coordinates"></param>
        /// <param name="latitude1"></param>
        /// <param name="longitude1"></param>
        /// <param name="latitude2"></param>
        /// <param name="longitude2"></param>
        /// <returns></returns>
        public static double DistanceInMeter(this IEnumerable <ICoordinate> coordinates, double latitude1, double longitude1,
                                             double latitude2, double longitude2)
        {
            var latitude  = latitude1;
            var longitude = longitude1;
            var distance  = 0.0;

            foreach (var coordinate in coordinates)
            {
                var cLatitude  = coordinate.Latitude;
                var cLongitude = coordinate.Longitude;
                distance = distance + GeoCoordinate.DistanceEstimateInMeter(latitude, longitude,
                                                                            cLatitude, cLongitude);
                latitude  = cLatitude;
                longitude = cLongitude;
            }
            return(distance + GeoCoordinate.DistanceEstimateInMeter(latitude, longitude,
                                                                    latitude2, longitude2));
        }
示例#7
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));
        }
示例#8
0
        public static uint SearchClosest(this GeometricGraph graph, float latitude, float longitude, float latitudeOffset, float longitudeOffset)
        {
            HashSet <uint> uintSet = graph.Search(latitude - latitudeOffset, longitude - longitudeOffset, latitude + latitudeOffset, longitude + longitudeOffset);
            double         num1    = double.MaxValue;
            uint           num2    = 4294967294;

            foreach (uint vertex in uintSet)
            {
                float latitude1;
                float longitude1;
                if (graph.GetVertex(vertex, out latitude1, out longitude1))
                {
                    double num3 = GeoCoordinate.DistanceEstimateInMeter((double)latitude, (double)longitude, (double)latitude1, (double)longitude1);
                    if (num3 < num1)
                    {
                        num1 = num3;
                        num2 = vertex;
                    }
                }
            }
            return(num2);
        }
示例#9
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);
        }
示例#10
0
        protected override void DoRun()
        {
            GeoCoordinate geoCoordinate   = new GeoCoordinate((double)this._latitude, (double)this._longitude).OffsetWithDistances((Meter)((double)this._maxOffsetInMeter));
            float         latitudeOffset  = (float)System.Math.Abs((double)this._latitude - geoCoordinate[1]);
            float         longitudeOffset = (float)System.Math.Abs((double)this._longitude - geoCoordinate[0]);

            uint[] numArray;
            if (this._isBetter == null)
            {
                numArray = new uint[2]
                {
                    this._graph.SearchClosestEdge(this._latitude, this._longitude, latitudeOffset, longitudeOffset, this._maxDistance, this._isAcceptable),
                    0U
                }
            }
            ;
            else
            {
                numArray = this._graph.SearchClosestEdges(this._latitude, this._longitude, latitudeOffset, longitudeOffset, this._maxDistance, new Func <GeometricEdge, bool>[2]
                {
                    this._isAcceptable,
                    (Func <GeometricEdge, bool>)(potentialEdge =>
                    {
                        if (this._isAcceptable(potentialEdge))
                        {
                            return(this._isBetter(potentialEdge));
                        }
                        return(false);
                    })
                });
            }
            if ((int)numArray[0] == -1)
            {
                this.ErrorMessage = string.Format("Could not resolve point at [{0}, {1}]. Probably too far from closest road or outside of the loaded network.", new object[2]
                {
                    (object)this._latitude.ToInvariantString(),
                    (object)this._longitude.ToInvariantString()
                });
            }
            else
            {
                GeometricEdge edge1  = this._graph.GetEdge(numArray[0]);
                uint          edgeId = numArray[0];
                float         projectedLatitude1;
                float         projectedLongitude1;
                float         projectedDistanceFromFirst1;
                int           projectedShapeIndex1;
                float         distanceToProjected1;
                float         totalLength1;
                if (!this._graph.ProjectOn(edge1, this._latitude, this._longitude, out projectedLatitude1, out projectedLongitude1, out projectedDistanceFromFirst1, out projectedShapeIndex1, out distanceToProjected1, out totalLength1))
                {
                    List <ICoordinate> shape       = this._graph.GetShape(edge1);
                    ICoordinate        coordinate1 = shape[0];
                    float num1 = 0.0f;
                    float num2 = 0.0f;
                    float num3 = (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate1.Latitude, (double)coordinate1.Longitude, (double)this._latitude, (double)this._longitude);
                    projectedLatitude1  = coordinate1.Latitude;
                    projectedLongitude1 = coordinate1.Longitude;
                    for (int index = 1; index < shape.Count; ++index)
                    {
                        ICoordinate coordinate2 = shape[index];
                        num2 += (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate2.Latitude, (double)coordinate2.Longitude, (double)coordinate1.Latitude, (double)coordinate1.Longitude);
                        distanceToProjected1 = (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate2.Latitude, (double)coordinate2.Longitude, (double)this._latitude, (double)this._longitude);
                        if ((double)distanceToProjected1 < (double)num3)
                        {
                            num3 = distanceToProjected1;
                            num1 = num2;
                            projectedLatitude1  = coordinate2.Latitude;
                            projectedLongitude1 = coordinate2.Longitude;
                        }
                        coordinate1 = coordinate2;
                    }
                    projectedDistanceFromFirst1 = num1;
                }
                if (this._isBetter != null && (int)numArray[0] != (int)numArray[1] && (int)numArray[1] != -1)
                {
                    GeometricEdge edge2 = this._graph.GetEdge(numArray[1]);
                    float         projectedLatitude2;
                    float         projectedLongitude2;
                    float         projectedDistanceFromFirst2;
                    int           projectedShapeIndex2;
                    float         distanceToProjected2;
                    float         totalLength2;
                    if (!this._graph.ProjectOn(edge2, this._latitude, this._longitude, out projectedLatitude2, out projectedLongitude2, out projectedDistanceFromFirst2, out projectedShapeIndex2, out distanceToProjected2, out totalLength2))
                    {
                        List <ICoordinate> shape       = this._graph.GetShape(edge2);
                        ICoordinate        coordinate1 = shape[0];
                        float num1 = 0.0f;
                        float num2 = 0.0f;
                        float num3 = (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate1.Latitude, (double)coordinate1.Longitude, (double)this._latitude, (double)this._longitude);
                        projectedLatitude2  = coordinate1.Latitude;
                        projectedLongitude2 = coordinate1.Longitude;
                        for (int index = 1; index < shape.Count; ++index)
                        {
                            ICoordinate coordinate2 = shape[index];
                            num2 += (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate2.Latitude, (double)coordinate2.Longitude, (double)coordinate1.Latitude, (double)coordinate1.Longitude);
                            distanceToProjected2 = (float)GeoCoordinate.DistanceEstimateInMeter((double)coordinate2.Latitude, (double)coordinate2.Longitude, (double)this._latitude, (double)this._longitude);
                            if ((double)distanceToProjected2 < (double)num3)
                            {
                                num3 = distanceToProjected2;
                                num1 = num2;
                                projectedLatitude2  = coordinate2.Latitude;
                                projectedLongitude2 = coordinate2.Longitude;
                            }
                            coordinate1 = coordinate2;
                        }
                        projectedDistanceFromFirst2 = num1;
                    }
                    if ((double)distanceToProjected2 <= (double)ResolveAlgorithm.BetterEdgeThreshold || (double)distanceToProjected2 <= (double)distanceToProjected1 * (double)ResolveAlgorithm.BetterEdgeFactor)
                    {
                        totalLength1                = totalLength2;
                        edgeId                      = numArray[1];
                        projectedLatitude1          = projectedLatitude2;
                        projectedLongitude1         = projectedLongitude2;
                        projectedDistanceFromFirst1 = projectedDistanceFromFirst2;
                    }
                }
                ushort offset = (ushort)((double)projectedDistanceFromFirst1 / (double)totalLength1 * (double)ushort.MaxValue);
                this._result      = new RouterPoint(projectedLatitude1, projectedLongitude1, edgeId, offset);
                this.HasSucceeded = true;
            }
        }
示例#11
0
 public void AddCoreEdge(uint vertex1, uint vertex2, EdgeData data, List <ICoordinate> shape)
 {
     if ((double)data.Distance < (double)this._db.Network.MaxEdgeDistance)
     {
         int num1 = (int)this._db.Network.AddEdge(vertex1, vertex2, data, (IEnumerable <ICoordinate>)shape);
     }
     else
     {
         if (shape == null)
         {
             shape = new List <ICoordinate>();
         }
         shape = new List <ICoordinate>((IEnumerable <ICoordinate>)shape);
         shape.Insert(0, (ICoordinate)this._db.Network.GetVertex(vertex1));
         shape.Add((ICoordinate)this._db.Network.GetVertex(vertex2));
         for (int index = 1; index < shape.Count; ++index)
         {
             if (GeoCoordinate.DistanceEstimateInMeter(shape[index - 1], shape[index]) >= (double)this._db.Network.MaxEdgeDistance)
             {
                 shape.Insert(index, (ICoordinate) new GeoCoordinateSimple()
                 {
                     Latitude  = (float)(((double)shape[index - 1].Latitude + (double)shape[index].Latitude) / 2.0),
                     Longitude = (float)(((double)shape[index - 1].Longitude + (double)shape[index].Longitude) / 2.0)
                 });
                 --index;
             }
         }
         int num2 = 0;
         List <ICoordinate> coordinateList1 = new List <ICoordinate>();
         float    num3   = 0.0f;
         int      index1 = num2 + 1;
         EdgeData edgeData;
         while (index1 < shape.Count)
         {
             float num4 = (float)GeoCoordinate.DistanceEstimateInMeter(shape[index1 - 1], shape[index1]);
             if ((double)num4 + (double)num3 > (double)this._db.Network.MaxEdgeDistance)
             {
                 ICoordinate coordinate = coordinateList1[coordinateList1.Count - 1];
                 coordinateList1.RemoveAt(coordinateList1.Count - 1);
                 uint vertexCount = this._db.Network.VertexCount;
                 this._db.Network.AddVertex(vertexCount, coordinate.Latitude, coordinate.Longitude);
                 RoutingNetwork network = this._db.Network;
                 int            num5    = (int)vertex1;
                 int            num6    = (int)vertexCount;
                 edgeData          = new EdgeData();
                 edgeData.Distance = num3;
                 edgeData.MetaId   = data.MetaId;
                 edgeData.Profile  = data.Profile;
                 EdgeData           data1           = edgeData;
                 List <ICoordinate> coordinateList2 = coordinateList1;
                 int num7 = (int)network.AddEdge((uint)num5, (uint)num6, data1, (IEnumerable <ICoordinate>)coordinateList2);
                 vertex1 = vertexCount;
                 coordinateList1.Clear();
                 coordinateList1.Add(shape[index1]);
                 num3 = num4;
                 ++index1;
             }
             else
             {
                 coordinateList1.Add(shape[index1]);
                 num3 += num4;
                 ++index1;
             }
         }
         if (coordinateList1.Count > 0)
         {
             coordinateList1.RemoveAt(coordinateList1.Count - 1);
         }
         RoutingNetwork network1 = this._db.Network;
         int            num8     = (int)vertex1;
         int            num9     = (int)vertex2;
         edgeData          = new EdgeData();
         edgeData.Distance = num3;
         edgeData.MetaId   = data.MetaId;
         edgeData.Profile  = data.Profile;
         EdgeData           data2           = edgeData;
         List <ICoordinate> coordinateList3 = coordinateList1;
         int num10 = (int)network1.AddEdge((uint)num8, (uint)num9, data2, (IEnumerable <ICoordinate>)coordinateList3);
     }
 }
示例#12
0
        public override void AddWay(Way way)
        {
            ICoordinate coordinate;
            EdgeData    data;

            if (way == null)
            {
                return;
            }

            if (way.Nodes == null)
            {
                return;
            }

            if (way.Nodes.Count == 0)
            {
                return;
            }

            if (!this._firstPass)
            {
                if (this.Processors != null)
                {
                    foreach (ITwoPassProcessor processor in this.Processors)
                    {
                        processor.SecondPass(way);
                    }
                }
                if (this._vehicles.AnyCanTraverse(way.Tags))
                {
                    if (this._processedWays.Contains(way.Id.Value))
                    {
                        return;
                    }
                    TagsCollection tagsCollection  = new TagsCollection(way.Tags.Count);
                    TagsCollection tagsCollection1 = new TagsCollection(way.Tags.Count);
                    foreach (Tag tag in way.Tags)
                    {
                        if (!this._vehicles.IsRelevantForProfile(tag.Key))
                        {
                            tagsCollection1.Add(tag);
                        }
                        else
                        {
                            tagsCollection.Add(tag);
                        }
                    }
                    if (this._normalizeTags)
                    {
                        TagsCollection tagsCollection2 = new TagsCollection(tagsCollection.Count);
                        if (!tagsCollection.Normalize(tagsCollection2, tagsCollection1, this._vehicles))
                        {
                            return;
                        }
                        if (this.Processors != null)
                        {
                            foreach (ITwoPassProcessor twoPassProcessor in this.Processors)
                            {
                                Action <TagsCollectionBase, TagsCollectionBase> onAfterWayTagsNormalize = twoPassProcessor.OnAfterWayTagsNormalize;
                                if (onAfterWayTagsNormalize == null)
                                {
                                    continue;
                                }
                                onAfterWayTagsNormalize.Invoke(tagsCollection2, tagsCollection);
                            }
                        }
                        tagsCollection = tagsCollection2;
                    }
                    uint num = this._db.EdgeProfiles.Add(tagsCollection);
                    if (num > 16384)
                    {
                        throw new Exception("Maximum supported profiles exeeded, make sure only routing tags are included in the profiles.");
                    }
                    uint num1 = this._db.EdgeMeta.Add(tagsCollection1);
                    int  num2 = 0;
Label0:
                    while (num2 < way.Nodes.Count - 1)
                    {
                        List <ICoordinate> list = new List <ICoordinate>();
                        float single            = 0f;
                        if (!this._stageCoordinates.TryGetValue(way.Nodes[num2], out coordinate))
                        {
                            for (int i = 0; i < way.Nodes.Count; i++)
                            {
                                this._anyStageNodes.Add(way.Nodes[i]);
                            }
                            return;
                        }
                        uint        from        = this.AddCoreNode(way.Nodes[num2], coordinate.Latitude, coordinate.Longitude);
                        long        item        = way.Nodes[num2];
                        ICoordinate coordinate1 = coordinate;
                        num2++;
                        long to    = -1;
                        long item1 = 9223372036854775807L;
                        while (this._stageCoordinates.TryGetValue(way.Nodes[num2], out coordinate))
                        {
                            single = single + (float)GeoCoordinate.DistanceEstimateInMeter(coordinate1, coordinate);
                            if (!this._coreNodes.Contains(way.Nodes[num2]))
                            {
                                list.Add(coordinate);
                                coordinate1 = coordinate;
                                num2++;
                            }
                            else
                            {
                                to    = this.AddCoreNode(way.Nodes[num2], coordinate.Latitude, coordinate.Longitude);
                                item1 = way.Nodes[num2];
                                if (from != to)
                                {
                                    RoutingEdge routingEdge = Enumerable.FirstOrDefault <RoutingEdge>(this._db.Network.GetEdgeEnumerator(from), (RoutingEdge x) => x.To == to);
                                    if (routingEdge != null || from == to)
                                    {
                                        data = routingEdge.Data;
                                        if (data.Distance == single)
                                        {
                                            data = routingEdge.Data;
                                            if (data.Profile == num)
                                            {
                                                data = routingEdge.Data;
                                                if (data.MetaId == num1)
                                                {
                                                    goto Label0;
                                                }
                                            }
                                        }
                                        uint  metaId   = num1;
                                        uint  profile  = num;
                                        float distance = single;
                                        if (list.Count == 0 && routingEdge != null && routingEdge.Shape != null)
                                        {
                                            list     = new List <ICoordinate>(routingEdge.Shape);
                                            from     = routingEdge.From;
                                            to       = routingEdge.To;
                                            data     = routingEdge.Data;
                                            metaId   = data.MetaId;
                                            data     = routingEdge.Data;
                                            profile  = data.Profile;
                                            data     = routingEdge.Data;
                                            distance = data.Distance;
                                            long num3 = to;
                                            data = new EdgeData()
                                            {
                                                MetaId   = num1,
                                                Distance = System.Math.Max(single, 0f),
                                                Profile  = (ushort)num
                                            };
                                            this.AddCoreEdge(from, (uint)num3, data, null);
                                        }
                                        if (list.Count <= 0)
                                        {
                                            GeoCoordinateSimple vertex = this._db.Network.GetVertex(from);
                                            uint num4 = this.AddNewCoreNode(item, vertex.Latitude, vertex.Longitude);
                                            data = new EdgeData()
                                            {
                                                Distance = 0f,
                                                MetaId   = metaId,
                                                Profile  = (ushort)profile
                                            };
                                            this.AddCoreEdge(from, num4, data, null);
                                            GeoCoordinateSimple geoCoordinateSimple = this._db.Network.GetVertex((uint)to);
                                            uint num5 = this.AddNewCoreNode(item1, geoCoordinateSimple.Latitude, geoCoordinateSimple.Longitude);
                                            long num6 = to;
                                            data = new EdgeData()
                                            {
                                                Distance = 0f,
                                                MetaId   = metaId,
                                                Profile  = (ushort)profile
                                            };
                                            this.AddCoreEdge(num5, (uint)num6, data, null);
                                            data = new EdgeData()
                                            {
                                                Distance = distance,
                                                MetaId   = metaId,
                                                Profile  = (ushort)profile
                                            };
                                            this.AddCoreEdge(num4, num5, data, null);
                                            goto Label0;
                                        }
                                        else
                                        {
                                            uint vertexCount = this._db.Network.VertexCount;
                                            this._db.Network.AddVertex(vertexCount, list[0].Latitude, list[0].Longitude);
                                            float single1 = (float)GeoCoordinate.DistanceEstimateInMeter(this._db.Network.GetVertex(from), list[0]);
                                            distance = distance - single1;
                                            data     = new EdgeData()
                                            {
                                                MetaId   = metaId,
                                                Distance = System.Math.Max(single1, 0f),
                                                Profile  = (ushort)profile
                                            };
                                            this.AddCoreEdge(from, vertexCount, data, null);
                                            list.RemoveAt(0);
                                            long num7 = to;
                                            data = new EdgeData()
                                            {
                                                MetaId   = metaId,
                                                Distance = System.Math.Max(distance, 0f),
                                                Profile  = (ushort)profile
                                            };
                                            this.AddCoreEdge(vertexCount, (uint)num7, data, list);
                                            goto Label0;
                                        }
                                    }
                                    else
                                    {
                                        long num8 = to;
                                        data = new EdgeData()
                                        {
                                            MetaId   = num1,
                                            Distance = single,
                                            Profile  = (ushort)num
                                        };
                                        this.AddCoreEdge(from, (uint)num8, data, list);
                                        goto Label0;
                                    }
                                }
                                else if (list.Count != 1)
                                {
                                    if (list.Count < 2)
                                    {
                                        goto Label0;
                                    }
                                    uint vertexCount1 = this._db.Network.VertexCount;
                                    this._db.Network.AddVertex(vertexCount1, list[0].Latitude, list[0].Longitude);
                                    uint vertexCount2 = this._db.Network.VertexCount;
                                    this._db.Network.AddVertex(vertexCount2, list[list.Count() - 1].Latitude, list[list.Count - 1].Longitude);
                                    float single2 = (float)GeoCoordinate.DistanceEstimateInMeter(this._db.Network.GetVertex(from), list[0]);
                                    float single3 = (float)GeoCoordinate.DistanceEstimateInMeter(this._db.Network.GetVertex((uint)to), list[list.Count - 1]);
                                    list.RemoveAt(0);
                                    list.RemoveAt(list.Count - 1);
                                    data = new EdgeData()
                                    {
                                        MetaId   = num1,
                                        Distance = single2,
                                        Profile  = (ushort)num
                                    };
                                    this.AddCoreEdge(from, vertexCount1, data, null);
                                    data = new EdgeData()
                                    {
                                        MetaId   = num1,
                                        Distance = single - single3 - single2,
                                        Profile  = (ushort)num
                                    };
                                    this.AddCoreEdge(vertexCount1, vertexCount2, data, list);
                                    uint num9 = (uint)to;
                                    data = new EdgeData()
                                    {
                                        MetaId   = num1,
                                        Distance = single3,
                                        Profile  = (ushort)num
                                    };
                                    this.AddCoreEdge(vertexCount2, num9, data, null);
                                    goto Label0;
                                }
                                else
                                {
                                    uint vertexCount3 = this._db.Network.VertexCount;
                                    this._db.Network.AddVertex(vertexCount3, list[0].Latitude, list[0].Longitude);
                                    data = new EdgeData()
                                    {
                                        MetaId   = num1,
                                        Distance = (float)GeoCoordinate.DistanceEstimateInMeter(this._db.Network.GetVertex(from), list[0]),
                                        Profile  = (ushort)num
                                    };
                                    this.AddCoreEdge(from, vertexCount3, data, null);
                                    goto Label0;
                                }
                            }
                        }
                        for (int j = 0; j < way.Nodes.Count; j++)
                        {
                            this._anyStageNodes.Add(way.Nodes[j]);
                        }
                        return;
                    }
                    this._processedWays.Add(way.Id.Value);
                }
            }
            else
            {
                if (this.Processors != null)
                {
                    foreach (ITwoPassProcessor processor1 in this.Processors)
                    {
                        processor1.FirstPass(way);
                    }
                }
                GeoCoordinateBox geoCoordinateBox = new GeoCoordinateBox(new GeoCoordinate(this._minLatitude, this._minLongitude), new GeoCoordinate(this._maxLatitude, this._maxLongitude));
                double           num10            = 1E-05;
                if (this._stages.Count == 0)
                {
                    if (this._nodeCount > (long)500000000 || this._minimumStages > 1)
                    {
                        double num11 = System.Math.Max(System.Math.Ceiling((double)(this._nodeCount / (long)500000000)), (double)this._minimumStages);
                        if (num11 >= 4)
                        {
                            num11 = 4;
                            this._stages.Add(new GeoCoordinateBox(new GeoCoordinate(this._minLatitude, this._minLongitude), new GeoCoordinate(geoCoordinateBox.Center.Latitude, geoCoordinateBox.Center.Longitude)));
                            this._stages[0] = this._stages[0].Resize(num10);
                            this._stages.Add(new GeoCoordinateBox(new GeoCoordinate(this._minLatitude, geoCoordinateBox.Center.Longitude), new GeoCoordinate(geoCoordinateBox.Center.Latitude, this._maxLongitude)));
                            this._stages[1] = this._stages[1].Resize(num10);
                            this._stages.Add(new GeoCoordinateBox(new GeoCoordinate(geoCoordinateBox.Center.Latitude, this._minLongitude), new GeoCoordinate(this._maxLatitude, geoCoordinateBox.Center.Longitude)));
                            this._stages[2] = this._stages[2].Resize(num10);
                            this._stages.Add(new GeoCoordinateBox(new GeoCoordinate(geoCoordinateBox.Center.Latitude, geoCoordinateBox.Center.Longitude), new GeoCoordinate(this._maxLatitude, this._maxLongitude)));
                            this._stages[3] = this._stages[3].Resize(num10);
                        }
                        else if (num11 < 2)
                        {
                            num11 = 1;
                            this._stages.Add(geoCoordinateBox);
                            this._stages[0] = this._stages[0].Resize(num10);
                        }
                        else
                        {
                            num11 = 2;
                            this._stages.Add(new GeoCoordinateBox(new GeoCoordinate(this._minLatitude, this._minLongitude), new GeoCoordinate(this._maxLatitude, geoCoordinateBox.Center.Longitude)));
                            this._stages[0] = this._stages[0].Resize(num10);
                            this._stages.Add(new GeoCoordinateBox(new GeoCoordinate(this._minLatitude, geoCoordinateBox.Center.Longitude), new GeoCoordinate(this._maxLatitude, this._maxLongitude)));
                            this._stages[1] = this._stages[1].Resize(num10);
                        }
                    }
                    else
                    {
                        this._stages.Add(geoCoordinateBox);
                        this._stages[0] = this._stages[0].Resize(num10);
                    }
                }
                if (this._vehicles.AnyCanTraverse(way.Tags))
                {
                    for (int k = 0; k < way.Nodes.Count; k++)
                    {
                        long item2 = way.Nodes[k];
                        if (this._allRoutingNodes.Contains(item2) || this._allNodesAreCore)
                        {
                            this._coreNodes.Add(item2);
                        }
                        this._allRoutingNodes.Add(item2);
                    }
                    this._coreNodes.Add(way.Nodes[0]);
                    this._coreNodes.Add(way.Nodes[way.Nodes.Count - 1]);
                    return;
                }
            }
        }
示例#13
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));
        }
示例#14
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);
        }