public JSONArraySRTM3(SRTM3Dictionary SRTM3) { version = SRTM3.Version; full_count = SRTM3.Tiles.Count; tiles = new List <List <string> >(); for (int i = 0; i < full_count; i++) { List <string> l = new List <string>(); SRTM3TileDesignator tile = SRTM3.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 DownloadTile(SRTM3TileDesignator 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.SRTM3_DataPath, filename)); }
public SRTM3TileDesignator 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")); SRTM3TileDesignator tile = null; if (Tiles.TryGetValue(index, out tile)) { if (tile.Local) { return(tile); } } return(null); }
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(); SRTM3TILESTATUS status = (SRTM3TILESTATUS)Enum.Parse(typeof(SRTM3TILESTATUS), 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 { } SRTM3TileDesignator tile = new SRTM3TileDesignator(index, filename, minlat, maxlat, minlon, maxlon, minelv, maxelv, rows, columns, version, url, status, local, lastupdated); this.Tiles.Add(tile.FileIndex, tile); } catch { } } }
private void CalcMinMaxElevation(ref SRTM3TileDesignator 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) { } }
private void GetAllTilesFromLocalDir() { // return empty dictionary if path not found if (!Directory.Exists(global::ScoutBase.Data.Properties.Settings.Default.SRTM3_DataPath)) { return; } LocalTiles.Clear(); FileInfo[] SRTM3files = new DirectoryInfo(global::ScoutBase.Data.Properties.Settings.Default.SRTM3_DataPath).GetFiles("???????.hgt"); foreach (FileInfo file in SRTM3files) { try { SRTM3TileDesignator 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 SRTM3TileDesignator 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 { } } }
public DataRow NewRow(SRTM3TileDesignator 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); }
public void Update(SRTM3TileDesignator tile) { // return on null if (tile == null) { return; } SRTM3TileDesignator 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 SRTM3TileDesignator(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 void GetAllTilesFromWeb() { // check for valid urls if (string.IsNullOrEmpty(global::ScoutBase.Data.Properties.Settings.Default.SRTM3_URLs)) { return; } // load tiles from web only once if (WebTiles.Count > 0) { return; } try { // split urls if necessary string[] srtm3urls; if (global::ScoutBase.Data.Properties.Settings.Default.SRTM3_URLs.Contains("\r\n")) { srtm3urls = global::ScoutBase.Data.Properties.Settings.Default.SRTM3_URLs.Split(new string[] { "\r\n" }, StringSplitOptions.None); } else { srtm3urls = new string[1]; srtm3urls[0] = global::ScoutBase.Data.Properties.Settings.Default.SRTM3_URLs; } // create a searchable index of all available tiles from web SortedDictionary <string, string> urls = new SortedDictionary <string, string>(); foreach (string url in srtm3urls) { 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")); SRTM3TileDesignator tile = new SRTM3TileDesignator(index, "", (double)lat, (double)lat + 1, (double)lon, (double)lon + 1, int.MaxValue, int.MinValue, 1201, 1201, 0, "", SRTM3TILESTATUS.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) { } }