Skip to content
Browse files

Initial commit.

  • Loading branch information...
1 parent 855e95f commit 3040b3f511496fe5f55f18d6a3bb4f4ec49e6f32 @alpinechough committed
Showing with 631 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +45 −0 Alpinechough.Srtm.csproj
  3. +20 −0 Alpinechough.Srtm.sln
  4. +27 −0 AssemblyInfo.cs
  5. +131 −0 GeographicalCoordinates.cs
  6. +50 −0 IGeographicalCoordinates.cs
  7. +53 −0 ISrtmData.cs
  8. +136 −0 SrtmData.cs
  9. +166 −0 SrtmDataCell.cs
View
3 .gitignore
@@ -0,0 +1,3 @@
+bin/
+Alpinechough.Srtm.pidb
+Alpinechough.Srtm.userprefs
View
45 Alpinechough.Srtm.csproj
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{CD10A6E7-745F-4C82-9AAB-C5AA90944195}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>Alpinechough.Srtm</RootNamespace>
+ <AssemblyName>Alpinechough.Srtm</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AssemblyInfo.cs" />
+ <Compile Include="GeographicalCoordinates.cs" />
+ <Compile Include="SrtmDataCell.cs" />
+ <Compile Include="SrtmData.cs" />
+ <Compile Include="IGeographicalCoordinates.cs" />
+ <Compile Include="ISrtmData.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>
View
20 Alpinechough.Srtm.sln
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alpinechough.Srtm", "Alpinechough.Srtm.csproj", "{CD10A6E7-745F-4C82-9AAB-C5AA90944195}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {CD10A6E7-745F-4C82-9AAB-C5AA90944195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CD10A6E7-745F-4C82-9AAB-C5AA90944195}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CD10A6E7-745F-4C82-9AAB-C5AA90944195}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CD10A6E7-745F-4C82-9AAB-C5AA90944195}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = Alpinechough.Srtm.csproj
+ EndGlobalSection
+EndGlobal
View
27 AssemblyInfo.cs
@@ -0,0 +1,27 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("Alpinechough.Srtm")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("Copyright (c) 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
131 GeographicalCoordinates.cs
@@ -0,0 +1,131 @@
+#region MIT License
+// MIT License
+// Copyright (c) 2012 Alpine Chough Software.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+#endregion
+
+using System;
+using System.Text;
+
+namespace Alpinechough.Srtm
+{
+/// <summary>
+/// Geographical coordinates.
+/// </summary>
+ public class GeographicalCoordinates : IGeographicalCoordinates
+ {
+ #region Lifecycle
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Alpinechough.Srtm.GeographicalCoordinates"/> class.
+ /// </summary>
+ public GeographicalCoordinates ()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Alpinechough.Srtm.GeographicalCoordinates"/> class.
+ /// </summary>
+ /// <param name='latitude'>
+ /// Latitude.
+ /// </param>
+ /// <param name='longitude'>
+ /// Longitude.
+ /// </param>
+ public GeographicalCoordinates (double latitude, double longitude)
+ {
+ Latitude = latitude;
+ Longitude = longitude;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Alpinechough.Srtm.GeographicalCoordinates"/> class.
+ /// </summary>
+ /// <param name='geographicalCoordinates'>
+ /// Geographical coordinates.
+ /// </param>
+ public GeographicalCoordinates (GeographicalCoordinates geographicalCoordinates)
+ :this(geographicalCoordinates.Latitude, geographicalCoordinates.Longitude)
+ {
+ }
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Gets or sets the latitude.
+ /// </summary>
+ /// <value>
+ /// The latitude.
+ /// </value>
+ public double Latitude {
+ get {
+ return latitude;
+ }
+ set {
+ if (value < -90 || value > 90)
+ throw new ArgumentOutOfRangeException ();
+
+ latitude = value;
+ }
+ }
+
+ private double latitude = 0;
+
+ /// <summary>
+ /// Gets or sets the longitude.
+ /// </summary>
+ /// <value>
+ /// The longitude.
+ /// </value>
+ public double Longitude {
+ get {
+ return longitude;
+ }
+ set {
+ if (value > 180 || value <= -180)
+ throw new ArgumentOutOfRangeException ();
+
+ longitude = value;
+ }
+ }
+
+ private double longitude = 0;
+
+ #endregion
+
+ #region ToString / Parse
+
+ /// <summary>
+ /// Returns a <see cref="System.String"/> that represents the current <see cref="Alpinechough.Srtm.GeographicalCoordinates"/>.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/> that represents the current <see cref="Alpinechough.Srtm.GeographicalCoordinates"/>.
+ /// </returns>
+ public override string ToString ()
+ {
+ return string.Format ("{0:0.000000}°, {1:0.000000}°", Latitude, Longitude);
+ }
+
+ #endregion
+ }
+}
+
View
50 IGeographicalCoordinates.cs
@@ -0,0 +1,50 @@
+#region MIT License
+// MIT License
+// Copyright (c) 2012 Alpine Chough Software.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+#endregion
+
+using System;
+
+namespace Alpinechough.Srtm
+{
+ /// <summary>
+ /// Geographical coordinates interface.
+ /// </summary>
+ public interface IGeographicalCoordinates
+ {
+ /// <summary>
+ /// Gets or sets the latitude.
+ /// </summary>
+ /// <value>
+ /// The latitude.
+ /// </value>
+ double Latitude { get; set; }
+
+ /// <summary>
+ /// Gets or sets the longitude.
+ /// </summary>
+ /// <value>
+ /// The longitude.
+ /// </value>
+ double Longitude { get; set; }
+ }
+}
+
View
53 ISrtmData.cs
@@ -0,0 +1,53 @@
+#region MIT License
+// MIT License
+// Copyright (c) 2012 Alpine Chough Software.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+#endregion
+
+using System;
+
+namespace Alpinechough.Srtm
+{
+ /// <summary>
+ /// SRTM data interface.
+ /// </summary>
+ public interface ISrtmData
+ {
+ /// <summary>
+ /// Unloads all SRTM data cells.
+ /// </summary>
+ void Unload ();
+
+ /// <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>
+ int GetHeight (IGeographicalCoordinates coordinates);
+ }
+}
+
View
136 SrtmData.cs
@@ -0,0 +1,136 @@
+#region MIT License
+// MIT License
+// Copyright (c) 2012 Alpine Chough Software.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+#endregion
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Alpinechough.Srtm
+{
+ /// <summary>
+ /// SRTM Data.
+ /// </summary>
+ /// <exception cref='DirectoryNotFoundException'>
+ /// Is thrown when part of a file or directory argument cannot be found.
+ /// </exception>
+ public class SrtmData
+ {
+ #region Lifecycle
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Alpinechough.Srtm.SrtmData"/> class.
+ /// </summary>
+ /// <param name='dataDirectory'>
+ /// Data directory.
+ /// </param>
+ /// <exception cref='DirectoryNotFoundException'>
+ /// Is thrown when part of a file or directory argument cannot be found.
+ /// </exception>
+ public SrtmData (string dataDirectory)
+ {
+ if (!Directory.Exists (dataDirectory))
+ throw new DirectoryNotFoundException (dataDirectory);
+
+ DataDirectory = dataDirectory;
+ DataCells = new List<SrtmDataCell> ();
+ }
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Gets or sets the data directory.
+ /// </summary>
+ /// <value>
+ /// The data directory.
+ /// </value>
+ private string DataDirectory { get; set; }
+
+ /// <summary>
+ /// Gets or sets the SRTM data cells.
+ /// </summary>
+ /// <value>
+ /// The SRTM data cells.
+ /// </value>
+ private List<SrtmDataCell> DataCells { get; set; }
+
+ #endregion
+
+ #region Public methods
+
+ /// <summary>
+ /// Unloads all SRTM data cells.
+ /// </summary>
+ public void Unload ()
+ {
+ DataCells.Clear ();
+ }
+
+ /// <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);
+ }
+
+ #endregion
+ }
+}
+
View
166 SrtmDataCell.cs
@@ -0,0 +1,166 @@
+#region MIT License
+// MIT License
+// Copyright (c) 2012 Alpine Chough Software.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+#endregion
+
+using System;
+using System.IO;
+
+namespace Alpinechough.Srtm
+{
+ /// <summary>
+ /// SRTM data cell.
+ /// </summary>
+ /// <exception cref='FileNotFoundException'>
+ /// Is thrown when a file path argument specifies a file that does not exist.
+ /// </exception>
+ /// <exception cref='ArgumentException'>
+ /// Is thrown when an argument passed to a method is invalid.
+ /// </exception>
+ /// <exception cref='ArgumentOutOfRangeException'>
+ /// Is thrown when an argument passed to a method is invalid because it is outside the allowable range of values as
+ /// specified by the method.
+ /// </exception>
+ public class SrtmDataCell
+ {
+ #region Lifecycle
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Alpinechough.Srtm.SrtmDataCell"/> class.
+ /// </summary>
+ /// <param name='filepath'>
+ /// Filepath.
+ /// </param>
+ /// <exception cref='FileNotFoundException'>
+ /// Is thrown when a file path argument specifies a file that does not exist.
+ /// </exception>
+ /// <exception cref='ArgumentException'>
+ /// Is thrown when an argument passed to a method is invalid.
+ /// </exception>
+ public SrtmDataCell (string filepath)
+ {
+ if (!File.Exists (filepath))
+ throw new FileNotFoundException ("File not found.", filepath);
+
+ if (string.Compare (".hgt", Path.GetExtension (filepath), StringComparison.CurrentCultureIgnoreCase) != 0)
+ throw new ArgumentException ("Invalid extension.", filepath);
+
+ string filename = Path.GetFileNameWithoutExtension (filepath).ToLower ();
+ string[] fileCoordinate = filename.Split (new [] { 'e', 'w' });
+ if (fileCoordinate.Length != 2)
+ throw new ArgumentException ("Invalid filename.", filepath);
+
+ fileCoordinate [0] = fileCoordinate [0].TrimStart (new [] { 'n', 's' });
+
+ Latitude = int.Parse (fileCoordinate [0]);
+ if (filename.Contains ("s"))
+ Latitude *= -1;
+
+ Longitude = int.Parse (fileCoordinate [1]);
+ if (filename.Contains ("w"))
+ Longitude *= -1;
+
+ HgtData = File.ReadAllBytes (filepath);
+
+ switch (HgtData.Length) {
+ case 1201*1201*2: // SRTM-3
+ PointsPerCell = 1201;
+ break;
+ case 3601*3601*2: // SRTM-1
+ PointsPerCell = 3601;
+ break;
+ default:
+ throw new ArgumentException ("Invalid file size.", filepath);
+ }
+ }
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Gets or sets the hgt data.
+ /// </summary>
+ /// <value>
+ /// The hgt data.
+ /// </value>
+ private byte[] HgtData { get; set; }
+
+ /// <summary>
+ /// Gets or sets the points per cell.
+ /// </summary>
+ /// <value>
+ /// The points per cell.
+ /// </value>
+ private int PointsPerCell { get; set; }
+
+ /// <summary>
+ /// Gets or sets the latitude of the srtm data file.
+ /// </summary>
+ /// <value>
+ /// The latitude.
+ /// </value>
+ public int Latitude { get; private set; }
+
+ /// <summary>
+ /// Gets or sets the longitude of the srtm data file.
+ /// </summary>
+ /// <value>
+ /// The longitude.
+ /// </value>
+ public int Longitude { get; private set; }
+
+ #endregion
+
+ #region Public Methods
+
+ /// <summary>
+ /// Gets the height.
+ /// </summary>
+ /// <returns>
+ /// The height.
+ /// </returns>
+ /// <param name='coordinates'>
+ /// Coordinates.
+ /// </param>
+ /// <exception cref='ArgumentOutOfRangeException'>
+ /// Is thrown when an argument passed to a method is invalid because it is outside the allowable range of values as
+ /// specified by the method.
+ /// </exception>
+ public int GetHeight (IGeographicalCoordinates coordinates)
+ {
+ int localLat = (int)((coordinates.Latitude - Latitude) * PointsPerCell);
+ int localLon = (int)(((coordinates.Longitude - Longitude)) * PointsPerCell);
+ int bytesPos = ((PointsPerCell - localLat - 1) * PointsPerCell * 2) + localLon * 2;
+
+ Console.WriteLine (bytesPos);
+
+ if (bytesPos < 0 || bytesPos > PointsPerCell * PointsPerCell * 2)
+ throw new ArgumentOutOfRangeException ("Coordinates out of range.", "coordinates");
+
+ // Motorola "big-endian" order with the most significant byte first
+ return (HgtData [bytesPos]) << 8 | HgtData [bytesPos + 1];
+ }
+
+ #endregion
+ }
+}
+

0 comments on commit 3040b3f

Please sign in to comment.
Something went wrong with that request. Please try again.