[GIS] Converting DEM text file to tiff file in QGIS

demqgis

I am trying to convert a digital elevation model in txt file format to a raster file (tiff) with qgis.

The file format is *.dat. The coordinate system is Gauss Krüger, Bessel, 5. meridian.

First I imported the txt file with the appropriate coordinate system. Now I want to convert it to a raster file. However the viewed data are black and I dont see any heights. What did I do wrong? Follow the link to view the screenshot of the imported dem in qgis:
Screenshot qgis

When zooming in it looks like this:
Screenshot zoomed in

This is an example of the data:

LATITUDE    LONGITUDE   HEIGHT
5390.0125   5659.9875   258.6
5390.0125   5659.9625   252.6
5390.0125   5659.9375   243.9
5390.0125   5659.9125   237.1
5390.0125   5659.8875   234.5
5390.0125   5659.8625   231.2
5390.0125   5659.8375   233.7

Best Answer

I believe we are talking here about regular DEM XYZ text file. The issue is that you need to have your XYZ data in very specific order to be able to read as GRID (Gridded XYZ)

  1. Cells with same Y coordinates must be placed on consecutive lines
  2. For a same Y coordinate value, the lines in the dataset must be organized by increasing X values
  3. The spacing between each cell must be constant and no missing value is supported

Once you have that you can use gdal_translate (In QGIS Raster / Conversion / Translate...)

A while back I created a python script which can be used for ordering XYZ data into proper order and filling up the missing data. Unfortunately I don't own rights to make that script publicly available.

What I can suggest instead if you can't make script yourself is to do it this way manually:

  1. import XYZ into QGIS as add Delimited text layer
  2. use Raster / Conversion / Rasterize... (where from your XYZ file you should be able to figure out the resolution and optionally extent).

I suggest to read manual on GDAL rasterize to be abble to adjust rasterize function to exactly what you need.