Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using (Tiff tiff = Tiff.Open(@"TestN41E071_dem.tif", r"))
  2. {
  3. int width = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
  4. int height = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
  5. double dpiX = tiff.GetField(TiffTag.XRESOLUTION)[0].ToDouble();
  6. double dpiY = tiff.GetField(TiffTag.YRESOLUTION)[0].ToDouble();
  7.  
  8. byte[] scanline = new byte[tiff.ScanlineSize()];
  9. ushort[] scanline16Bit = new ushort[tiff.ScanlineSize() / 2];
  10.  
  11. for (int i = 0; i < height; i++)
  12. {
  13. tiff.ReadScanline(scanline, i); //Loading ith Line
  14. MultiplyScanLineAs16BitSamples(scanline, scanline16Bit, 16,i);
  15. }
  16. }
  17.  
  18. private static void MultiplyScanLineAs16BitSamples(byte[] scanline, ushort[] temp, ushort factor,int row)
  19. {
  20. if (scanline.Length % 2 != 0)
  21. {
  22. // each two bytes define one sample so there should be even number of bytes
  23. throw new ArgumentException();
  24. }
  25.  
  26. Buffer.BlockCopy(scanline, 0, temp, 0, scanline.Length);
  27.  
  28. for (int i = 0; i < temp.Length; i++)
  29. {
  30. temp[i] *= factor;
  31. MessageBox.Show("Row:"+row.ToString()+"Column:"+(i/2).ToString()+"Value:"+temp[i].ToString());
  32. }
  33. }
  34.  
  35. int buffersize = 1000000;
  36. using (Tiff tiff = Tiff.Open(geotifffile, "r"))
  37. {
  38. int nooftiles = tiff.GetField(TiffTag.TILEBYTECOUNTS).Length;
  39. int width = tiff.GetField(TiffTag.TILEWIDTH)[0].ToInt();
  40. int height = tiff.GetField(TiffTag.TILELENGTH)[0].ToInt();
  41. byte[] buffer = new byte[buffersize];
  42.  
  43. for (int i = 0; i < nooftiles; i++)
  44. {
  45. int size = tiff.ReadEncodedTile(i, buffer, 0, buffersize);
  46. float[,] data = new float[width, height];
  47. Buffer.BlockCopy(buffer, 0, data, 0, size); // Convert byte array to x,y array of floats (height data)
  48. // Do whatever you want with the height data (calculate hillshade images etc.)
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement