/// <summary> /// Generates an index file by listing all available SRTM cells on the FTP site. /// </summary> public void Generate() { activityLogger.Log(ActivityLogLevel.Verbose, "Downloading data for SRTM index generation"); for (SrtmContinentalRegion continentalRegion = (SrtmContinentalRegion)(SrtmContinentalRegion.None + 1); continentalRegion < SrtmContinentalRegion.End; continentalRegion++) { string region = continentalRegion.ToString(); string url = srtmSource + region + "/"; WebRequest request = WebRequest.Create(new System.Uri(url)); WebResponse response = request.GetResponse(); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); MatchCollection matches = Regex.Matches(responseFromServer, fileNamePattern, RegexOptions.IgnoreCase); // Process each match. foreach (Match match in matches) { GroupCollection groups = match.Groups; string filename = groups[1].Value.Trim(); if (filename.Length == 0) { continue; } Srtm3Cell srtm3Cell = Srtm3Cell.CreateSrtm3Cell(filename, false); SetValueForCell(srtm3Cell.CellLon, srtm3Cell.CellLat, (int)continentalRegion); } // Cleanup the streams and the response. reader.Close(); dataStream.Close(); response.Close(); } }
public IDictionary <int, Srtm3Cell> FetchCachedCellsList() { Dictionary <int, Srtm3Cell> cachedCells = new Dictionary <int, Srtm3Cell> (); DirectoryInfo cacheDir = new DirectoryInfo(Srtm3CachePath); FileInfo[] files = null; try { files = cacheDir.GetFiles("*.hgt"); foreach (FileInfo file in files) { Srtm3Cell cell = Srtm3Cell.CreateSrtm3Cell(file.Name, false); cachedCells.Add(Srtm3Cell.CalculateCellKey(cell), cell); } } catch (DirectoryNotFoundException) { // no cache found, skip } return(cachedCells); }