/// <summary> /// Tests preprocessing data from a PBF file. /// </summary> /// <param name="name"></param> /// <param name="pbfFile"></param> public static void TestPreprocessing(string name, string pbfFile) { FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile)); Stream stream = testFile.OpenRead(); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(new PBFOsmStreamSource(stream)); var performanceInfo = new PerformanceInfoConsumer("PreProcessor", 20000); performanceInfo.Start(); performanceInfo.Report("Pulling from {0}...", testFile.Name); var tagsIndex = new TagsIndex(); // creates a tagged index. // read from the OSM-stream. var memoryData = new RouterDataSource <Edge>(new Graph <Edge>(), tagsIndex); var targetData = new GraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex); targetData.RegisterSource(progress); targetData.Pull(); stream.Dispose(); performanceInfo.Stop(); // make sure the router is still here after GC to note the memory difference. OsmSharp.Logging.Log.TraceEvent("PreProcessor", Logging.TraceEventType.Information, memoryData.ToString()); memoryData = null; GC.Collect(); }
static void Main(string[] args) { // enable logging and use the console as output. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener( new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener()); // create router. using (var source = new FileInfo(@"kempen.osm.pbf").OpenRead()) { var pbfSource = new PBFOsmStreamSource(source); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(pbfSource); var router = Router.CreateCHFrom(progress, new OsmRoutingInterpreter(), Vehicle.Car); OsmSharp.Service.Routing.ApiBootstrapper.Add("default", router); } var uri = new Uri("http://*****:*****@ http://localhost:1234"); System.Diagnostics.Process.Start("http://localhost:1234/default"); Console.ReadLine(); } }
/// <summary> /// Tests interpreting all data from a given pbf source. /// </summary> /// <param name="name"></param> /// <param name="scene"></param> /// <param name="interpreter"></param> /// <param name="pbfSource"></param> public static Stream TestInterpret(string name, MapCSSInterpreter interpreter, Scene2D scene, string pbfSource) { StyleOsmStreamSceneTarget target = new StyleOsmStreamSceneTarget( interpreter, scene, new WebMercator()); FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfSource)); Stream stream = testFile.OpenRead(); OsmStreamSource source = new PBFOsmStreamSource(stream); OsmStreamFilterProgress progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); target.RegisterSource(progress); PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name)); performanceInfo.Start(); performanceInfo.Report("Interpreting style with objects from {0}...", pbfSource.ToString()); target.Pull(); performanceInfo.Stop(); Console.Write("", scene.BackColor); stream.Dispose(); return(testFile.OpenRead()); }
/// <summary> /// Loads a routing network created from OSM data. /// </summary> public static void LoadOsmData(this RouterDb db, OsmStreamSource[] sources, LoadSettings settings, params Itinero.Profiles.Vehicle[] vehicles) { if (!db.IsEmpty) { throw new ArgumentException("Can only load a new routing network into an empty router db, add multiple streams at once to load multiple files."); } if (vehicles == null || vehicles.Length == 0) { throw new ArgumentNullException("vehicles", "A least one vehicle is needed to load OSM data."); } if (sources == null || sources.Length == 0) { throw new ArgumentNullException("sources", "A least one source is needed to load OSM data."); } if (settings == null) { settings = new LoadSettings(); } // merge sources if needed. var source = sources[0]; for (var i = 1; i < sources.Length; i++) { var merger = new OsmSharp.Streams.Filters.OsmStreamFilterMerge(); merger.RegisterSource(source); merger.RegisterSource(sources[i]); source = merger; } if (sources.Length > 1 && !(source is OsmStreamFilterProgress)) { // just one source the the callee is choosing a progress filter but assumed the default for a merged stream. var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); source = progress; } // load the data. var target = new Streams.RouterDbStreamTarget(db, vehicles, settings.AllCore, processRestrictions: settings.ProcessRestrictions, processors: settings.Processors, simplifyEpsilonInMeter: settings.NetworkSimplificationEpsilon); target.KeepNodeIds = settings.KeepNodeIds; target.RegisterSource(source); target.Pull(); // sort the network. db.Sort(); // optimize the network if requested. if (settings.NetworkSimplificationEpsilon != 0) { db.OptimizeNetwork(settings.NetworkSimplificationEpsilon); } // compress the network. db.Network.Compress(); }
/// <summary> /// Raises the OnLoad event. /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); // initialize mapcss interpreter. var mapCSSInterpreter = new MapCSSInterpreter( new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\static\default.mapcss").OpenRead(), new MapCSSDictionaryImageSource()); // initialize map. var map = new OsmSharp.UI.Map.Map(); //// initialize router. //_router = Router.CreateLiveFrom(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource( // new FileInfo(@"kempen.osm.pbf").OpenRead()), new OsmRoutingInterpreter()); var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List <float>(new float[] { 16, 14, 12, 10 })); var target = new StyleOsmStreamSceneTarget( mapCSSInterpreter, scene, new WebMercator()); var source = new XmlOsmStreamSource( new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\relive_mechelen\mechelen_new.osm").OpenRead()); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); target.RegisterSource(progress); target.Pull(); //var merger = new Scene2DObjectMerger(); //scene = merger.BuildMergedScene(scene); map.AddLayer(new LayerScene(scene)); //var dataSource = MemoryDataSource.CreateFromXmlStream( // new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\relive_mechelen\mechelen_new.osm").OpenRead()); //map.AddLayer(new LayerOsm(dataSource, mapCSSInterpreter, map.Projection)); //var layerTile = new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg", 200); //layerTile.MinZoom = 12; //layerTile.MaxZoom = 13; //map.AddLayer(layerTile); //map.AddLayer(new LayerScene( // Scene2D.Deserialize(new FileInfo(@"default.map").OpenRead(), // true))); // initialize route/points layer. _layerRoute = new LayerRoute(new OsmSharp.Math.Geo.Projections.WebMercator()); map.AddLayer(_layerRoute); _layerPrimitives = new LayerPrimitives(new OsmSharp.Math.Geo.Projections.WebMercator()); map.AddLayer(_layerPrimitives); // set control properties. this.mapControl1.Map = map; this.mapControl1.MapCenter = new GeoCoordinate(51.0167, 4.4914); // wechel this.mapControl1.MapZoom = 14; this.mapControl1.MapMouseClick += mapControl1_MapMouseClick; this.mapControl1.MapMouseMove += mapControl1_MapMouseMove; }
public static void Main(string[] args) { Native.Initialize(); // enable logging and use the console as output. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener( new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener()); // initialize mapcss interpreter. var mapCSSInterpreter = new MapCSSInterpreter( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Service.Tiles.Sample.SelfHost.custom.mapcss"), new MapCSSDictionaryImageSource()); var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List <float>(new float[] { 16, 14, 12, 10 })); var target = new StyleOsmStreamSceneTarget( mapCSSInterpreter, scene, new WebMercator()); var source = new PBFOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Service.Tiles.Sample.SelfHost.kempen.osm.pbf")); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); target.RegisterSource(progress); target.Pull(); var merger = new Scene2DObjectMerger(); scene = merger.BuildMergedScene(scene); // create a new instance (with a cache). var instance = new RenderingInstance(); instance.Map.AddLayer(new LayerScene(scene)); // add a default test instance. ApiBootstrapper.AddInstance("default", instance); // start hosting this! using (var host = new NancyHost(new Uri("http://*****:*****@ http://localhost:1234"); System.Diagnostics.Process.Start("http://localhost:1234/default"); Console.ReadLine(); } }
/// <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 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 performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 5000); performanceInfo.Start(); performanceInfo.Report("Pulling from {0}...", testFile.Name); // read from the OSM-stream. var memoryData = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex, 100000000); var targetData = new LiveGraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex); targetData.RegisterSource(progress); targetData.Pull(); var metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); var routingSerializer = new LiveEdgeFlatfileSerializer(); routingSerializer.Serialize(writeStream, memoryData, metaData); stream.Dispose(); writeStream.Dispose(); OsmSharp.Logging.Log.TraceEvent("CHSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information, string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024)); performanceInfo.Stop(); }
/// <summary> /// Loads a routing network created from OSM data. /// </summary> public static void LoadOsmData(this RouterDb db, OsmStreamSource[] sources, bool allCore = false, bool processRestrictions = true, IEnumerable <ITwoPassProcessor> processors = null, params Itinero.Profiles.Vehicle[] vehicles) { if (!db.IsEmpty) { throw new ArgumentException("Can only load a new routing network into an empty router db, add multiple streams at once to load multiple files."); } if (vehicles == null || vehicles.Length == 0) { throw new ArgumentNullException("vehicles", "A least one vehicle is needed to load OSM data."); } if (sources == null || sources.Length == 0) { throw new ArgumentNullException("sources", "A least one source is needed to load OSM data."); } // merge sources if needed. var source = sources[0]; for (var i = 1; i < sources.Length; i++) { var merger = new OsmSharp.Streams.Filters.OsmStreamFilterMerge(); merger.RegisterSource(source); merger.RegisterSource(sources[i]); source = merger; } if (sources.Length > 1 && !(source is OsmStreamFilterProgress)) { // just one source the the callee is choosing a progress filter but assumed the default for a merged stream. var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); source = progress; } // load the data. var target = new Streams.RouterDbStreamTarget(db, vehicles, allCore, processRestrictions: processRestrictions, processors: processors); target.RegisterSource(source); target.Pull(); // sort the network. db.Sort(); }
/// <summary> /// Executes reading tests. /// </summary> public static void Test() { var testFile = new FileInfo(@".\TestFiles\kempen-big.osm.pbf"); var stream = testFile.OpenRead(); var source = new PBFOsmStreamSource(stream); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); var completeSource = new OsmSharp.Osm.Streams.Complete.OsmSimpleCompleteStreamSource(progress); PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("OsmSimpleCompleteStreamSourceTests.Pull"); performanceInfo.Start(); performanceInfo.Report("Pulling from {0}...", testFile.Name); var completeObjects = new List <ICompleteOsmGeo>(completeSource); stream.Dispose(); performanceInfo.Stop(); }
/// <summary> /// Tests preprocessing data from a PBF file. /// </summary> /// <param name="name"></param> /// <param name="pbfFile"></param> public static void TestPreprocessing(string name, string pbfFile) { FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile)); Stream stream = testFile.OpenRead(); PBFOsmStreamSource source = new PBFOsmStreamSource(stream); OsmStreamFilterProgress progress = new OsmStreamFilterProgress(source); PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("LivePreProcessor"); performanceInfo.Start(); performanceInfo.Report("Pulling from {0}...", testFile.Name); var router = Router.CreateLiveFrom(progress, new OsmRoutingInterpreter()); stream.Dispose(); performanceInfo.Stop(); // make sure the route is still here after GC to note the memory difference. OsmSharp.Logging.Log.TraceEvent("LivePreProcessor", Logging.TraceEventType.Information, router.ToString()); router = null; GC.Collect(); }
/// <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> /// Loads a routing network created from OSM data. /// </summary> public static void LoadOsmDataAndShortcuts(this RouterDb db, OsmStreamSource source, LoadSettings settings, params Itinero.Profiles.Vehicle[] vehicles) { if (!db.IsEmpty) { throw new ArgumentException( "Can only load a new routing network into an empty router db, add multiple streams at once to load multiple files."); } if (vehicles == null || vehicles.Length == 0) { throw new ArgumentNullException("vehicles", "A least one vehicle is needed to load OSM data."); } if (settings == null) { settings = new LoadSettings(); } // merge sources if needed. var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); source = progress; // make sure the routerdb can handle multiple edges. db.Network.GeometricGraph.Graph.MarkAsMulti(); // load the data. var target = new RouterDbStreamTarget(db, vehicles, settings.AllCore, processRestrictions: settings.ProcessRestrictions, processors: settings.Processors, simplifyEpsilonInMeter: settings.NetworkSimplificationEpsilon); target.KeepNodeIds = settings.KeepNodeIds; target.KeepWayIds = settings.KeepWayIds; target.RegisterSource(source); target.Pull(); foreach (var profile in db.GetSupportedProfiles()) { db.AddIslandData(profile); } foreach (var vehicleType in db.GetRestrictedVehicleTypes().ToList()) { db.RemoveRestrictions(vehicleType); } db.Sort(); // // optimize the network. db.RemoveDuplicateEdges(); // db.SplitLongEdges(); db.ConvertToSimple(); AddVelo(db); // // optimize the network if requested. // if (settings.NetworkSimplificationEpsilon > 0) // { // db.OptimizeNetwork(settings.NetworkSimplificationEpsilon); // } // // compress the network. // db.Compress(); }
/// <summary> /// Loads a routing network created from OSM data. /// </summary> public static void LoadOsmData(this RouterDb db, OsmStreamSource[] sources, LoadSettings settings, params Itinero.Profiles.Vehicle[] vehicles) { if (!db.IsEmpty) { throw new ArgumentException("Can only load a new routing network into an empty router db, add multiple streams at once to load multiple files."); } if (vehicles == null || vehicles.Length == 0) { throw new ArgumentNullException("vehicles", "A least one vehicle is needed to load OSM data."); } if (sources == null || sources.Length == 0) { throw new ArgumentNullException("sources", "A least one source is needed to load OSM data."); } if (settings == null) { settings = new LoadSettings(); } // merge sources if needed. var source = sources[0]; for (var i = 1; i < sources.Length; i++) { var merger = new OsmSharp.Streams.Filters.OsmStreamFilterMerge(); merger.RegisterSource(source); merger.RegisterSource(sources[i]); source = merger; } if (sources.Length > 1 && !(source is OsmStreamFilterProgress)) { // just one source the the callee is choosing a progress filter but assumed the default for a merged stream. var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); source = progress; } // make sure the routerdb can handle multiple edges. db.Network.GeometricGraph.Graph.MarkAsMulti(); // determine normalization flag. var normalize = true; foreach (var vehicle in vehicles) { if (vehicle.Normalize) { continue; } normalize = false; break; } // load the data. var target = new Streams.RouterDbStreamTarget(db, vehicles, settings.AllCore, processRestrictions: settings.ProcessRestrictions, processors: settings.Processors, simplifyEpsilonInMeter: settings.NetworkSimplificationEpsilon); target.KeepNodeIds = settings.KeepNodeIds; target.KeepWayIds = settings.KeepWayIds; target.RegisterSource(source, normalize); target.Pull(); // optimize the network. db.RemoveDuplicateEdges(); db.SplitLongEdges(); db.ConvertToSimple(); // sort the network. db.Sort(); // optimize the network if requested. if (settings.NetworkSimplificationEpsilon > 0) { db.OptimizeNetwork(settings.NetworkSimplificationEpsilon); } // compress the network. db.Compress(); }
/// <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(); }