" />
Chez Éric Sibert
+ Accueil du site > Géographie > Données

Format of Vista Pro DEM files

The purpose of this page is to explain how to decode the "dem" files such as you can find it in Visual DEM France .

Mis en ligne le 9/03/2005

The purpose of this page is to explain how to decode the "dem" files such as you can find it in Visual DEM France .

Each file represents an area of 258x258 points. You can find in the ctp files all datas usefull for georeferencing these files. For example, the files Visual DEM France are based on the extended Lambert II projection with a step of 75 meters. Using this, we can calculate the size of a file in meter. You should take into account an overlapping between near files, equal to a line or of a column according to the direction, which gives you effective dimensions of 256x256 points, i.e. 19,2x19,2 km².

A file starts with a header of $800 bytes. You can ignore it. After, datas are encoded line by line from the south to the north. Each line is encoded from west to east.

Overview :
- At the beginning of a line, the starting elevation is provided on two bytes. Then, you go to the following point by coding the difference of elevation on one byte except when the difference is too large. Then, you calculate again the elevation with an absolute elevation on two bytes. And so on until the end of the line. With this, a compression of the areas with constant elevation is added. This compression is similar to RLE, namely a byte indicates either the number of repetition, or the number of normal coding before the next repetition.

Practice :
To simplify the work, we will proceed to the decoding in two steps. The first step consists in replacing compression by their repetitions. The second spet will give the absolute elevations by using the relative one.

The first two bytes of the line contain the length of the (compressed) line in the file.

At the beginning of the line (after the 2 bytes indicating the length), one takes the first byte. Let call C his value. If C is equal or higher to 128, this is a repetition of 257-C time the following byte. If C is lower than 128 then there are no repetitions during the next C+1 bytes. You just need to use the next C+1 as they are. When you arrive at the end of one of the two sequences defined above (repetition or normal coding), you start again with examinating the first byte after the sequence and again you compare it with 128. The decompressed line is step after step gradually reconstituted. When you have used all the byte of the compressed line, you have got the uncompressed line.

Variation of elevation
We now use the uncompressed line.The first two bytes provide the absolute elevation (first*256+second) at the beginning of the line. Then, the value of the byte that you find indicates how to calculate the elevation of the next point :
- C=128 : absolute elevation calculated according to the two next bytes.
- C < 128 : elevation’s increase is equal to C, compared to the previous point.
- C>129 : elevation’s decreases equal to 256-C compared to the previuos point (or an increases of C if C is a shortInt).
When you have got 258 altitudes, you are at the end of the line.

That’s all.

Zip - 2.7 ko
Code source pour la décompression DEM -> TXT

Just find enclosed a Delphi 6 project, which converts a DEM file into TXT one.

Copyright : droit d'auteur Éric Sibert. Site réalisé avec SPIP.