Exemple #1
0
 public JSONArraySRTM1(SRTM1Dictionary SRTM1)
 {
     version    = SRTM1.Version;
     full_count = SRTM1.Tiles.Count;
     tiles      = new List <List <string> >();
     for (int i = 0; i < full_count; i++)
     {
         List <string>       l    = new List <string>();
         SRTM1TileDesignator tile = SRTM1.Tiles.Values.ElementAt(i);
         l.Add(tile.FileIndex);
         l.Add(tile.FileName);
         l.Add(tile.MinLat.ToString("F8", CultureInfo.InvariantCulture));
         l.Add(tile.MaxLat.ToString("F8", CultureInfo.InvariantCulture));
         l.Add(tile.MinLon.ToString("F8", CultureInfo.InvariantCulture));
         l.Add(tile.MaxLon.ToString("F8", CultureInfo.InvariantCulture));
         l.Add(tile.MinElv.ToString());
         l.Add(tile.MaxElv.ToString());
         l.Add(tile.Rows.ToString());
         l.Add(tile.Columns.ToString());
         l.Add(tile.URL.ToString());
         l.Add(tile.Status.ToString());
         l.Add(tile.Local.ToString());
         l.Add(tile.LastUpdated.ToString("u"));
         tiles.Add(l);
     }
 }
Exemple #2
0
        public void DownloadTile(SRTM1TileDesignator tile)
        {
            if (tile == null)
            {
                return;
            }
            if (String.IsNullOrEmpty(tile.URL))
            {
                return;
            }
            AutoDecompressionWebClient cl = new AutoDecompressionWebClient();
            string filename = Path.GetFileName(tile.URL.Substring(tile.URL.LastIndexOf('/')));

            cl.DownloadFile(tile.URL, Path.Combine(Properties.Settings.Default.SRTM1_DataPath, filename));
        }
Exemple #3
0
        public SRTM1TileDesignator GetTileFromPoint(double lat, double lon)
        {
            // get the lat/lon base values for a single tile to load
            int latbase = (int)Math.Floor(lat);
            int lonbase = (int)Math.Floor(lon);
            // calculate index
            string index = String.Concat((lat > 0) ? "N" : "S", Math.Abs(latbase).ToString("00")) +
                           String.Concat((lon > 0) ? "E" : "W", Math.Abs(lonbase).ToString("000"));
            SRTM1TileDesignator tile = null;

            if (Tiles.TryGetValue(index, out tile))
            {
                if (tile.Local)
                {
                    return(tile);
                }
            }
            return(null);
        }
Exemple #4
0
 public void FromTable(DataTable dt)
 {
     if (dt == null)
     {
         return;
     }
     this.Clear();
     foreach (DataRow row in dt.Rows)
     {
         string          index       = row["FileIndex"].ToString();
         string          filename    = row["FileName"].ToString();
         double          minlat      = System.Convert.ToDouble(row["MinLat"]);
         double          maxlat      = System.Convert.ToDouble(row["MaxLat"]);
         double          minlon      = System.Convert.ToDouble(row["MinLon"]);
         double          maxlon      = System.Convert.ToDouble(row["MaxLon"]);
         int             minelv      = System.Convert.ToInt32(row["MinElv"]);
         int             maxelv      = System.Convert.ToInt32(row["MaxElv"]);
         int             rows        = System.Convert.ToInt32(row["Rows"]);
         int             columns     = System.Convert.ToInt32(row["Columns"]);
         int             version     = System.Convert.ToInt32(row["Version"]);
         string          url         = row["URL"].ToString();
         SRTM1TILESTATUS status      = (SRTM1TILESTATUS)Enum.Parse(typeof(SRTM1TILESTATUS), row["Status"].ToString());
         bool            local       = System.Convert.ToBoolean(row["Local"]);
         DateTime        lastupdated = DateTime.UtcNow;
         try
         {
             try
             {
                 lastupdated = DateTime.ParseExact(row["LastUpdated"].ToString(), "yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture);
                 lastupdated = lastupdated.ToUniversalTime();
             }
             catch
             {
             }
             SRTM1TileDesignator tile = new SRTM1TileDesignator(index, filename, minlat, maxlat, minlon, maxlon, minelv, maxelv, rows, columns, version, url, status, local, lastupdated);
             this.Tiles.Add(tile.FileIndex, tile);
         }
         catch
         {
         }
     }
 }
Exemple #5
0
 private void CalcMinMaxElevation(ref SRTM1TileDesignator tile)
 {
     try
     {
         // open file to get more information
         if (tile.Local && ((tile.MinElv == int.MaxValue) || (tile.MaxElv == int.MinValue)))
         {
             using (BinaryReader br = new BinaryReader(File.OpenRead(tile.FileName)))
             {
                 tile.MinElv = int.MaxValue;
                 tile.MaxElv = int.MinValue;
                 long l = br.BaseStream.Length / 2;
                 for (int i = 0; i < l; i++)
                 {
                     byte[] a16 = new byte[2];
                     br.Read(a16, 0, 2);
                     Array.Reverse(a16);
                     short s = BitConverter.ToInt16(a16, 0);
                     if (s < elv_missing_flag)
                     {
                         s = (short)elv_missing_flag;
                     }
                     if (s != elv_missing_flag)
                     {
                         if (s < tile.MinElv)
                         {
                             tile.MinElv = s;
                         }
                         if (s > tile.MaxElv)
                         {
                             tile.MaxElv = s;
                         }
                     }
                 }
                 Application.DoEvents();
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Exemple #6
0
 private void GetAllTilesFromLocalDir()
 {
     // return empty dictionary if path not found
     if (!Directory.Exists(global::ScoutBase.Data.Properties.Settings.Default.SRTM1_DataPath))
     {
         return;
     }
     LocalTiles.Clear();
     FileInfo[] SRTM1files = new DirectoryInfo(global::ScoutBase.Data.Properties.Settings.Default.SRTM1_DataPath).GetFiles("???????.hgt");
     foreach (FileInfo file in SRTM1files)
     {
         try
         {
             SRTM1TileDesignator tile = GetTileInfoFromFile(file.FullName);
             if (tile != null)
             {
                 // valid tile found, complete tile information
                 // check min/max info
                 if ((tile.MaxElv == int.MinValue) || (tile.MinElv == int.MaxValue))
                 {
                     // try to get cached min/max info
                     SRTM1TileDesignator oldtile;
                     if (Tiles.TryGetValue(tile.FileIndex, out oldtile))
                     {
                         tile.MinElv = oldtile.MinElv;
                         tile.MaxElv = oldtile.MaxElv;
                     }
                     // still no min/max info?
                     if ((tile.MaxElv == int.MinValue) || (tile.MinElv == int.MaxValue))
                     {
                         // calculate min/max elevation
                         CalcMinMaxElevation(ref tile);
                     }
                 }
                 LocalTiles.Add(tile.FileIndex, tile);
             }
         }
         catch
         {
         }
     }
 }
Exemple #7
0
        public DataRow NewRow(SRTM1TileDesignator tile)
        {
            DataRow row = this.NewRow();

            row["FileIndex"]   = tile.FileIndex;
            row["Filename"]    = tile.FileName;
            row["MinLat"]      = tile.MinLat;
            row["MaxLat"]      = tile.MaxLat;
            row["MinLon"]      = tile.MinLon;
            row["MaxLon"]      = tile.MaxLon;
            row["MinElv"]      = tile.MinElv;
            row["MaxElv"]      = tile.MaxElv;
            row["Rows"]        = tile.Rows;
            row["Columns"]     = tile.Columns;
            row["Version"]     = tile.Version;
            row["URL"]         = tile.URL;
            row["Status"]      = tile.Status.ToString();
            row["Local"]       = tile.Local;
            row["LastUpdated"] = tile.LastUpdated.ToString("u");
            return(row);
        }
Exemple #8
0
        public void Update(SRTM1TileDesignator tile)
        {
            // return on null
            if (tile == null)
            {
                return;
            }
            SRTM1TileDesignator entry = null;

            lock (this)
            {
                if (Tiles.TryGetValue(tile.FileIndex, out entry))
                {
                    entry.FileIndex   = tile.FileIndex;
                    entry.FileName    = tile.FileName;
                    entry.MinLat      = tile.MinLat;
                    entry.MaxLat      = tile.MaxLat;
                    entry.MinLon      = tile.MinLon;
                    entry.MaxLon      = tile.MaxLon;
                    entry.MinElv      = tile.MinElv;
                    entry.MaxElv      = tile.MaxElv;
                    entry.Rows        = tile.Rows;
                    entry.Columns     = tile.Columns;
                    entry.Version     = tile.Version;
                    entry.URL         = tile.URL;
                    entry.Status      = tile.Status;
                    entry.Local       = tile.Local;
                    entry.LastUpdated = tile.LastUpdated;
                    changed           = true;
                }
                else
                {
                    this.Tiles.Add(tile.FileIndex, new SRTM1TileDesignator(tile.FileIndex, tile.FileName, tile.MinLat, tile.MaxLat, tile.MinLon, tile.MaxLon, tile.MinElv, tile.MaxElv, tile.Rows, tile.Columns, tile.Version, tile.URL, tile.Status, tile.Local, tile.LastUpdated));
                    changed = true;
                }
            }
        }
Exemple #9
0
 private void GetAllTilesFromWeb()
 {
     // check for valid urls
     if (string.IsNullOrEmpty(global::ScoutBase.Data.Properties.Settings.Default.SRTM1_URLs))
     {
         return;
     }
     // load tiles from web only once
     if (WebTiles.Count > 0)
     {
         return;
     }
     try
     {
         // split urls if necessary
         string[] SRTM1urls;
         if (global::ScoutBase.Data.Properties.Settings.Default.SRTM1_URLs.Contains("\r\n"))
         {
             SRTM1urls = global::ScoutBase.Data.Properties.Settings.Default.SRTM1_URLs.Split(new string[] { "\r\n" }, StringSplitOptions.None);
         }
         else
         {
             SRTM1urls    = new string[1];
             SRTM1urls[0] = global::ScoutBase.Data.Properties.Settings.Default.SRTM1_URLs;
         }
         // create a searchable index of all available tiles from web
         SortedDictionary <string, string> urls = new SortedDictionary <string, string>();
         foreach (string url in SRTM1urls)
         {
             HTTPDirectorySearcher    s = new HTTPDirectorySearcher();
             List <HTTPDirectoryItem> l = s.GetDirectoryInformation(url);
             foreach (HTTPDirectoryItem item in l)
             {
                 try
                 {
                     // find possible file names
                     if (item.Name.Contains(".zip"))
                     {
                         urls.Add(item.Name.Split('.')[0].ToUpper(), item.AbsolutePath);
                     }
                 }
                 catch
                 {
                 }
             }
         }
         // initally generate tile info
         for (int lat = -90; lat < 90; lat++)
         {
             for (int lon = -180; lon < 180; lon++)
             {
                 string index = ((lat < 0) ? "S" + Math.Abs(lat).ToString("00") : "N" + Math.Abs(lat).ToString("00"))
                                + ((lon < 0) ? "W" + Math.Abs(lon).ToString("000") : "E" + Math.Abs(lon).ToString("000"));
                 SRTM1TileDesignator tile = new SRTM1TileDesignator(index, "", (double)lat, (double)lat + 1, (double)lon, (double)lon + 1, int.MaxValue, int.MinValue, 1201, 1201, 0, "", SRTM1TILESTATUS.UNDEFINED, false);
                 // search tile in web tile index
                 string url;
                 if (urls.TryGetValue(tile.FileIndex, out url))
                 {
                     // add tile if found
                     tile.URL = url;
                     WebTiles.Add(tile.FileIndex, tile);
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }