Skip to content

Instantly share code, notes, and snippets.

@bmount
Last active December 10, 2015 23:28
Show Gist options
  • Select an option

  • Save bmount/4509022 to your computer and use it in GitHub Desktop.

Select an option

Save bmount/4509022 to your computer and use it in GitHub Desktop.
Reading SRTM hgt files in JavaScript
f = require('fs')
h = f.readFileSync('sfoak_srtm_vox.buf')
// read the (1/4 over, 1/4th down) point, 2nd arg would be 3601* 500 + 100 for 50th x in 250th row (2 bytes per record):
g = new DataView(h, Math.pow(2, 3601)/2, 1000)
> g.getInt16(0, true)
97
> g.getInt16(1, true)
24320 // wrong, next int16 is two bytes over
> g.getInt16(2, true)
95 // correct
> h = f.readFileSync('N37W123.hgt')
> g = new DataView(h, Math.pow(2, 3601)/2, 1000)
> g.getInt16(0, true)
24832 // wrong, big endian DataView default useful at last
> g.getInt16(0, false)
97 //correct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment