Beispiel #1
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .CreateLogger();


#if DEBUG
            var loggingBlacklist = new HashSet <string>();
#else
            var loggingBlacklist = new HashSet <string>();
#endif
            Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                if (loggingBlacklist.Contains(o))
                {
                    return;
                }

                if (!string.IsNullOrEmpty(o))
                {
                    message = $"[{o}] {message}";
                }

                if (level == Logging.TraceEventType.Verbose.ToString().ToLower())
                {
                    Log.Debug(message);
                }
                else if (level == Logging.TraceEventType.Information.ToString().ToLower())
                {
                    Log.Information(message);
                }
                else if (level == Logging.TraceEventType.Warning.ToString().ToLower())
                {
                    Log.Warning(message);
                }
                else if (level == Logging.TraceEventType.Critical.ToString().ToLower())
                {
                    Log.Fatal(message);
                }
                else if (level == Logging.TraceEventType.Error.ToString().ToLower())
                {
                    Log.Error(message);
                }
                else
                {
                    Log.Debug(message);
                }
            };

            // load data.
            var routerDb = BuildRouterDb.BuildOrLoad();

            // load transit db.
            var transitDb = BuildTransitDb.BuildOrLoad();

            var router = new Router(routerDb)
            {
                VerifyAllStoppable = true,
                CustomRouteBuilder = new Temp.Temp()
            };

            var antwerpen1        = new Coordinate(51.21880619138497f, 4.397792816162109f);
            var antwerpen2        = new Coordinate(51.21888683113129f, 4.432253837585449f);
            var brusselHermanTeir = new Coordinate(50.865696744357294f, 4.3497008085250854f);
            var brusselCentraal   = new Coordinate(50.83144119255431f, 4.339964389801025f);
            var lille             = new Coordinate(51.25979327802935f, 4.875869750976562f);
            var turnhout          = new Coordinate(51.3202332109125f, 4.9339234828948975f);
            var tourEnTaxis       = new Coordinate(50.86439661723841f, 4.348719120025635f);
            var marcheEnFamenne   = new Coordinate(50.23142236000259f, 5.333776473999023f);
            var ieper             = new Coordinate(50.85532180383167f, 2.860565185546875f);
//
//            var route = router.Calculate(router.Db.GetSupportedProfile("pedestrian.shortcut"),
//                antwerpen1, antwerpen2);
//            File.WriteAllText("route-antwerpen.json", route.ToGeoJson());
//
//            route = router.Calculate(router.Db.GetSupportedProfile("pedestrian.shortcut"),
//                brusselHermanTeir, brusselCentraal);
//            File.WriteAllText("route-brussel.json", route.ToGeoJson());
//

            var sourceLocation = antwerpen2;
            var targetLocation = brusselHermanTeir;

            var routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                            sourceLocation, targetLocation);
            File.WriteAllText("intermodal-route1.json", routeResult.Value.ToGeoJson());

            routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                        antwerpen2, lille);
            File.WriteAllText("intermodal-route2.json", routeResult.Value.ToGeoJson());

            routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                        turnhout, lille);
            File.WriteAllText("intermodal-route3.json", routeResult.Value.ToGeoJson());

            routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                        turnhout, marcheEnFamenne);
            File.WriteAllText("intermodal-route4.json", routeResult.Value.ToGeoJson());

            routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                        turnhout, ieper);
            File.WriteAllText("intermodal-route5.json", routeResult.Value.ToGeoJson());
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            Itinero.Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                if (level == Logging.TraceEventType.Verbose.ToString().ToLower())
                {
                    Log.Debug($"[{o}] {level} - {message}");
                }
                else if (level == Logging.TraceEventType.Information.ToString().ToLower())
                {
                    Log.Information($"[{o}] {level} - {message}");
                }
                else if (level == Logging.TraceEventType.Warning.ToString().ToLower())
                {
                    Log.Warning($"[{o}] {level} - {message}");
                }
                else if (level == Logging.TraceEventType.Critical.ToString().ToLower())
                {
                    Log.Fatal($"[{o}] {level} - {message}");
                }
                else if (level == Logging.TraceEventType.Error.ToString().ToLower())
                {
                    Log.Error($"[{o}] {level} - {message}");
                }
                else
                {
                    Log.Debug($"[{o}] {level} - {message}");
                }
            };

            // attach logger.
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .CreateLogger();

            // build router db.
            var routerDb = BuildRouterDb.Build();

            // test writing vector tiles.
            var tile      = Tiles.Tile.CreateAroundLocation(51.267966846313556f, 4.801913201808929f, 9);
            var tileRange = tile.GetSubTiles(14);

            var func = new Action(() =>
            {
                foreach (var t in tileRange)
                {
                    var config = new VectorTileConfig()
                    {
                        EdgeLayerConfigs = new List <EdgeLayerConfig>()
                        {
                            new EdgeLayerConfig()
                            {
                                Name = "cyclenetwork",
                                GetAttributesFunc = (edgeId, zoom) =>
                                {
                                    var attributes = routerDb.GetEdgeAttributes(edgeId);
                                    if (attributes == null)
                                    {
                                        return(null);
                                    }

                                    var ok = attributes.Any(a => a.Key == "cyclenetwork");
                                    if (!ok)
                                    {
                                        return(null);
                                    }

                                    return(attributes);
                                }
                            }
                        },
                        VertexLayerConfigs = new List <VertexLayerConfig>()
                        {
                            new VertexLayerConfig()
                            {
                                Name = "cyclenodes",
                                GetAttributesFunc = (vertex, zoom) =>
                                {
                                    var attributes = routerDb.GetVertexAttributes(vertex);
                                    var ok         = attributes.Any(a => a.Key == "rcn_ref");
                                    if (!ok)
                                    {
                                        return(null);
                                    }

                                    return(attributes);
                                }
                            }
                        }
                    };

                    Log.Information("Extracting tile: {0}", t.ToInvariantString());
                    var vectorTile = routerDb.ExtractTile(t.Id, config);

                    if (vectorTile.IsEmpty)
                    {
                        continue;
                    }

                    Log.Information("Writing tile: {0}", t.ToInvariantString());
                    var fileInfo = new FileInfo(Path.Combine("tiles", t.Zoom.ToString(), t.X.ToString(), $"{t.Y}.mvt"));
                    if (!fileInfo.Directory.Exists)
                    {
                        fileInfo.Directory.Create();
                    }

                    using (var stream = fileInfo.Open(FileMode.Create))
                    {
                        Itinero.VectorTiles.Mapbox.MapboxTileWriter.Write(vectorTile, stream);
                    }
                }
            });

            func.TestPerf($"Extracted and written {tileRange.Count} tiles.");
        }