Answer the question
In order to leave comments, you need to log in
How to correctly read hgt format file using C#?
I want to write a function that will take latitude and longitude as input and in return give me the height at that point. There is an hgt file (our height map). Its resolution is 1201x1201, the size of each height is 16 bits (16-bit signed integers) - infa from the docks. I'm trying to read a file, but I'm getting wrong results. Here is the code. The value in the for loop is just an example, so as not to read the entire file
using System;
using System.IO;
using System.Collections;
namespace TextFileReader_csharp
{
class Class1
{
static void Main(string[] args)
{
int b = 0;
using (FileStream fs = new FileStream("N53E028.hgt", FileMode.Open, FileAccess.Read))
{
int counter = 0;
for (int i = 0; i < 300; i += 2)
{
var buf = new byte[2];
fs.Read(buf, 0, 2);
var val = (BitConverter.ToInt16(buf, 0));
Console.Write(val.ToString() + " ");
if (counter % 16 == 0)
{
Console.WriteLine();
}
counter++;
}
// } while (b != -1);
Console.ReadKey();
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question