Exemple #1
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]);
        }
Exemple #2
0
        public static List <ICoordinate> ShapePointsTo(this RouterPoint point, RouterDb routerDb, RouterPoint other)
        {
            if ((int)point.EdgeId != (int)other.EdgeId)
            {
                throw new ArgumentException("Cannot build shape points list between router points on different edges.");
            }
            GeometricEdge      edge = routerDb.Network.GeometricGraph.GetEdge(point.EdgeId);
            double             num1 = (double)routerDb.Network.GeometricGraph.Length(edge);
            double             num2 = (double)point.Offset / (double)ushort.MaxValue;
            float              num3 = (float)(num1 * num2);
            double             num4 = (double)other.Offset / (double)ushort.MaxValue;
            float              num5 = (float)(num1 * num4);
            List <ICoordinate> shape;

            if ((double)num3 > (double)num5)
            {
                shape = routerDb.Network.GeometricGraph.GetShape(edge, num5, num3);
                shape.Reverse();
            }
            else
            {
                shape = routerDb.Network.GeometricGraph.GetShape(edge, num3, num5);
            }
            return(shape);
        }
        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;
            }
        }
Exemple #4
0
        public RoutingEdge GetEdge(uint edgeId)
        {
            GeometricEdge edge = this._graph.GetEdge(edgeId);

            OsmSharp.Routing.Data.EdgeData         edgeData = EdgeDataSerializer.Deserialize(edge.Data);
            OsmSharp.Routing.Network.Data.EdgeData data     = new OsmSharp.Routing.Network.Data.EdgeData()
            {
                MetaId   = this._edgeData[(long)edgeId],
                Distance = edgeData.Distance,
                Profile  = edgeData.Profile
            };
            return(new RoutingEdge(edge.Id, edge.From, edge.To, data, edge.DataInverted, edge.Shape));
        }
Exemple #5
0
        public static float DistanceTo(this RouterPoint point, RouterDb routerDb, uint vertex)
        {
            GeometricEdge edge = routerDb.Network.GeometricGraph.GetEdge(point.EdgeId);
            float         num1 = routerDb.Network.GeometricGraph.Length(edge);
            float         num2 = num1 * ((float)point.Offset / (float)ushort.MaxValue);

            if ((int)edge.From == (int)vertex)
            {
                return(num2);
            }
            if ((int)edge.To == (int)vertex)
            {
                return(num1 - num2);
            }
            throw new ArgumentOutOfRangeException(string.Format("Vertex {0} is not part of edge {1}.", new object[2]
            {
                (object)vertex,
                (object)point.EdgeId
            }));
        }
Exemple #6
0
        public static List <ICoordinate> ShapePointsTo(this RouterPoint point, RouterDb routerDb, uint vertex)
        {
            GeometricEdge edge        = routerDb.Network.GeometricGraph.GetEdge(point.EdgeId);
            float         num         = routerDb.Network.GeometricGraph.Length(edge);
            float         maxDistance = num * ((float)point.Offset / (float)ushort.MaxValue);

            if ((int)edge.From == (int)vertex)
            {
                List <ICoordinate> shape = routerDb.Network.GeometricGraph.GetShape(edge, vertex, maxDistance);
                shape.Reverse();
                return(shape);
            }
            if ((int)edge.To == (int)vertex)
            {
                List <ICoordinate> shape = routerDb.Network.GeometricGraph.GetShape(edge, vertex, num - maxDistance);
                shape.Reverse();
                return(shape);
            }
            throw new ArgumentOutOfRangeException(string.Format("Vertex {0} is not part of edge {1}.", new object[2]
            {
                (object)vertex,
                (object)point.EdgeId
            }));
        }
        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;
            }
        }
Exemple #8
0
        public static Path[] ToPaths(this RouterPoint point, RouterDb routerDb, Func <ushort, Factor> getFactor, bool asSource)
        {
            GeometricEdge edge = routerDb.Network.GeometricGraph.GetEdge(point.EdgeId);
            float         distance;
            ushort        profile;

            EdgeDataSerializer.Deserialize(edge.Data[0], out distance, out profile);
            Factor factor = getFactor(profile);
            float  num1   = distance;
            float  num2   = (float)point.Offset / (float)ushort.MaxValue;

            if ((int)factor.Direction == 0)
            {
                if ((double)num2 == 0.0)
                {
                    return new Path[2]
                           {
                               new Path(edge.From),
                               new Path(edge.To, num1 * (1f - num2) * factor.Value, new Path(edge.From))
                           }
                }
                ;
                if ((double)num2 == 1.0)
                {
                    return new Path[2]
                           {
                               new Path(edge.From, num1 * num2 * factor.Value, new Path(edge.To)),
                               new Path(edge.To)
                           }
                }
                ;
                return(new Path[2]
                {
                    new Path(edge.From, num1 * num2 * factor.Value, new Path(4294967294U)),
                    new Path(edge.To, num1 * (1f - num2) * factor.Value, new Path(4294967294U))
                });
            }
            if ((int)factor.Direction == 1)
            {
                if (asSource)
                {
                    if ((double)num2 == 1.0)
                    {
                        return new Path[1]
                               {
                                   new Path(edge.To)
                               }
                    }
                    ;

                    if ((double)num2 == 0.0)
                    {
                        return new Path[2]
                               {
                                   new Path(edge.From),
                                   new Path(edge.To, num1 * (1f - num2) * factor.Value, new Path(edge.From))
                               }
                    }
                    ;
                    return(new Path[1]
                    {
                        new Path(edge.To, num1 * (1f - num2) * factor.Value, new Path(4294967294U))
                    });
                }
                if ((double)num2 == 0.0)
                {
                    return new Path[1]
                           {
                               new Path(edge.From)
                           }
                }
                ;
                if ((double)num2 == 1.0)
                {
                    return new Path[2]
                           {
                               new Path(edge.To),
                               new Path(edge.From, num1 * num2 * factor.Value, new Path(edge.To))
                           }
                }
                ;
                return(new Path[1]
                {
                    new Path(edge.From, num1 * num2 * factor.Value, new Path(4294967294U))
                });
            }
            if (!asSource)
            {
                if ((double)num2 == 1.0)
                {
                    return new Path[1]
                           {
                               new Path(edge.To)
                           }
                }
                ;
                if ((double)num2 == 0.0)
                {
                    return new Path[2]
                           {
                               new Path(edge.From),
                               new Path(edge.To, num1 * (1f - num2) * factor.Value, new Path(edge.From))
                           }
                }
                ;
                return(new Path[1]
                {
                    new Path(edge.To, num1 * (1f - num2) * factor.Value, new Path(4294967294U))
                });
            }
            if ((double)num2 == 0.0)
            {
                return new Path[1]
                       {
                           new Path(edge.From)
                       }
            }
            ;
            if ((double)num2 == 1.0)
            {
                return new Path[2]
                       {
                           new Path(edge.To),
                           new Path(edge.From, num1 * num2 * factor.Value, new Path(edge.To))
                       }
            }
            ;
            return(new Path[1]
            {
                new Path(edge.From, num1 * num2 * factor.Value, new Path(4294967294U))
            });
        }