Ich versuche libtiff.net zu verwenden Höhendaten von einer GeoTIFF-Datei zu lesen. Bisher habe ich meist nur in der Lage gewesen Metadaten aus der Datei auf libtiff.net Homepage am Beispiel zu lesen.GeoTIFF libtiff.net Höhendaten in C# erhalten
Aber howto lesen Höhendaten Ich verstehe nicht ... Ich habe versucht, zuerst mit Tiff.ReadScanline()
lesen, wie beschrieben here aber die Datei-I scheint haben anders (wahrscheinlich in Kacheln, wenn ich es richtig verstanden habe) gespeichert werden
Hier ist die Metadaten (soweit ich das lesen konnte) (von dem dänischen Geländehöhendatensatz ist die tIFF-Datei):
tiff c: \ Benutzer *** \ DTM_1km_6170_500.tif, Seite 0 haben folgende Tags gesetzt:
Width System.Int32: 2500
imagelength System.Int32: 2500
BitsPerSample System.Int16: 32
COMPRESSION BitMiracle.LibTiff.Classic.Compression: ADOBE_DEFLATE
Photometrische BitMiracle.LibTiff.Classic. Photometrische: MINISBLACK
Stripoffsets System.UInt64 []: System.UInt64 []
SAMPL ESPERPIXEL System.Int16: 1
stripbytecounts System.UInt64 []: System.UInt64 []
PLANARCONFIG BitMiracle.LibTiff.Classic.PlanarConfig: Contig
Prädiktor BitMiracle.LibTiff.Classic.Predictor: Gleitpunktumgebung
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
DATENTYP System.Int16 : 3
GEOTIFF_MODELPIXELSCALETAG System.Int32: 3 GEO TIFF_MODELPIXELSCALETAG System.Byte []: Ù? Ù?
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.Byte []: ETRS89/UTM-Zone 32N | ETRS89 |
42113 System.Int32: 6 42113 System.Byte []: -9999
Der Code, den ich so weit geschrieben haben, wie folgt:
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());
}
}
}
}
Also, wenn jemand diese Howto extrahieren weiß Daten, die sehr geschätzt würden.