我正在嘗試使用libtiff.net從GeoTIFF文件讀取高程數據。 到目前爲止,我大部分時間都只能使用libtiff.net網頁上的示例從文件中讀取元數據。GeoTIFF libtiff.net獲取c中的高程數據#
但HOWTO讀取高程數據,我不知道......我第一次嘗試用Tiff.ReadScanline()
閱讀描述here,但我有一個文件,似乎以不同的方式存儲(可能在瓷磚,如果我理解正確)
這裏是元數據(據我已經能夠讀)(TIFF文件是從丹麥地形高程數據集):
TIFF文件C:\用戶*** \ DTM_1km_6170_500.tif,0頁有以下標籤設置:
IMAGEWIDTH System.Int32:2500
IMAGELENGTH System.Int32:2500
BITSPERSAMPLE System.Int16:32
COMPRESSION BitMiracle.LibTiff.Classic.Compression:ADOBE_DEFLATE
光度法BitMiracle.LibTiff.Classic。光度:MINISBLACK
STRIPOFFSETS System.UInt64形式[]:System.UInt64形式[]
SAMPL ESPERPIXEL System.Int16:1
STRIPBYTECOUNTS System.UInt64形式[]:System.UInt64形式[]
PLANARCONFIG BitMiracle.LibTiff.Classic.PlanarConfig:重疊羣
PREDICTOR BitMiracle.LibTiff.Classic.Predictor:浮點
TILEWIDTH System.Int32:256
TILELENGTH System.Int32:256
TILEOF FSETS System.UInt64形式[]:System.UInt64形式[]
TILEBYTECOUNTS System.UInt64形式[]:System.UInt64形式[]
SAMPLEFORMAT BitMiracle.LibTiff.Classic.SampleFormat:IEEEFP
DATATYPE System.Int16 :3
GEOTIFF_MODELPIXELSCALETAG System.Int32:3 GEOTIFF_MODELPIXELSCALETAG System.Byte []:U U?
GEOTIFF_MODELTIEPOINTTAG System.Int32:6 GEOTIFF_MODELTIEPOINTTAG System.Byte []:a^WA
34735 System.Int32:36 34735 System.Byte []: ±±#°ED)#
34736 System.Int32:3 34736 System.Byte []:
34737 System.Int32:30 34737 System。字節[]:ETRS89/UTM區域 32N | ETRS89 |
42113 System.Int32:6 42113 System.Byte []:-9999
到目前爲止,我寫的代碼如下:
namespace GeoTIFFReader
{
public class GeoTIFF
{
private double[,] heightmap;
private double dx;
private double dy;
private double startx;
private double starty;
public GeoTIFF(string fn)
{
using (Tiff tiff = Tiff.Open(fn, "r"))
{
if (tiff == null)
{
// Error - could not open
return;
}
int width = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
int height = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
heightmap = new double[width, height];
FieldValue[] modelPixelScaleTag = tiff.GetField(TiffTag.GEOTIFF_MODELPIXELSCALETAG);
FieldValue[] modelTiePointTag = tiff.GetField(TiffTag.GEOTIFF_MODELTIEPOINTTAG);
byte[] modelPixelScale = modelPixelScaleTag[1].GetBytes();
dx = BitConverter.ToDouble(modelPixelScale, 0);
dy = BitConverter.ToDouble(modelPixelScale, 8) * -1;
byte[] modelTransformation = modelTiePointTag[1].GetBytes();
double originLon = BitConverter.ToDouble(modelTransformation, 24);
double originLat = BitConverter.ToDouble(modelTransformation, 32);
startx = originLon + dx/2.0;
starty = originLat + dy/2.0;
double curx = startx;
double cury = starty;
FieldValue[] bitsPerSampleTag = tiff.GetField(TiffTag.BITSPERSAMPLE);
FieldValue[] tilewtag = tiff.GetField(TiffTag.TILEWIDTH);
FieldValue[] tilehtag = tiff.GetField(TiffTag.TILELENGTH);
int tilew = tilewtag[0].ToInt();
int tileh = tilehtag[0].ToInt();
var tile = new byte[tilew*tileh];
//var scanline = new byte[tiff.ScanlineSize()]; Does not work... wrong format
for (int il = 0; il < height; il++)
{
//tiff.ReadScanline(scanline, il); // Load il'th line of data
for (int ir = 0; ir < width; ir++)
{
// Here I would like to read each pixel data that contains elevation in gray-scale in f32 as far I as I understand from metadata
//object value = scanline[ir];
//heightmap[ir, il] = double.Parse(value.ToString());
}
}
Console.WriteLine(heightmap.ToString());
}
}
}
}
所以,如果有人知道HOWTO提取此數據,這將非常感激。