Example #1
0
        public IEnumerable <OsmGeo> GetTile(uint t)
        {
            // TODO: async this and use task.delay below to prevent thread starvation!

            // wait until tile is removed from queue.
            while (true)
            {
                lock (Lock)
                {
                    if (_tiles.ContainsKey(t))
                    {
                        Thread.Sleep(200);
                    }
                    else
                    {
                        _tiles[t] = t;
                        break;
                    }
                }
            }

            try
            {
                var z = 14;
                var(x, y) = TileStatic.ToTile(z, t);
                var tileUrlFormatted = _tileUrl.Replace("{x}", x.ToString())
                                       .Replace("{y}", y.ToString())
                                       .Replace("{z}", z.ToString());
                var stream = _downloader.Download(tileUrlFormatted, _cachePath);
                if (stream == null)
                {
                    return(Enumerable.Empty <OsmGeo>());
                }

                try
                {
                    return((new XmlOsmStreamSource(stream)).ToList());
                }
                catch (Exception e)
                {
                    _logger.LogWarning(e, "Failed to parse tile: {z}{x}/{y}.", 14, x, y);
                    return(Enumerable.Empty <OsmGeo>());
                }
            }
            finally
            {
                _tiles.Remove(t, out _);
            }
        }
Example #2
0
        static async Task Main(string[] args)
        {
            var logFile = Path.Combine("logs", "log-{Date}.txt");

            Log.Logger = new LoggerConfiguration()
#if DEBUG
                         .MinimumLevel.Debug()
#else
                         .MinimumLevel.Information()
#endif
                         .Enrich.FromLogContext()
                         .WriteTo.RollingFile(new JsonFormatter(), logFile)
                         .WriteTo.Console()
                         .CreateLogger();

            var cacheFolder = "/media/xivk/2T-SSD-EXT/temp";
            var tileUrl     = "https://data1.anyways.eu/tiles/full/20200628-150902/14/{x}/{y}.osm";

            var osmTileSource = new OsmTileSource(tileUrl, cacheFolder);

            bool IsBarrier(TagsCollectionBase?tags)
            {
                if (tags == null)
                {
                    return(false);
                }

                return(DefaultMergeFactorCalculator.Barriers.TryCalculateValue(tags, out _));
            }

            var box = ((4.604644775390625,
                        51.382066781130575), (4.94384765625,
                                              51.19655766797793));

            var tiles = box.TilesFor(14).Select(x => TileStatic.ToLocalId(x, 14));
            foreach (var tile in tiles)
            {
                Log.Information($"Processing tile {TileStatic.ToTile(14, tile)}...");
                await TiledBarrierGraphBuilder.BuildForTile(tile, cacheFolder, x =>
                {
                    Log.Information($"Fetching OSM data tile {TileStatic.ToTile(14, x)}...");
                    return(osmTileSource.GetTile(x));
                }, IsBarrier);
            }
        }