Example #1
0
        public int GetGLOBEElevation(string datapath, double lat, double lon)
        {
            int x, y;

            byte[] a16 = new byte[2];
            try
            {
                // get the lat/lon base values for a single tile to load
                GLOBETile tile = this.GLOBETiles.GetTileFromPoint(lat, lon);
                if (tile == null)
                {
                    return(elev_m_missing_flag); // tile is missing --> no elevation data available
                }
                if ((globebr == null) || (tile != currenttile))
                {
                    globebr     = new BinaryReader(File.OpenRead(tile.Name));
                    currenttile = tile;
                }
                x = (int)((tile.MaxLat - lat) / tile.DivLat);
                y = (int)((lon - tile.MinLon) / tile.DivLon);
                long streampos = (x * tile.Columns + y) * 2;
                globebr.BaseStream.Position = streampos;
                globebr.Read(a16, 0, 2);
                // Array.Reverse(a16);
                int e1 = BitConverter.ToInt16(a16, 0);
                if ((e1 == -32768) || (e1 == globe_elv_missing))
                {
                    e1 = elev_m_missing_flag;
                }
                if (e1 < tile.MinElv)
                {
                    e1 = tile.MinElv;
                }
                if (e1 > tile.MaxElv)
                {
                    e1 = tile.MaxElv;
                }
                return(e1);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("[" + System.Reflection.MethodBase.GetCurrentMethod().Name + "]:" + ex.Message);
            }
            return(elev_m_missing_flag);
        }
Example #2
0
        public Bitmap DrawGLOBEBitmap(GLOBETile tile)
        {
            byte[]          a16     = new byte[2];
            DEMColorPalette palette = new DEMColorPalette();

            byte[]  buffer;
            short[] Data  = new short[tile.Columns * tile.Rows];
            Bitmap  bm    = new Bitmap(tile.Columns, tile.Rows);
            int     index = 0;

            using (BinaryReader br = new BinaryReader(File.OpenRead(tile.Name)))
            {
                buffer = br.ReadBytes(Data.Length * 2);
                Buffer.BlockCopy(buffer, 0, Data, 0, buffer.Length);
                index++;
            }
            for (int i = 0; i < tile.Rows; i++)
            {
                // System.Console.WriteLine(i);
                for (int j = 0; j < tile.Columns; j++)
                {
                    int e1 = Data[(i * tile.Columns + j)];
                    if (e1 != elev_m_missing_flag)
                    {
                        double e = (double)(e1 - tile.MinElv) / (double)(tile.MaxElv - tile.MinElv) * 100.0;
                        if (e < 0)
                        {
                            e = 0;
                        }
                        if (e > 100)
                        {
                            e = 100;
                        }
                        bm.SetPixel(j, i, palette.GetColor(e));
                    }
                    else
                    {
                        bm.SetPixel(j, i, Color.FromArgb(0, 0, 128));
                    }
                }
            }
            return(bm);
        }