Open and read a bin file
Open and read a bin file
(OP)
Sorry to bother you guys, but I know nothing about bin files. I've been trying for 3 days to extract elevation data from a SRTM3.hgt file, but can't make any sense of the values I'm getting.
The only description of the data file format I can find is,
"The is provided as two byte 16-bit signed integer data in a simple binary raster. There are no header or trailer bytes embedded in the file. The data is stored in row major order with 1201 rows, of 1201 values. Byte order is big-endian standard with the most significant byte first. Since they are signed integers elevations can range from -32767 to 32767 meters, encompassing the range of elevation to be found on the Earth."
I have a typical file located here (700kb),
http:/ /rapidshar e.com/file s/3698999/ N36W005.hg t.zip.html
I would really like to know how to extract the elevations from that file using VB6. Greatly appreciate any how-to advice. A canned sub I could drop in would be worth its weight in gold. Thanks.
The only description of the data file format I can find is,
"The is provided as two byte 16-bit signed integer data in a simple binary raster. There are no header or trailer bytes embedded in the file. The data is stored in row major order with 1201 rows, of 1201 values. Byte order is big-endian standard with the most significant byte first. Since they are signed integers elevations can range from -32767 to 32767 meters, encompassing the range of elevation to be found on the Earth."
I have a typical file located here (700kb),
http:/
I would really like to know how to extract the elevations from that file using VB6. Greatly appreciate any how-to advice. A canned sub I could drop in would be worth its weight in gold. Thanks.
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
CODE
CODE
CODE
Dim myRow As Integer
Dim myCol As Integer
Dim myFileNum As Integer
Dim a As Byte
Dim b As Byte
Dim c As Long
myFileNum = FreeFile
Open mFile For Binary As myFileNum
For myRow = 0 To 1200
For myCol = 0 To 2401 Step 2
Get #myFileNum, , a
Get #myFileNum, , b
c = b + 256 * a
Debug.Print c;
myArray(myRow, (myCol + 1) \ 2) = c
Next myCol
Debug.Print
Next myRow
Close #myFileNum
End Sub
Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting
Steam Engine enthusiasts: www.essexsteam.co.uk
RE: Open and read a bin file
Your code is very clear, but what I can't understand is what the statement c = b + 256 * a is actually doing. I suppose it is reversing the byte order and adding them together. This may be important, because one little (I hope) problem is that it hangs with an overflow error (row 38), when it gets b = 0, and a = 128. I will study up on adding bits & bytes. Maybe I just have to add a branch for that condition.
Thanks again. (how much does it weigh so far? )
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
OK, great, now I'll try to see why the hangup is happening.
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
I suspect that this 'special' value may possibly be data corruption, or more likely a deliberate flag to indicate some feature (maybe unknown/unreliable measurement?)
In the whole datafile there are quite a few (maybe around 30) of these (128,0) pairs. Other than that, the only negative numbers are very small (resolving to -1 or -2 metres) and adjacent to a load of values that resolve to 0.
To get the SIGNED values from my first post add the declaration
CODE
CODE
c = b + 256 * a
Debug.Print c;
CODE
If a > 127 Then
a1 = a - 256
c = CInt(b) + CLng(256 * a1)
Else
c = CInt(b) + CLng(256 * a)
End If
Debug.Print c;
I would be interested to find out what the 128, 0 represents
And I hope you enjoy the website!
Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting
Steam Engine enthusiasts: www.essexsteam.co.uk
RE: Open and read a bin file
The data file is a typical file from NASA's "Shuttle Radar Topography Mission", (SRTM), for which the elevations have been resolved into 3 second quadrants (appx. 90 m at the equator) between N60 and S56 degrees latitude. I'm using N36W005.hgt, because it is close to where I live. The title of the file indicates the lower left "pixel" centerline of coverage is at N 36:00:00 Lat and W 5:00:00 Longitude, hgt = height). I am trying to develop some pipeline routing and terrain visualization software by overlaying Google Earth images onto the elevation matrix. Then I'll be able to fly the route without using a helicopter. I already have an OGL terrain visualization program that I've been testing, but using data with only 30 second resolution, so its pretty fake looking terrain. I was able to find ASCII files with that data, but the 03 sec ASCII files that exist now are 250 MB and a bit unwieldly. The bins are, as you already know only about 3 MB, so much easier to use. I also have a GPS hookup into a 2D viewer that I will integrate into the 3D system, along with some modules to download the satellite photos automatically and stitch them together, etc. All should be ready soon.
I really appreciate your help, so if you're interested, I will send you a source code beta as soon as its cleaned up a bit. My e-mail is in the contact section of my virtualpipeline MSN space webpage. Let me know where I can reach you.
Now that time isn't the problem.... away from the bits and on to steam. The neatest gift I ever got for Xmas was one of those little German steam engines.
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
Each pixel represents 3 seconds of latitude and 3 seconds of longitude. A geographically correct plot really should be compressed 80% in the horizontal direction, since at this latitude, 1 degree of longitude is 80% that of 1 degree of latitude.
Thanks for your help.
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
I have now morphed the program into an OGL terrain viewer. The Elevation version above now has a line of sight module, which can be used for U/VHF antenna or forest fire tower positioning, etc. Work continues on the 3D terrain viewer using freely downloaded satellite photos from www.terraserver.com. Photos must be corrected for latitude & longitude before use, but the program will do it for you. Here's an example of the latest output. This view is from a perspective along the approach path to Gibraltar's airport... from the west.
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting
Steam Engine enthusiasts: www.essexsteam.co.uk
RE: Open and read a bin file
I thought you were invoved in locomotive work and was quite surprized to see that I guessed wrong. I didn't expect to see the steam tractors. I also didn't think they were as complicated as they are. Quite facinating and a very complex piece of work reconditioning one. Rolling a finished product out of the shop must be a special feeling. It is really an acomplishment to be proud of.
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com
RE: Open and read a bin file
RE: Open and read a bin file
BigInch-born in the trenches.
http://virtualpipeline.spaces.msn.com