title: How to read GeoTIFF file from C#
body: <p>I have acquired Digital Elevation Maps(Height Map of Earth) of some area. My aim was to create Realistic Terrains.</p>
  <p>Terrain Generation is no problem. I have practiced that using VC# &amp; XNA framework.</p>
  <p>The problem is that those Height Map Files are in GeoTIFF format which i don't know how to read. Nor do i have previous experience with reading any image files so that i could experiment something using little tips-bits available on internet about reading GeoTIFF files. So far i have been unsuccessful.</p>
  <ul>
  <li>The geoTIFF files I have are 3601 x 3601 files.</li>
  <li>Each file has two version, a decimal &amp; num valued files.</li>
  <li>Each file has data of every second of longitude &amp; latitude of
  Geo-Coords along with Height Map i.e Lon, Lat, height from sea level</li>
  </ul>
  <p>How to read these file :)</p>
  <p>The files I have are from ASTER G-DEM Version-2 <a href="http://www.ersdac.or.jp/GDEM/E/2.html" rel="nofollow noreferrer" title="OFFICIAL LINK">LINK TO OFFICIAL DESCRIPTION</a> according to them GeoTIFF is pretty standard which is because some GeoTIFF Visualizers I dwonloaded are showing me the correct data.</p>
  <p>I am gonna be using C#. I would appreciate if we talk in relation to this language.</p>
  <hr />
  <h2><strong>E D I T</strong></h2>
  <p>okay i got the <strong>libtiff</strong> and this what i have done,</p>
  <pre><code>using (Tiff tiff = Tiff.Open(@&quot;Test\N41E071_dem.tif&quot;, r))
  {
    int width   = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
    int height  = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
    double dpiX = tiff.GetField(TiffTag.XRESOLUTION)[0].ToDouble();
    double dpiY = tiff.GetField(TiffTag.YRESOLUTION)[0].ToDouble(); 
  
    byte[] scanline        = new byte[tiff.ScanlineSize()]; 
    ushort[] scanline16Bit = new ushort[tiff.ScanlineSize() / 2];
  
    for (int i = 0; i &lt; height; i++)
    {
      tiff.ReadScanline(scanline, i); //Loading ith Line                        
      MultiplyScanLineAs16BitSamples(scanline, scanline16Bit, 16,i);
    }
  }
  
  private static void MultiplyScanLineAs16BitSamples(byte[] scanline, ushort[] temp, ushort factor,int row)
  {
    if (scanline.Length % 2 != 0)
    {
      // each two bytes define one sample so there should be even number of bytes
      throw new ArgumentException();
    }
    
    Buffer.BlockCopy(scanline, 0,   temp, 0, scanline.Length);
  
    for (int i = 0; i &lt; temp.Length; i++)
    {                
      temp[i] *= factor;
      MessageBox.Show(&quot;Row:&quot;+row.ToString()+&quot;Column:&quot;+(i/2).ToString()+&quot;Value:&quot;+temp[i].ToString());
    }
  }
  </code></pre>
  <p>where i am displaying the message box, i am displaying the corresponding values, <strong>Am i doing it Right</strong>, i am asking this cuz this is my maiden experience with images &amp; 8\16 bit problem. I think unlike the official tutorials of libtiff i should be using <strong>short</strong> instead of <strong>ushort</strong> because the images i am using are <strong>&quot;GeoTIFF, signed 16 bits&quot;</strong></p>