/// <summary> /// Tests preprocessing data from a PBF file. /// </summary> /// <param name="name"></param> /// <param name="pbfFile"></param> public static void TestSerialization(string name, string pbfFile) { var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile)); var performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 2000); performanceInfo.Start(); performanceInfo.Report("Pulling from {0}...", testFile.Name); var stream = testFile.OpenRead(); var source = new PBFOsmStreamSource(stream); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); var testOutputFile = new FileInfo(@"test.routing"); testOutputFile.Delete(); var writeStream = testOutputFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite); var tagsIndex = new TagsIndex(); var interpreter = new OsmRoutingInterpreter(); var graph = new RouterDataSource <Edge>(new Graph <Edge>(), tagsIndex); var routingSerializer = new RoutingDataSourceSerializer(); var memoryMappedGraph = new Graph <Edge>(1024); var coordinates = new HugeCoordinateIndex(1024); var memoryData = new RouterDataSource <Edge>(memoryMappedGraph, tagsIndex); var targetData = new GraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex, coordinates); targetData.RegisterSource(progress); targetData.Pull(); performanceInfo.Stop(); memoryData.Compress(); performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 100000); performanceInfo.Start(); performanceInfo.Report("Writing file for {0}...", testFile.Name); var metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); routingSerializer.Serialize(writeStream, memoryData, metaData); stream.Dispose(); writeStream.Dispose(); OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", OsmSharp.Logging.TraceEventType.Information, string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024)); performanceInfo.Stop(); ////performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 100000); ////performanceInfo.Start(); ////performanceInfo.Report("Reading file for {0}...", testFile.Name); //var testInputFile = new FileInfo(@"test.routing"); //var readStream = testInputFile.OpenRead(); //RoutingTest.TestSerialized(readStream); ////var deserializedGraph = routingSerializer.Deserialize(readStream, false); ////readStream.Dispose(); ////OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", OsmSharp.Logging.TraceEventType.Information, //// string.Format("Read: {0}KB", testInputFile.Length / 1024)); ////OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", Logging.TraceEventType.Information, deserializedGraph.ToInvariantString()); ////performanceInfo.Stop(); }
/// <summary> /// Tests preprocessing data from a PBF file. /// </summary> /// <param name="name"></param> /// <param name="pbfFile"></param> public static void TestSerialization(string name, string pbfFile) { var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile)); var performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000); performanceInfo.Start(); performanceInfo.Report("Pulling from {0}...", testFile.Name); var stream = testFile.OpenRead(); var source = new PBFOsmStreamSource(stream); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); var testOutputFile = new FileInfo(@"test.routing"); testOutputFile.Delete(); Stream writeStream = testOutputFile.OpenWrite(); var tagsIndex = new TagsTableCollectionIndex(); var interpreter = new OsmRoutingInterpreter(); var graph = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex); var routingSerializer = new LiveEdgeFlatfileSerializer(); // read from the OSM-stream. using (var fileFactory = new MemoryMappedFileFactory(@"d:\temp\")) { using (var memoryMappedGraph = new MemoryMappedGraph <LiveEdge>(10000, fileFactory)) { using (var coordinates = new HugeCoordinateIndex(fileFactory, 10000)) { var memoryData = new DynamicGraphRouterDataSource <LiveEdge>(memoryMappedGraph, tagsIndex); var targetData = new LiveGraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex, coordinates); targetData.RegisterSource(progress); targetData.Pull(); performanceInfo.Stop(); performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000); performanceInfo.Start(); performanceInfo.Report("Writing file for {0}...", testFile.Name); var metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); routingSerializer.Serialize(writeStream, memoryData, metaData); } } } stream.Dispose(); writeStream.Dispose(); OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information, string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024)); performanceInfo.Stop(); performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000); performanceInfo.Start(); performanceInfo.Report("Reading file for {0}...", testFile.Name); var testInputFile = new FileInfo(@"europe-latest.osm.pbf.routing"); Stream readStream = testInputFile.OpenRead(); var deserializedGraph = routingSerializer.Deserialize(readStream, false); readStream.Dispose(); OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information, string.Format("Read: {0}KB", testInputFile.Length / 1024)); OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", Logging.TraceEventType.Information, deserializedGraph.ToInvariantString()); performanceInfo.Stop(); }