[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Reading "ArcGrid" formated geological data on Debian? Alternatives?



Hi Brett,

The data is also available in GeoTiff format (there are lots of geotiff 
viewers around) using a nice interactive interface at:

	http://srtm.csi.cgiar.org/SELECTION/inputCoord.asp

Alternatively, they are available as a raw binary file from:

	ftp://e0srp01u.ecs.nasa.gov/srtm/version2/SRTM3/

downloading the tiles you want. For information on the binary format, see

	ftp://e0srp01u.ecs.nasa.gov/srtm/version2/Documentation/SRTM_Topo.pdf

They are called "hgt" files but they aren't really anything scary to parse.... 
it's just row-major 16-bit unsigned int data in big-endian format. It's 
trivial to read in most languages including C, Perl, Fortran etc, e.g. 
(cutting a relevant bit of old C code I have around here [1]):

--------------- 8< -----------------

  FILE *dem;
  int i,j;
  short height;
  double** d;

  dem = fopen(filename, "rb");

  d = (double**) malloc(sizeof(double*)*numRows);
  
  for (i=0; i<numRows; i++) {
    d[i] = (double*) malloc(sizeof(double)*numColumns);
  }
  
  for (i=0; i<numRows; i++) {
    for (j=0; j<numColumns; j++) {
      fread(&height, 2, 1, dem);
      d[j][i] = byteswap(height);
    }
  }

short byteswap(short a) {
  int b;
  b  = (a & 0x00FF) << 8;
  b += (a & 0xFF00) >> 8;
  return b;
}

--------------- 8< -----------------

have fun with it!

cheers
Stuart


[1] it's pretty crap C, I know that, but it works. This was going to be part 
of a SRTM to Garmin GPS map project that I started work on ages ago. It was 
to be a GPL'd method of creating contour maps for the Garmin mapping GPS 
units. I got as far as SRTM to contour listing in "polish" format which links 
in with a shareware "polish" to garmin converter, but never really finished 
that section off and started work on the polish to garmin converter [2]. 
You're free to do whatever you want with that code snippet!

[2] But if someone else wants to help out with getting this working, I'll 
happily resurrect that project as I still need these tools occasionally.


-- 
Stuart Prescott                 www.nanoNANOnano.net


Reply to: