public JSONArrayGLOBE(GLOBEDictionary globe) { version = globe.Version; full_count = globe.Tiles.Count; tiles = new List <List <string> >(); for (int i = 0; i < full_count; i++) { List <string> l = new List <string>(); GLOBETileDesignator tile = globe.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); } }
public void CalcMinMaxElevation(ref GLOBETileDesignator 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++) { short s = br.ReadInt16(); if (s != elv_missing_flag) { if (s < tile.MinElv) { tile.MinElv = s; } if (s > tile.MaxElv) { tile.MaxElv = s; } } } } } } catch (Exception ex) { } }
private SortedDictionary <string, GLOBETileDesignator> GetAllTilesFromLocalDir() { // return empty dictionary if path not found if (!Directory.Exists(global::ScoutBase.Data.Properties.Settings.Default.GLOBE_DataPath)) { return(new SortedDictionary <string, GLOBETileDesignator>()); } SortedDictionary <string, GLOBETileDesignator> localtiles = new SortedDictionary <string, GLOBETileDesignator>(); FileInfo[] GLOBEfiles = new DirectoryInfo(global::ScoutBase.Data.Properties.Settings.Default.GLOBE_DataPath).GetFiles("????.*"); foreach (FileInfo file in GLOBEfiles) { try { GLOBETileDesignator tile = GetTileInfoFromFile(file.FullName); if (tile != null) { // valid tile found, complete tile information // check min/max info GLOBETileDesignator oldtile; if ((tile.MaxElv == int.MinValue) || (tile.MinElv == int.MaxValue)) { // try to get cached min/max info 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); } } if (localtiles.TryGetValue(tile.FileIndex, out oldtile)) { if ((tile.Status == GLOBETILESTATUS.GOOD) && (tile.Version > oldtile.Version)) { //remove outdated tile localtiles.Remove(oldtile.FileIndex); } } localtiles.Add(tile.FileIndex, tile); } } catch (Exception ex) { } } return(localtiles); }
public void DownloadTile(GLOBETileDesignator 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.GLOBE_DataPath, filename)); }
public void Update(GLOBETileDesignator tile) { // return on null if (tile == null) { return; } GLOBETileDesignator 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 GLOBETileDesignator(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; } } }
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); }
public GLOBETileDesignator GetTileInfoFromFile(string filename) { if (!IsGLOBEFile(filename)) { return(null); } string upperfilename = Path.GetFileNameWithoutExtension(filename).ToUpper(); char index = upperfilename[0]; int vresion = System.Convert.ToInt32(upperfilename.Substring(1, 2)); char status = upperfilename[3]; GLOBETileDesignator tile = null; switch (index) { case 'A': tile = new GLOBETileDesignator("A", filename, 50.0, 90.0, -180.0, -90.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'B': tile = new GLOBETileDesignator("B", filename, 50.0, 90.0, -90.0, -0.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'C': tile = new GLOBETileDesignator("C", filename, 50.0, 90.0, 0.0, 90.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'D': tile = new GLOBETileDesignator("D", filename, 50.0, 90.0, 90.0, 180.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'E': tile = new GLOBETileDesignator("E", filename, 0.0, 50.0, -180.0, -90.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'F': tile = new GLOBETileDesignator("F", filename, 0.0, 50.0, -90.0, -0.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'G': tile = new GLOBETileDesignator("G", filename, 0.0, 50.0, 0.0, 90.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'H': tile = new GLOBETileDesignator("H", filename, 0.0, 50.0, 90.0, 180.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'I': tile = new GLOBETileDesignator("I", filename, -50.0, 0.0, -180.0, -90.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'J': tile = new GLOBETileDesignator("J", filename, -50.0, 0.0, -90.0, -0.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'K': tile = new GLOBETileDesignator("K", filename, -50.0, 0.0, 0.0, 90.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'L': tile = new GLOBETileDesignator("L", filename, -50.0, 0.0, 90.0, 180.0, int.MaxValue, int.MinValue, 6000, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'M': tile = new GLOBETileDesignator("M", filename, -90.0, -50.0, -180.0, -90.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'N': tile = new GLOBETileDesignator("N", filename, -90.0, -50.0, -90.0, -0.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'O': tile = new GLOBETileDesignator("O", filename, -90.0, -50.0, 0.0, 90.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; case 'P': tile = new GLOBETileDesignator("P", filename, -90.0, -50.0, 90.0, 180.0, int.MaxValue, int.MinValue, 4800, 10800, 0, "", GLOBETILESTATUS.UNDEFINED, true); break; default: return(null); } try { int.TryParse(upperfilename.Substring(1, 2), out tile.Version); tile.Status = (GLOBETILESTATUS)Enum.ToObject(typeof(GLOBETILESTATUS), upperfilename[3]); } catch (Exception ex) { // do nothing } return(tile); }