コード例 #1
0
        internal static void AddTileFor(this TiledBarrierGraph graph, int vertex, Func <uint, IEnumerable <OsmGeo> > getTile,
                                        Func <TagsCollectionBase, bool> isBarrier)
        {
            var vLocation = graph.GetVertex(vertex);
            var t         = TileStatic.WorldTileLocalId(vLocation.longitude, vLocation.latitude, graph.Zoom);

            graph.AddTiles(new[] { t }, getTile, isBarrier);
        }
コード例 #2
0
        internal static void LoadForTile(this TiledBarrierGraph graph, uint tile,
                                         Func <uint, IEnumerable <OsmGeo> > getTile,
                                         Func <TagsCollectionBase, bool> isBarrier)
        {
            // mark tile as loaded.
            graph.SetTileLoaded(tile);

            // first load the tile in question.
            var tileData   = getTile(tile);
            var extraTiles = graph.Add(tileData, isBarrier);

            // add all the tiles.
            graph.AddTiles(extraTiles, getTile, isBarrier);
        }
コード例 #3
0
        public static async Task BuildForTile(uint tile, string folder, Func <uint, IEnumerable <OsmGeo> > getTile,
                                              Func <TagsCollectionBase, bool> isBarrier)
        {
            // wait until tile is removed from queue.
            while (true)
            {
                if (_tiles.ContainsKey(tile))
                {
                    await Task.Delay(200);
                }
                else
                {
                    _tiles[tile] = tile;
                    break;
                }
            }

            try
            {
                var file = Path.Combine(folder, $"{tile}.tile.graph.zip");
                if (File.Exists(file))
                {
                    return;
                }

                // load data for tile.
                var graph = new TiledBarrierGraph();
                graph.LoadForTile(tile, getTile, isBarrier);

                // run face assignment for the tile.
                var result = graph.AssignFaces(tile);
                while (!result.success)
                {
                    // extra tiles need loading.-
                    graph.AddTiles(result.missingTiles, getTile, isBarrier);

                    // try again.
                    result = graph.AssignFaces(tile);
                }

                // assign landuse.
                IEnumerable <(Polygon polygon, string type)> GetLanduse(
                    ((double longitude, double latitude)topLeft, (double longitude, double latitude)bottomRight) box)
                {
                    return(LandusePolygons.GetLandusePolygons(box, graph.Zoom, getTile, t =>
                    {
                        if (DefaultMergeFactorCalculator.Landuses.TryCalculateValue(t, out var type))
                        {
                            return type;
                        }

                        return null;
                    }));
                }

                graph.AssignLanduse(tile, GetLanduse);

                await using var stream           = File.Open(file, FileMode.Create);
                await using var compressedStream = new GZipStream(stream, CompressionLevel.Fastest);
                graph.WriteTileTo(compressedStream, tile);
            }
            finally
            {
                _tiles.Remove(tile, out _);
            }
        }