/// <summary> /// Tests building a router db. /// </summary> public static Func <PerformanceTestResult <RouterDb> > GetTestBuildRouterDb(string file, bool allcore, bool processRestrictions, params Vehicle[] vehicles) { return(() => { OsmStreamSource source; using (var stream = File.OpenRead(file)) { var routerdb = new RouterDb(); if (file.ToLowerInvariant().EndsWith("osm.pbf")) { source = new OsmSharp.Streams.PBFOsmStreamSource(stream); } else { source = new OsmSharp.Streams.XmlOsmStreamSource(stream); } var progress = new OsmSharp.Streams.Filters.OsmStreamFilterProgress(); progress.RegisterSource(source); routerdb.LoadOsmData(progress, new LoadSettings() { AllCore = allcore, ProcessRestrictions = processRestrictions, OptimizeNetwork = true, NetworkSimplificationEpsilon = 1, KeepNodeIds = true }, vehicles); return new PerformanceTestResult <RouterDb>(routerdb); } }); }
/// <summary> /// Tests building a router db. /// </summary> public static Func <RouterDb> GetTestBuildRouterDb(string file, bool allcore, bool processRestrictions, params Vehicle[] vehicles) { return(() => { OsmStreamSource source; using (var stream = File.OpenRead(file)) { var routerdb = new RouterDb(); if (file.ToLowerInvariant().EndsWith("osm.pbf")) { source = new OsmSharp.Streams.PBFOsmStreamSource(stream); } else { source = new OsmSharp.Streams.XmlOsmStreamSource(stream); } var progress = new OsmSharp.Streams.Filters.OsmStreamFilterProgress(); progress.RegisterSource(source); routerdb.LoadOsmData(progress, allcore, processRestrictions, vehicles); return routerdb; } }); }
public static void Main(string[] args) { // enable logging. OsmSharp.Logging.Logger.LogAction = (o, level, message, parameters) => { Console.WriteLine(string.Format("[{0}-{3}] {1} - {2}", o, level, message, DateTime.Now.ToString())); }; // download and extract test-data if not already there. OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Downloading PBF..."); Download.DownloadAll(); // create a source. var source = new OsmSharp.Streams.PBFOsmStreamSource(File.OpenRead(Download.Local)); // loop over all objects and count them. int nodes = 0, ways = 0, relations = 0; var testAction = new Action(() => { foreach (var osmGeo in source) { if (osmGeo.Type == OsmGeoType.Node) { nodes++; } if (osmGeo.Type == OsmGeoType.Way) { ways++; } if (osmGeo.Type == OsmGeoType.Relation) { relations++; } } }); testAction.TestPerf("Test counting objects."); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Counted {0} nodes, {1} ways and {2} relations.", nodes, ways, relations); // loop over all objects and count them ignoring nodes. nodes = 0; ways = 0; relations = 0; source.Reset(); testAction = new Action(() => { foreach (var osmGeo in source.EnumerateAndIgore(true, false, false)) { if (osmGeo.Type == OsmGeoType.Node) { nodes++; } if (osmGeo.Type == OsmGeoType.Way) { ways++; } if (osmGeo.Type == OsmGeoType.Relation) { relations++; } } }); testAction.TestPerf("Test counting objects without nodes."); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Counted {0} nodes, {1} ways and {2} relations.", nodes, ways, relations); // loop over all objects and count them ignoring nodes. nodes = 0; ways = 0; relations = 0; source.Reset(); testAction = new Action(() => { foreach (var osmGeo in source.EnumerateAndIgore(true, true, false)) { if (osmGeo.Type == OsmGeoType.Node) { nodes++; } if (osmGeo.Type == OsmGeoType.Way) { ways++; } if (osmGeo.Type == OsmGeoType.Relation) { relations++; } } }); testAction.TestPerf("Test counting objects without nodes and ways."); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Counted {0} nodes, {1} ways and {2} relations.", nodes, ways, relations); // write a compressed PBF. source.Reset(); testAction = new Action(() => { using (var output = File.Open("output.osm.pbf", FileMode.Create)) { var target = new OsmSharp.Streams.PBFOsmStreamTarget(output, true); target.RegisterSource(source); target.Pull(); } }); testAction.TestPerf("Test writing a PBF."); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Written PBF."); // test converting to complete. source.Reset(); testAction = new Action(() => { var filteredQuery = from osmGeo in source where osmGeo.Type == OsmGeoType.Way && osmGeo.Tags.ContainsKey("highway") && !osmGeo.Tags.Contains("highway", "cycleway") && !osmGeo.Tags.Contains("highway", "bus_stop") && !osmGeo.Tags.Contains("highway", "street_lamp") && !osmGeo.Tags.Contains("highway", "path") && !osmGeo.Tags.Contains("highway", "turning_cycle") && !osmGeo.Tags.Contains("highway", "traffic_signals") && !osmGeo.Tags.Contains("highway", "stops") && !osmGeo.Tags.Contains("highway", "pedestrian") && !osmGeo.Tags.Contains("highway", "footway") || osmGeo.Type == OsmGeoType.Node select osmGeo; var collectionComplete = filteredQuery.ToComplete(); var completeWays = collectionComplete.Where(x => x.Type == OsmGeoType.Way).ToList(); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Found {0} complete ways.", completeWays.Count); }); testAction.TestPerf("Test converting to complete ways."); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Converted completed ways."); // regression test for indexing names. source.Reset(); testAction = new Action(() => { var completeSource = new OsmSimpleCompleteStreamSource(source); var namesDictionary = completeSource .Where(o => string.IsNullOrWhiteSpace(o.Tags.GetValue("name")) == false) .GroupBy(o => o.Tags.GetValue("name")) .ToDictionary(g => g.Key, g => g.ToList()); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Indexed {0} names.", namesDictionary.Count); }); testAction.TestPerf("Test indexing names."); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Indexed names."); OsmSharp.Logging.Logger.Log("Program", TraceEventType.Information, "Testing finished."); #if DEBUG Console.ReadLine(); #endif }
static void Main(string[] args) { //#if DEBUG if (args == null || args.Length == 0) { args = new string[] { @"/data/work/data/OSM/belgium-latest.osm.pbf", @"/data/work/openplannerteam/data/tilesdb/", @"14" }; } //#endif // enable logging. OsmSharp.Logging.Logger.LogAction = (origin, level, message, parameters) => { var formattedMessage = $"{origin} - {message}"; switch (level) { case "critical": Log.Fatal(formattedMessage); break; case "error": Log.Error(formattedMessage); break; case "warning": Log.Warning(formattedMessage); break; case "verbose": Log.Verbose(formattedMessage); break; case "information": Log.Information(formattedMessage); break; default: Log.Debug(formattedMessage); break; } }; Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() .WriteTo.Console() .WriteTo.File(Path.Combine("logs", "log-.txt"), rollingInterval: RollingInterval.Day) .CreateLogger(); // try // { // validate arguments. if (args.Length < 3) { Log.Fatal("Expected 3 arguments: inputfile outputdir zoom"); return; } if (!File.Exists(args[0])) { Log.Fatal("Input file not found: {0}", args[0]); return; } if (!Directory.Exists(args[1])) { Log.Fatal("Cache directory doesn't exist: {0}", args[1]); return; } if (!uint.TryParse(args[2], out var zoom)) { Log.Fatal("Can't parse zoom: {0}", args[2]); return; } var ticks = DateTime.Now.Ticks; const bool compressed = false; if (!File.Exists(Path.Combine(args[1], "0", "0", "0.nodes.idx"))) { Log.Information("Building the tiled DB..."); var source = new OsmSharp.Streams.PBFOsmStreamSource( File.OpenRead(args[0])); var progress = new OsmSharp.Streams.Filters.OsmStreamFilterProgress(); progress.RegisterSource(source); // filter out routeable data only. var nodeIndex = new OsmIdIndex(); while (progress.MoveNext(true, false, true)) { if (!(progress.Current() is Way w) || w.Nodes == null) { continue; } if (w.Tags == null || !w.Tags.ContainsKey("highway")) { continue; } foreach (var n in w.Nodes) { nodeIndex.Add(n); } } var filtered = new OsmEnumerableStreamSource(progress.Where(x => { if (x is Node) { return(nodeIndex.Contains(x.Id.Value)); } else if (x is Way) { return(x.Tags != null && x.Tags.ContainsKey("highway")); } else { if (x.Tags == null) { return(false); } return(x.Tags.ContainsKey("route") || x.Tags.ContainsKey("restriction")); } })); // splitting tiles and writing indexes. Build.Builder.Build(filtered, args[1], zoom, compressed); } else { Log.Error("The tiled DB already exists, cannot overwrite, delete it first..."); } // } // catch (Exception e) // { // Log.Fatal(e, "Unhandled exception."); // throw; // } }