I have acquired Digital Elevation Maps (a map of the height of the Earth) of some area. My goal was to create Realistic Territories.
Creating a landscape is not a problem. I practiced this using the VC # and XNA infrastructure.
The problem is that these DEM files are in GeoTIFF format, which I donβt know how to read. I also have no experience reading any image files so I can experiment with the little tips available on the Internet about reading GeoTIFF files. So far, I have not been successful.
- GeoTIFF files I have 3601 x 3601 files.
- Each file has two versions, decimal and ten-digit files.
- Each file has data of every second longitude and latitude. Geocoders along with a height map ie Lon, Lat, altitude from sea level.
How to read these files :)
The files that I have are from ASTER G-DEM Version-2 LINK TO OFFICIAL DESCRIPTION according to them GeoTIFF is pretty standard because some of the GeoTIFF documenters that I downloaded show me the correct data.
I am going to use C #. I would be grateful if we talk about this language.
Ed i t
okay i got libtiff and this is what i did
using (Tiff tiff = Tiff.Open(@"Test\N41E071_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()); } }
where I show the message box, I show the corresponding values, I do it right , I ask about it, because this is my first experience with images and the problem is with 8 \ 16 bits. I think, unlike the official libtiff manuals, I should use short instead of ushort , because the images I use are "GeoTIFF signed 16 bits"