Example #1
0
        public IActionResult GetMvt(int z, uint x, uint y)
        {
            if (z != 14)
            {
                return(NotFound());
            }

            var tile = TileStatic.ToLocalId(x, y, z);

            try
            {
                var box = TileStatic.Box(z, tile);

                var landusePolygons = LandusePolygons.GetLandusePolygons(box, z, Startup.TileSource.GetTile, t =>
                {
                    if (DefaultMergeFactorCalculator.Landuses.TryCalculateValue(t, out var type))
                    {
                        return(type);
                    }

                    return(null);
                }).Select(p => new Feature(p.polygon, new AttributesTable {
                    { "type", p.landuseType }
                }));

                var layer = new Layer {
                    Name = "landuse"
                };
                foreach (var loc in landusePolygons)
                {
                    layer.Features.Add(loc);
                }

                var vectorTile = new VectorTile
                {
                    TileId = new NetTopologySuite.IO.VectorTiles.Tiles.Tile((int)x, (int)y, z).Id
                };
                vectorTile.Layers.Add(layer);

                var memoryStream = new MemoryStream();
                vectorTile.Write(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);

                return(new FileStreamResult(memoryStream, "application/x-protobuf"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
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);
            }
        }
Example #3
0
        public IEnumerable <Feature> Get(int z, uint x, uint y)
        {
            var tile = TileStatic.ToLocalId(x, y, z);
            var box  = TileStatic.Box(z, tile);

            var landusePolygons = LandusePolygons.GetLandusePolygons(box, z, Startup.TileSource.GetTile, t =>
            {
                if (DefaultMergeFactorCalculator.Landuses.TryCalculateValue(t, out var type))
                {
                    return(type);
                }

                return(null);
            }).Select(p => new Feature(p.polygon, new AttributesTable {
                { "type", p.landuseType }
            }));

            return(landusePolygons);
        }