Example #1
0
        public static void Main(string[] args)
        {
            Itinero.Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                Log.Information(string.Format("[{0}] {1} - {2}", o, level, message));
            };

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

            // load multimodal db and extract tiles.
            var multimodalDb = MultimodalDb.Deserialize(File.OpenRead(@"C:\work\data\routing\belgium.multimodaldb"));
            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()
                    {
                        SegmentLayerConfig = new SegmentLayerConfig()
                        {
                            Name = "transportation"
                        },
                        StopLayerConfig = new StopLayerConfig()
                        {
                            Name = "stops"
                        }
                    };

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

                    //Log.Information("Writing tile: {0}", t.ToInvariantString());
                    using (var stream = File.Open(t.Id.ToInvariantString() + ".mvt", FileMode.Create))
                    {
                        Itinero.VectorTiles.Mapbox.MapboxTileWriter.Write(vectorTile, stream);
                    }
                }
            });

            func.TestPerf(string.Format("Extracted and written {0} tiles.", tileRange.Count));

            Console.ReadLine();
        }
Example #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.");
        }