예제 #1
0
        public static TagsCollectionBase GetProfileAndMeta(this RouterDb db, uint profileId, uint meta)
        {
            TagsCollection     tagsCollection1 = new TagsCollection();
            TagsCollectionBase tagsCollection2 = db.EdgeMeta.Get(meta);

            if (tagsCollection2 != null)
            {
                tagsCollection1.AddOrReplace(tagsCollection2);
            }
            TagsCollectionBase tagsCollection3 = db.EdgeProfiles.Get(profileId);

            if (tagsCollection3 != null)
            {
                tagsCollection1.AddOrReplace(tagsCollection3);
            }
            return((TagsCollectionBase)tagsCollection1);
        }
예제 #2
0
        public static void AddContracted(this RouterDb db, Profile profile)
        {
            DirectedMetaGraph directedMetaGraph = (DirectedMetaGraph)null;

            lock (db)
            {
                directedMetaGraph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize);
                new DirectedGraphBuilder(db.Network.GeometricGraph.Graph, directedMetaGraph, (Func <ushort, Factor>)(p => profile.Factor(db.EdgeProfiles.Get((uint)p)))).Run();
            }
            new HierarchyBuilder(directedMetaGraph, (IPriorityCalculator) new EdgeDifferencePriorityCalculator(directedMetaGraph, (IWitnessCalculator) new DykstraWitnessCalculator(int.MaxValue))
            {
                DifferenceFactor = 5,
                DepthFactor      = 5,
                ContractedFactor = 8
            }, (IWitnessCalculator) new DykstraWitnessCalculator(int.MaxValue)).Run();
            lock (db)
                db.AddContracted(profile, directedMetaGraph);
        }
예제 #3
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
            }));
        }
예제 #4
0
        public static FeatureCollection GetFeatures(this RouterDb db)
        {
            RoutingNetwork    network           = db.Network;
            FeatureCollection featureCollection = new FeatureCollection();
            HashSet <long>    longSet           = new HashSet <long>();

            RoutingNetwork.EdgeEnumerator edgeEnumerator = network.GetEdgeEnumerator();
            for (uint vertex1 = 0; vertex1 < network.VertexCount; ++vertex1)
            {
                GeoCoordinateSimple vertex2 = network.GeometricGraph.GetVertex(vertex1);
                featureCollection.Add(new Feature((Geometry) new Point(new GeoCoordinate((double)vertex2.Latitude, (double)vertex2.Longitude)), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>) new Tag[1]
                {
                    Tag.Create("id", vertex1.ToInvariantString())
                })));
                edgeEnumerator.MoveTo(vertex1);
                edgeEnumerator.Reset();
                while (edgeEnumerator.MoveNext())
                {
                    if (!longSet.Contains((long)edgeEnumerator.Id))
                    {
                        longSet.Add((long)edgeEnumerator.Id);
                        List <ICoordinate>   shape             = network.GetShape(edgeEnumerator.Current);
                        List <GeoCoordinate> geoCoordinateList = new List <GeoCoordinate>();
                        foreach (ICoordinate coordinate in shape)
                        {
                            geoCoordinateList.Add(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude));
                        }
                        LineString         lineString     = new LineString((IEnumerable <GeoCoordinate>)geoCoordinateList);
                        TagsCollectionBase profileAndMeta = db.GetProfileAndMeta((uint)edgeEnumerator.Data.Profile, edgeEnumerator.Data.MetaId);
                        profileAndMeta.AddOrReplace(Tag.Create("id", edgeEnumerator.Id.ToInvariantString()));
                        featureCollection.Add(new Feature((Geometry)lineString, (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>)profileAndMeta)));
                    }
                }
            }
            return(featureCollection);
        }
예제 #5
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
            }));
        }
예제 #6
0
 public static RouterDb Deserialize(Stream stream)
 {
     return(RouterDb.Deserialize(stream, (RouterDbProfile)null));
 }
예제 #7
0
 public Router(RouterDb db)
 {
     this._db = db;
     this.VerifyAllStoppable = false;
 }
예제 #8
0
 public static Path PathTo(this RouterPoint point, RouterDb db, Profile profile, RouterPoint target)
 {
     return(point.PathTo(db, (Func <ushort, Factor>)(p => profile.Factor(db.EdgeProfiles.Get((uint)p))), target));
 }
예제 #9
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))
            });
        }
예제 #10
0
 public static Path[] ToPaths(this RouterPoint point, RouterDb routerDb, Profile profile, bool asSource)
 {
     return(point.ToPaths(routerDb, (Func <ushort, Factor>)(p => profile.Factor(routerDb.EdgeProfiles.Get((uint)p))), asSource));
 }