Пример #1
0
        public void TestGraphSerialize3()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var graph = GraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                            Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)),
                                                        new TagsIndex(new MemoryMappedStream(new MemoryStream())), interpreter);

            // serialize.
            using (var stream = new MemoryStream())
            {
                graph.Serialize(stream, Edge.SizeUints, Edge.MapFromDelegate, Edge.MapToDelegate);

                // deserialize.
                stream.Seek(0, SeekOrigin.Begin);
                var graphDeserialized = RouterDataSource <Edge> .Deserialize(stream, Edge.SizeUints, Edge.MapFromDelegate, Edge.MapToDelegate, false);

                // compare.
                Assert.AreEqual(graph.VertexCount, graphDeserialized.VertexCount);
                for (uint vertex = 1; vertex <= graph.VertexCount; vertex++)
                {
                    float latitude1, longitude1, latitude2, longitude2;
                    if (graph.GetVertex(vertex, out latitude1, out longitude1) &&
                        graphDeserialized.GetVertex(vertex, out latitude2, out longitude2))
                    {
                        Assert.AreEqual(latitude1, latitude2, 0.000001);
                        Assert.AreEqual(longitude1, longitude2, 0.000001);
                    }
                    var edges             = graph.GetEdges(vertex).ToKeyValuePairs();
                    var edgesDeserialized = graphDeserialized.GetEdges(vertex).ToKeyValuePairs();
                    Assert.AreEqual(edges.Length, edgesDeserialized.Length);
                    for (int idx = 0; idx < edges.Length; idx++)
                    {
                        Assert.AreEqual(edges[idx].Value.Distance, edgesDeserialized[idx].Value.Distance);
                        Assert.AreEqual(edges[idx].Value.Tags, edgesDeserialized[idx].Value.Tags);
                        Assert.AreEqual(edges[idx].Value.Forward, edgesDeserialized[idx].Value.Forward);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Deserializes the given stream into a routable graph.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="lazy"></param>
        /// <param name="vehicles"></param>
        /// <returns></returns>
        protected override RouterDataSource <CHEdgeData> DoDeserialize(LimitedStream stream, bool lazy, IEnumerable <string> vehicles)
        {
            var routerDataSource = RouterDataSource <CHEdgeData> .Deserialize(stream, CHEdgeData.SizeUints, CHEdgeData.MapFromDelegate, CHEdgeData.MapToDelegate, !lazy);

            if (vehicles != null)
            {
                foreach (var vehicleName in vehicles)
                {
                    Vehicle vehicle;
                    if (!Vehicle.TryGetByUniqueName(vehicleName, out vehicle))
                    {
                        OsmSharp.Logging.Log.TraceEvent("CHEdgeSerializer", Logging.TraceEventType.Information,
                                                        string.Format("Vehicle profile {0} not found during serialization. It won't be supported by the router.", vehicleName));
                    }
                    routerDataSource.AddSupportedProfile(vehicle);
                }
            }
            return(routerDataSource);
        }