如何从 C# 读取 GeoTIFF 文件 [英] How to read GeoTIFF file from C#

查看:91
本文介绍了如何从 C# 读取 GeoTIFF 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经获得了某个地区的数字高程图(地球高度图).我的目标是创建逼真的地形.

I have acquired Digital Elevation Maps(Height Map of Earth) of some area. My aim was to create Realistic Terrains.

地形生成没问题.我已经练习过使用 VC# &XNA 框架.

Terrain Generation is no problem. I have practiced that using VC# & XNA framework.

问题是那些高度图文件是我不知道如何阅读的 GeoTIFF 格式.我以前也没有阅读任何图像文件的经验,因此我可以使用互联网上有关阅读 GeoTIFF 文件的小技巧进行实验.到目前为止,我一直没有成功.

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.

  • 我拥有的 geoTIFF 文件是 3601 x 3601 文件.
  • 每个文件都有两个版本,一个十进制和一个num 个有价值的文件.
  • 每个文件都有经度和每秒的数据.纬度地理坐标以及高度图,即 Lon、Lat、距海平面的高度

如何阅读这些文件:)

我拥有的文件来自 ASTER G-DEM Version-2 官方描述链接据他们说,GeoTIFF 是非常标准的,这是因为我下载的一些 GeoTIFF 可视化工具向我显示了正确的数据.

The files I have are from ASTER G-DEM Version-2 LINK TO OFFICIAL DESCRIPTION according to them GeoTIFF is pretty standard which is because some GeoTIFF Visualizers I dwonloaded are showing me the correct data.

我将使用 C#.如果我们就这种语言进行讨论,我将不胜感激.

I am gonna be using C#. I would appreciate if we talk in relation to this language.

好的,我得到了 libtiff,这就是我所做的,

okay i got the libtiff and this what i have done,

using (Tiff tiff = Tiff.Open(@"TestN41E071_dem.tif", 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 < 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 < temp.Length; i++)
  {                
    temp[i] *= factor;
    MessageBox.Show("Row:"+row.ToString()+"Column:"+(i/2).ToString()+"Value:"+temp[i].ToString());
  }
}

在我显示消息框的地方,我正在显示相应的值,我做得对吗,我在问这个,因为这是我对图像和图像的首次体验816 位问题.我认为与 libtiff 的官方教程不同,我应该使用 short 而不是 ushort,因为我使用的图像是 GeoTIFF,签名 16 位"强>

where i am displaying the message box, i am displaying the corresponding values, Am i doing it Right, i am asking this cuz this is my maiden experience with images & 816 bit problem. I think unlike the official tutorials of libtiff i should be using short instead of ushort because the images i am using are "GeoTIFF, signed 16 bits"

推荐答案

有一些 SDK 可用于从 C# 读取 GeoTIFF 文件:

There are some SDKs out there usable from C# to read GeoTIFF files:

  • http://www.bluemarblegeo.com/global-mapper/developer/developer.php#details (commercial)
  • http://bitmiracle.com/libtiff/ (free)
  • http://trac.osgeo.org/gdal/wiki/GdalOgrInCsharp (free?)

更新:

GeoTIFF 的规范可以在 here 中找到 - 对我来说似乎GeoTIFF 可以包含不同的信息子类型",而这些信息又需要适当地解释......

The spec for GeoTIFF can be found here - to me it seems that GeoTIFFs can contain different "subtypes" of information which in turn need to be interpreted appropriately...

这篇关于如何从 C# 读取 GeoTIFF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆