Beispiel #1
0
        public async Task <IActionResult> GetBitmapTile(int x, int y, int z, string formatExtension)
        {
            // todo for now default values. these will be passed in eventually
            var testDataPath = _configuration["TestDataPath"];

            Guid projectId;
            bool isValid = Guid.TryParse(_configuration["DefaultProjectUid"], out projectId);

            if (!isValid)
            {
                return(NotFound()); // todo
            }
            if (z < 1)
            {
                // these two tiles are standard
                // Use tiler to fetch the correct tile
                var basicTile = await new Tiler.Tiler().FetchTile(testDataPath, x, y, z);
                if (basicTile != null)
                {
                    HttpContext.Response.Headers.Add("Content-Encoding", "gzip"); // already compressed on disk
                    //   HttpContext.Response.Headers.Add("Access-Control-Allow-Origin","*"); // already compressed on disk

                    HttpContext.Response.Headers.Add("Content-Length", basicTile.Length.ToString());
                    HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream");
                    HttpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={y}.terrain");
                    return(File(basicTile, _TerrainDataQM));
                }

                Console.WriteLine($"*** Tile x:{x},y:{y},z:{z} was found ***");
                return(NotFound()); // todo
            }

            // Bitmap tiler
            BitmapDEMSource demSrc   = new BitmapDEMSource();
            var             elevData = await demSrc.GetDemXYZ(x, y, z); // DI injected for single instance

            // This class constructs a cesium quantized mesh from the dem
            var vertices = new Mesh.Mesh().MakeFakeMesh(ref elevData);

            // todo fill in header details
            var tempHeadr = new TerrainTileHeader()
            {
                MaximumHeight          = elevData.MaximumHeight,
                MinimumHeight          = elevData.MinimumHeight,
                CenterX                = elevData.CenterX,
                CenterY                = elevData.CenterY,
                CenterZ                = elevData.CenterZ,
                BoundingSphereCenterX  = elevData.BoundingSphereCenterX,
                BoundingSphereCenterY  = elevData.BoundingSphereCenterY,
                BoundingSphereCenterZ  = elevData.BoundingSphereCenterZ,
                BoundingSphereRadius   = elevData.BoundingSphereRadius,
                HorizonOcclusionPointX = elevData.HorizonOcclusionPointX,
                HorizonOcclusionPointY = elevData.HorizonOcclusionPointY,
                HorizonOcclusionPointZ = elevData.HorizonOcclusionPointZ
            };

            // This class constructs a quantized mesh tile mesh from the original mesh
            var tile = new Tiler.Tiler().MakeTile(vertices, tempHeadr, MapUtil.GridSizeToTriangleCount(elevData.GridSize),
                                                  elevData.GridSize);

            // Debugging code
            string   file = $"c:\\temp\\Test-{x}-{y}-{z}.terrain";
            FileInfo fi   = new FileInfo(file);

            if (!fi.Exists && z == 8 && x == 501)
            {
                var ms = new MemoryStream(tile);
                using (FileStream fs = new FileStream(file, FileMode.Create))
                    using (GZipStream zipStream = new GZipStream(fs, CompressionMode.Compress, false))
                    {
                        zipStream.Write(ms.ToArray(), 0, ms.ToArray().Length); // .Write(bytes, 0, bytes.Length);
                    }
            }

            if (tile != null)
            {
                var compressed = MapUtil.Compress(tile);
                HttpContext.Response.Headers.Add("Content-Encoding", "gzip"); // already compressed on disk
                HttpContext.Response.Headers.Add("Content-Length", compressed.Length.ToString());
                HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream");
                HttpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={y}.terrain");
                return(File(compressed, _TerrainDataQM));
                // return Ok(MapUtil.Compress(tile));
            }
            else
            {
                return(NotFound());
            }
        }
Beispiel #2
0
        public async Task <IActionResult> GetStaticTile(int x, int y, int z, string formatExtension, [FromQuery] Guid projectUid, [FromQuery] Guid filterUid)
        {
            // todo for now default values. these will be passed in eventually
            var testDataPath = _configuration["TestDataPath"];

            Guid projectId = projectUid;
            Guid filterid  = filterUid;
            bool isValid   = Guid.TryParse(_configuration["DefaultProjectUid"], out projectId);

            if (!isValid)
            {
                return(NotFound()); // todo
            }
            if (z < 1)              // root level
            {
                // these two tiles are standard. Use tiler to fetch the correct tile
                var basicTile = await new Tiler.Tiler().FetchTile(testDataPath, x, y, z);
                if (basicTile != null)
                {
                    HttpContext.Response.Headers.Add("Content-Encoding", "gzip"); // already compressed on disk
                    HttpContext.Response.Headers.Add("Content-Length", basicTile.Length.ToString());
                    HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream");
                    HttpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={y}.terrain");
                    return(File(basicTile, _TerrainDataQM));
                }

                Console.WriteLine($"*** Tile x:{x},y:{y},z:{z} was found ***");
                return(NotFound());
            }


            var elevData = await _demSource.GetDemXYZ(x, y, z); // DI injected for single instance

            // This class constructs a cesium quantized mesh from the dem
            var vertices = new Mesh.Mesh().MakeFakeMesh(ref elevData);

            var tempHeadr = new TerrainTileHeader()
            {
                MaximumHeight          = elevData.MaximumHeight,
                MinimumHeight          = elevData.MinimumHeight,
                CenterX                = elevData.CenterX,
                CenterY                = elevData.CenterY,
                CenterZ                = elevData.CenterZ,
                BoundingSphereCenterX  = elevData.BoundingSphereCenterX,
                BoundingSphereCenterY  = elevData.BoundingSphereCenterY,
                BoundingSphereCenterZ  = elevData.BoundingSphereCenterZ,
                BoundingSphereRadius   = elevData.BoundingSphereRadius,
                HorizonOcclusionPointX = elevData.HorizonOcclusionPointX,
                HorizonOcclusionPointY = elevData.HorizonOcclusionPointY,
                HorizonOcclusionPointZ = elevData.HorizonOcclusionPointZ
            };

            // This class constructs a quantized mesh tile mesh from the original mesh
            var tile = new Tiler.Tiler().MakeTile(vertices, tempHeadr, MapUtil.GridSizeToTriangleCount(elevData.GridSize),
                                                  elevData.GridSize);

            if (tile != null)
            {
                var compressed = MapUtil.Compress(tile);
                HttpContext.Response.Headers.Add("Content-Encoding", "gzip"); // already compressed on disk
                HttpContext.Response.Headers.Add("Content-Length", compressed.Length.ToString());
                HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream");
                HttpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={y}.terrain");
                return(File(compressed, _TerrainDataQM));
            }

            return(NotFound());
        }
Beispiel #3
0
        public async Task <IActionResult> GetFakeTile(int x, int y, int z, string formatExtension)
        {
            // todo for now default values. these will be passed in eventually
            var testDataPath = _configuration["TestDataPath"];

            Guid projectId;
            bool isValid = Guid.TryParse(_configuration["DefaultProjectUid"], out projectId);

            if (!isValid)
            {
                return(NotFound()); // todo
            }
            if (z < 1)
            {
                // these two tiles are standard
                // Use tiler to fetch the correct tile
                var basicTile = await new Tiler.Tiler().FetchTile(testDataPath, x, y, z);
                if (basicTile != null)
                {
                    HttpContext.Response.Headers.Add("Content-Encoding", "gzip"); // already compressed on disk
                    //   HttpContext.Response.Headers.Add("Access-Control-Allow-Origin","*"); // already compressed on disk

                    HttpContext.Response.Headers.Add("Content-Length", basicTile.Length.ToString());
                    HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream");
                    HttpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={y}.terrain");
                    Console.WriteLine($"*** Tile x:{x},y:{y},z:{z} was found ***");
                    return(File(basicTile, _TerrainDataQM));
                }

                return(NotFound());
            }

            FakeDEMSource demSrc = new FakeDEMSource();

            demSrc.Initalize(new MapHeader()
            {
                GridSize = _GridSize
            });

            // todo x,y,z to lat lon
            var elevData = await demSrc.GetDemLL(1, 1, 1, 1); // just the same tile always for now

            // This class constructs a cesium quantized mesh from the dem
            var vertices = new Mesh.Mesh().MakeFakeMesh(ref elevData);

            // todo fill in header details
            var tempHeadr = new TerrainTileHeader()
            {
                MaximumHeight = elevData.MaximumHeight,
                MinimumHeight = elevData.MinimumHeight
            };

            // This class constructs a quantized mesh tile mesh from the original mesh
            var tile = new Tiler.Tiler().MakeTile(vertices, tempHeadr, MapUtil.GridSizeToTriangleCount(elevData.GridSize),
                                                  elevData.GridSize);

            if (tile != null)
            {
                var compressed = MapUtil.Compress(tile);
                HttpContext.Response.Headers.Add("Content-Encoding", "gzip"); // already compressed on disk
                //   HttpContext.Response.Headers.Add("Access-Control-Allow-Origin","*"); // already compressed on disk

                HttpContext.Response.Headers.Add("Content-Length", compressed.Length.ToString());
                HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream");
                HttpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={y}.terrain");
                return(File(compressed, _TerrainDataQM));
            }
            else
            {
                return(NotFound());
            }
        }