SRTM3 .hgt files have 1201*1201 DEM elevation data, I extract .hgt files data elevation into file Elevation.json with index.js with the help from this GitHub project.

Then I rename Elevation.json into Elevation.txt, replacing all ],[ from inside the converted .hgt file in json array into ]^l[ with MS Word to get each row from json at new line.

Finally, I import this .txt file into .xlsx file with "comma" as separating delimiter.

I expect as final result in Excel, just 2101 rows and 2101 columns.

Why is there an error always at these cells?

I shortcuted the first and the last 3 columns and the first and the last 2 rows to show you the result

enter image description here.

Note: blank cells = no found data.

I tried different .hgt file from world wide, the problem still exist.

  • Is there any similar node.js other than in this project above, that can exctract the data from hgt files? – Khaled Feb 2 '18 at 5:07

I think it is bug in index.js. I just replicate what you did but differently, and got to the same result:

I run index.js in a .hgt file, then replaced the "],[" by new lines and removed any extra "[" or "]" doing

cat heights.json | sed 's/\],\[/\n/g' | tr -d ']' | tr -d '[' > heights.csv

Then loading the csv in matlab in fact produced an error of inconsistency in the number of columns per row.

By counting the number of commas per line using:

sed 's/[^,]//g' heights+cr.txt | awk '{ print length }'

It indeed show that the first row has 1202 columns, the last 1200 columns and all the rest 1201 columns.

However, after loading the same .htg file directly in Matlab, it produce a nice 1201x1201 matrix.

You can load it directly in Matlab with the following code:

fileID=fopen('S40W067.hgt','r');% Replace by your HTG file
data = fread(fileID,[1201,1300],'uint16',0,'b');

If you rather python, this question show some code examples.

By looking at the data from index.js and from Matlab, it seem that if you move the extra element at the end of row one, to be the first of row two, and then the last of two to be the first of the third row and so on, you will end up with the correct 1201x1201 data matrix.

  • Thank you Camilo for you work, confirming that it is a debug in file node.js, I hope that one can solve it – Khaled Feb 9 '18 at 14:46
  • @Khaled You welcome. That github seem inactive for a while, but still I would recommend you to post a bug report. If you found my answer satisfactory, please accept it. – Camilo Rada Feb 12 '18 at 17:17
  • Sorry, I clicked twice, for accepting without intention, I didnt notice that – Khaled Feb 12 '18 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.