Пример #1
0
        public override async Task RunAsync(IWwtContext context, CancellationToken token)
        {
            string query = context.Request.Params["Q"];

            string[] values        = query.Split(',');
            int      level         = Convert.ToInt32(values[0]);
            int      tileX         = Convert.ToInt32(values[1]);
            int      tileY         = Convert.ToInt32(values[2]);
            int      demSize       = 33 * 33;
            int      parentL       = Math.Max(1, level - 3);
            int      DemGeneration = level - parentL;

            int count    = (int)Math.Pow(2, 3 - DemGeneration);
            int tileSize = (int)Math.Pow(2, DemGeneration);

            int offsetX = (tileX % tileSize) * count * 32;
            int offsetY = (tileY % tileSize) * count * 32;

            var parentX = tileX / tileSize;
            var parentY = tileY / tileSize;

            using var stream = await _veDownloader.DownloadVeTileAsync(VirtualEarthTile.Ecn, parentL, parentX, parentY, token);


            DemTile tile = DemCodec.Decompress(stream);

            if (tile != null)
            {
                float[] DemData = new float[demSize];
                int     yh      = 0;
                for (int yl = 0; yl < 33; yl++)
                {
                    int xh = 0;
                    for (int xl = 0; xl < 33; xl++)
                    {
                        int indexI = xl + (32 - yl) * 33;
                        DemData[indexI] = (float)tile.AltitudeInMeters(yh + offsetY, xh + offsetX);

                        xh += count;
                    }
                    yh += count;
                }

                var data = new byte[DemData.Length * 4];
                using var ms = new MemoryStream(data);
                var bw = new BinaryWriter(ms);

                foreach (float sample in DemData)
                {
                    bw.Write(sample);
                }
                bw.Flush();
                await context.Response.OutputStream.WriteAsync(data, 0, data.Length, token);
            }

            context.Response.End();
        }
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values  = query.Split(',');
            int      level   = Convert.ToInt32(values[0]);
            int      tileX   = Convert.ToInt32(values[1]);
            int      tileY   = Convert.ToInt32(values[2]);
            int      demSize = 33 * 33;
            //string wwtDemDir = ConfigurationManager.AppSettings["WWTDEMDir"];
            //string filename = String.Format(wwtDemDir  + @"\Mercator\Chunks\{0}\{1}.chunk", level, tileY);
            string urlBase = "http://ecn.t{0}.tiles.virtualearth.net/tiles/d{1}.elv?g=1&n=z";

            string    id     = WWTUtil.GetTileID(tileX, tileY, level, false);
            int       server = WWTUtil.GetServerID(tileX, tileY);
            WebClient client = new WebClient();

            string url = string.Format(urlBase, server, id);

            byte[]       data   = client.DownloadData(url);
            MemoryStream stream = new MemoryStream(data);

            DemTile tile = DemCodec.Decompress(stream);

            if (tile != null)
            {
                float[] DemData = new float[demSize];
                int     yh      = 0;
                for (int yl = 0; yl < 33; yl++)
                {
                    int xh = 0;
                    for (int xl = 0; xl < 33; xl++)
                    {
                        int indexI = xl + (32 - yl) * 33;
                        DemData[indexI] = (float)tile.AltitudeInMeters(yh, xh);
                        //  Response.Write( tile.AltitudeInMeters(yh, xh).ToString() + "\n");

                        xh += 8;
                        //Response.Write(indexI);
                    }
                    yh += 8;
                }
                data = new byte[DemData.Length * 4];
                MemoryStream ms = new MemoryStream(data);
                BinaryWriter bw = new BinaryWriter(ms);

                foreach (float sample in DemData)
                {
                    bw.Write(sample);
                }
                bw.Flush();
                context.Response.BinaryWrite(data);
            }

            context.Response.End();
        }
Пример #3
0
        public override async Task RunAsync(IWwtContext context, CancellationToken token)
        {
            string query = context.Request.Params["Q"];

            string[]  values  = query.Split(',');
            int       level   = Convert.ToInt32(values[0]);
            int       tileX   = Convert.ToInt32(values[1]);
            int       tileY   = Convert.ToInt32(values[2]);
            const int demSize = 33 * 33;

            using var stream = await _veDownloader.DownloadVeTileAsync(VirtualEarthTile.Ecn, level, tileX, tileY, token);

            DemTile tile = DemCodec.Decompress(stream);

            if (tile != null)
            {
                float[] DemData = new float[demSize];
                int     yh      = 0;
                for (int yl = 0; yl < 33; yl++)
                {
                    int xh = 0;
                    for (int xl = 0; xl < 33; xl++)
                    {
                        int indexI = xl + (32 - yl) * 33;
                        DemData[indexI] = (float)tile.AltitudeInMeters(yh, xh);

                        xh += 8;
                    }
                    yh += 8;
                }

                var data = new byte[DemData.Length * 4];
                using var ms = new MemoryStream(data);
                var bw = new BinaryWriter(ms);

                foreach (float sample in DemData)
                {
                    bw.Write(sample);
                }

                bw.Flush();
                await context.Response.OutputStream.WriteAsync(data, 0, data.Length, token);
            }

            context.Response.End();
        }