/// <summary> /// Gets the elevation. /// </summary> /// <returns> /// The height. Null, if elevation is not available. /// </returns> /// <param name='coordinates'> /// Coordinates. /// </param> /// <exception cref='Exception'> /// Represents errors that occur during application execution. /// </exception> public int?GetElevation(IGeographicalCoordinates coordinates) { int cellLatitude = (int)Math.Floor(Math.Abs(coordinates.Latitude)); if (coordinates.Latitude < 0) { cellLatitude *= -1; cellLatitude -= 1; // because negative so in bottom tile } int cellLongitude = (int)Math.Floor(Math.Abs(coordinates.Longitude)); if (coordinates.Longitude < 0) { cellLongitude *= -1; cellLongitude -= 1; // because negative so in left tile } SrtmDataCell dataCell = DataCells.Where(dc => dc.Latitude == cellLatitude && dc.Longitude == cellLongitude).FirstOrDefault(); if (dataCell != null) { return(dataCell.GetElevation(coordinates)); } string filename = string.Format("{0}{1:D2}{2}{3:D3}.hgt", cellLatitude < 0 ? "S" : "N", Math.Abs(cellLatitude), cellLongitude < 0 ? "W" : "E", Math.Abs(cellLongitude)); string filePath = Path.Combine(DataDirectory, filename); if (!File.Exists(filePath)) { throw new Exception("SRTM data cell not found: " + filePath); } dataCell = new SrtmDataCell(filePath); DataCells.Add(dataCell); return(dataCell.GetElevation(coordinates)); }
/// <summary> /// Gets the height. /// </summary> /// <returns> /// The height. /// </returns> /// <param name='coordinates'> /// Coordinates. /// </param> /// <exception cref='Exception'> /// Represents errors that occur during application execution. /// </exception> public int GetHeight (IGeographicalCoordinates coordinates) { int cellLatitude = (int)Math.Floor (Math.Abs (coordinates.Latitude)); if (coordinates.Latitude < 0) cellLatitude *= -1; int cellLongitude = (int)Math.Floor (Math.Abs (coordinates.Longitude)); if (coordinates.Longitude < 0) cellLongitude *= -1; SrtmDataCell dataCell = DataCells.Where (dc => dc.Latitude == cellLatitude && dc.Longitude == cellLongitude).FirstOrDefault (); if (dataCell != null) return dataCell.GetHeight (coordinates); string filename = string.Format ("{0}{1:D2}{2}{3:D3}.hgt", cellLatitude < 0 ? "S" : "N", Math.Abs (cellLatitude), cellLongitude < 0 ? "W" : "E", Math.Abs (cellLongitude)); string filePath = Path.Combine (DataDirectory, filename); if (!File.Exists (filePath)) throw new Exception ("SRTM data cell not found: "+filePath); dataCell = new SrtmDataCell (filePath); DataCells.Add (dataCell); return dataCell.GetHeight (coordinates); }