Example #1
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)
     {
     }
 }
Example #2
0
        private SortedDictionary <string, GLOBETileDesignator> GetAllTilesFromWeb()
        {
            // check for valid urls
            if (string.IsNullOrEmpty(global::ScoutBase.Data.Properties.Settings.Default.GLOBE_URLs))
            {
                return(new SortedDictionary <string, GLOBETileDesignator>());
            }
            // split urls if necessary
            string[] globeurls;
            if (global::ScoutBase.Data.Properties.Settings.Default.GLOBE_URLs.Contains("\r\n"))
            {
                globeurls = global::ScoutBase.Data.Properties.Settings.Default.GLOBE_URLs.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            }
            else
            {
                globeurls    = new string[1];
                globeurls[0] = global::ScoutBase.Data.Properties.Settings.Default.GLOBE_URLs;
            }
            // create a searchable index of all available tiles from web
            SortedDictionary <string, URLInfo> urls = new SortedDictionary <string, URLInfo>();

            foreach (string globeurl in globeurls)
            {
                HTTPDirectorySearcher    s = new HTTPDirectorySearcher();
                List <HTTPDirectoryItem> l = s.GetDirectoryInformation(globeurl);
                foreach (HTTPDirectoryItem item in l)
                {
                    try
                    {
                        // find possible file names
                        if (item.Name.Contains(".zip"))
                        {
                            string  fileindex = item.Name.Split('.')[0].ToUpper().Substring(0, 1);
                            int     version   = System.Convert.ToInt32(item.Name.Split('.')[0].ToUpper().Substring(1, 2));
                            string  status    = item.Name.Split('.')[0].ToUpper().Substring(3, 1);
                            URLInfo url       = new URLInfo(fileindex, version, status, item.AbsolutePath);
                            URLInfo oldurl;
                            if (urls.TryGetValue(fileindex, out oldurl))
                            {
                                if ((url.Status == "G") && (url.Version > oldurl.Version))
                                {
                                    urls.Remove(oldurl.Index);
                                }
                            }
                            urls.Add(url.Index, url);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            // initally generate tile info
            SortedDictionary <string, GLOBETileDesignator> globetiles = new SortedDictionary <string, GLOBETileDesignator>();
            GLOBETileDesignator globetile;

            globetile = new GLOBETileDesignator("A", "", 50.0, 90.0, -180.0, -90.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("B", "", 50.0, 90.0, -90.0, -0.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("C", "", 50.0, 90.0, 0.0, 90.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("D", "", 50.0, 90.0, 90.0, 180.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("E", "", 0.0, 50.0, -180.0, -90.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("F", "", 0.0, 50.0, -90.0, -0.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("G", "", 0.0, 50.0, 0.0, 90.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("H", "", 0.0, 50.0, 90.0, 180.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("I", "", -50.0, 0.0, -180.0, -90.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("J", "", -50.0, 0.0, -90.0, -0.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("K", "", -50.0, 0.0, 0.0, 90.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("L", "", -50.0, 0.0, 90.0, 180.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("M", "", -90.0, -50.0, -180.0, -90.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("N", "", -90.0, -50.0, -90.0, -0.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("O", "", -90.0, -50.0, 0.0, 90.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);
            globetile = new GLOBETileDesignator("P", "", -90.0, -50.0, 90.0, 180.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, false);
            globetiles.Add(globetile.FileIndex, globetile);

            SortedDictionary <string, GLOBETileDesignator> webtiles = new SortedDictionary <string, GLOBETileDesignator>();

            foreach (GLOBETileDesignator tile in globetiles.Values)
            {
                // search tile in web tile index
                URLInfo url;
                if (urls.TryGetValue(tile.FileIndex, out url))
                {
                    // add tile if found
                    tile.URL     = url.URL;
                    tile.Version = url.Version;
                    try
                    {
                        tile.Status = (GLOBETILESTATUS)url.Status[0];
                    }
                    catch
                    {
                    }
                    webtiles.Add(tile.FileIndex, tile);
                }
            }
            return(webtiles);
        }