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; } }
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); }
public static (bool success, IEnumerable <uint> missingTiles) AssignFaces(this TiledBarrierGraph graph, uint tile) { if (!graph.HasTile(tile)) { return(false, new[] { tile }); } var tileBox = TileStatic.Box(graph.Zoom, tile); var tilesMissing = new HashSet <uint>(); graph.ResetFaces(); // the default face for the case where a loop cannot be found. var unAssignableFace = graph.AddFace(); // check each edges for faces and if missing assign them. var enumerator = graph.GetEnumerator(); for (var v = 0; v < graph.VertexCount; v++) { if (!enumerator.MoveTo(v)) { continue; } if (!enumerator.MoveNext()) { continue; } var vBox = graph.GetVertexBox(v); if (vBox == null || !vBox.Value.Overlaps(tileBox)) { continue; } // var vTile = TileStatic.WorldTileLocalId(vLocation.longitude, vLocation.latitude, graph.Zoom); // if (vTile != tile) continue; enumerator.MoveTo(v); while (enumerator.MoveNext()) { if (enumerator.Forward && enumerator.FaceRight != int.MaxValue) { continue; } if (!enumerator.Forward && enumerator.FaceLeft != int.MaxValue) { continue; } // check if the edge bbox overlaps the tiles. var eBox = enumerator.Box; if (!eBox.Overlaps(tileBox)) { continue; } // ok this edge has an undetermined face. var result = enumerator.AssignFace(unAssignableFace); if (!result.success) { tilesMissing.UnionWith(result.missingTiles); } } } if (tilesMissing.Count > 0) { return(false, tilesMissing); } return(true, Enumerable.Empty <uint>()); }