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();
        }
Exemple #2
0
        public override void Run(IWwtContext context)
        {
            string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"];
            string dsstoastpng = WWTUtil.GetCurrentConfigShare("DSSTOASTPNG", true);

            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    octsetlevel = level;
            string filename;

            if (level > 20)
            {
                context.Response.Write("No image");
                context.Response.Close();
                return;
            }

            if (level < 8)
            {
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\BmngMerBase.plate", level, tileX, tileY);
                int    length = (int)s.Length;
                byte[] data   = new byte[length];
                s.Read(data, 0, length);
                context.Response.OutputStream.Write(data, 0, length);
                context.Response.Flush();
                context.Response.End();
                return;
            }
            else if (level < 10)
            {
                int    L           = level;
                int    X           = tileX;
                int    Y           = tileY;
                string mime        = "png";
                int    powLev5Diff = (int)Math.Pow(2, L - 2);
                int    X32         = X / powLev5Diff;
                int    Y32         = Y / powLev5Diff;
                filename = string.Format(wwtTilesDir + @"\BmngMerL2X{1}Y{2}.plate", mime, X32, Y32);

                int L5 = L - 2;
                int X5 = X % powLev5Diff;
                int Y5 = Y % powLev5Diff;
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(filename, L5, X5, Y5);
                int    length = (int)s.Length;
                byte[] data   = new byte[length];
                s.Read(data, 0, length);
                context.Response.OutputStream.Write(data, 0, length);
                context.Response.Flush();
                context.Response.End();
                return;
            }

            System.Net.WebClient client = new System.Net.WebClient();


            string url = String.Format("http://a{0}.ortho.tiles.virtualearth.net/tiles/a{1}.jpeg?g=15", WWTUtil.GetServerID(tileX, tileY), WWTUtil.GetTileID(tileX, tileY, level, false));

            byte[] dat = client.DownloadData(url);


            client.Dispose();

            context.Response.OutputStream.Write(dat, 0, dat.Length);
        }
        public override void Run(IWwtContext context)
        {
            string wwtTilesDir  = ConfigurationManager.AppSettings["WWTTilesDir"];
            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);
            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]);
            string   filename = String.Format(DSSTileCache + "\\EarthBlend\\level{0}\\{2}\\{1}_{2}.jpg", level, tileX, tileY);
            string   path     = String.Format(DSSTileCache + "\\EarthBlend\\level{0}\\{2}", level, tileX, tileY);

            if (level > 20)
            {
                context.Response.Write("No image");
                context.Response.Close();
                return;
            }

            if (level < 8)
            {
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\BmngMerBase.plate", level, tileX, tileY);
                int    length = (int)s.Length;
                byte[] data   = new byte[length];
                s.Read(data, 0, length);
                context.Response.OutputStream.Write(data, 0, length);
                context.Response.Flush();
                context.Response.End();
                return;
            }
            else if (level == 8)
            {
                int    L           = level;
                int    X           = tileX;
                int    Y           = tileY;
                string mime        = "png";
                int    powLev5Diff = (int)Math.Pow(2, L - 2);
                int    X32         = X / powLev5Diff;
                int    Y32         = Y / powLev5Diff;
                filename = string.Format(wwtTilesDir + @"\BmngMerL2X{1}Y{2}.plate", mime, X32, Y32);

                int L5 = L - 2;
                int X5 = X % powLev5Diff;
                int Y5 = Y % powLev5Diff;
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(filename, L5, X5, Y5);
                int    length = (int)s.Length;
                byte[] data   = new byte[length];
                s.Read(data, 0, length);
                context.Response.OutputStream.Write(data, 0, length);
                context.Response.Flush();
                context.Response.End();
                return;
            }
            else if (level == 9)
            {
                if (!File.Exists(filename))
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    int    L             = level;
                    int    X             = tileX;
                    int    Y             = tileY;
                    string mime          = "png";
                    int    powLev5Diff   = (int)Math.Pow(2, L - 2);
                    int    X32           = X / powLev5Diff;
                    int    Y32           = Y / powLev5Diff;
                    string platefilename = string.Format(wwtTilesDir + @"\BmngMerL2X{1}Y{2}.plate", mime, X32, Y32);

                    int L5 = L - 2;
                    int X5 = X % powLev5Diff;
                    int Y5 = Y % powLev5Diff;

                    float[][] ptsArray =
                    {
                        new float[] { 1, 0, 0,    0, 0 },
                        new float[] { 0, 1, 0,    0, 0 },
                        new float[] { 0, 0, 1,    0, 0 },
                        new float[] { 0, 0, 0, 0.5f, 0 },
                        new float[] { 0, 0, 0,    0, 1 }
                    };
                    ColorMatrix     clrMatrix     = new ColorMatrix(ptsArray);
                    ImageAttributes imgAttributes = new ImageAttributes();
                    imgAttributes.SetColorMatrix(clrMatrix,
                                                 ColorMatrixFlag.Default,
                                                 ColorAdjustType.Bitmap);
                    context.Response.ContentType = "image/png";
                    Stream s = PlateTilePyramid.GetFileStream(platefilename, L5, X5, Y5);

                    Bitmap   bmp = new Bitmap(s);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    string   tempName = WWTUtil.DownloadVeTile(level, tileX, tileY, false);
                    FileInfo fi       = new FileInfo(tempName);
                    if (fi.Length != 0 && fi.Length != 1033)
                    {
                        Bitmap temp = new Bitmap(tempName);

                        g.DrawImage(temp, new Rectangle(0, 0, 256, 256), 0, 0, 256, 256, GraphicsUnit.Pixel, imgAttributes);
                        temp.Dispose();
                    }
                    g.Dispose();
                    bmp.Save(filename, ImageFormat.Jpeg);
                    bmp.Dispose();
                }

                context.Response.WriteFile(filename);
                return;
            }


            System.Net.WebClient client = new System.Net.WebClient();


            string url = String.Format("http://a{0}.ortho.tiles.virtualearth.net/tiles/a{1}.jpeg?g=15", WWTUtil.GetServerID(tileX, tileY), WWTUtil.GetTileID(tileX, tileY, level, false));

            byte[] dat = client.DownloadData(url);


            client.Dispose();

            context.Response.OutputStream.Write(dat, 0, dat.Length);
        }