1

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
11
  • What is the format of the file? Commented Feb 28, 2016 at 11:03
  • the format of the file which I imported was first dat. But I changed it from dat to txt. It contains the following: LATITUDE LONGITUDE HEIGHT
    – yPennylane
    Commented Feb 28, 2016 at 11:05
  • try changing it to ascii, (asc) Commented Feb 28, 2016 at 11:09
  • Do I do this by just changing the txt to asc?
    – yPennylane
    Commented Feb 28, 2016 at 11:10
  • I've never really tried using dat files myself, but .txt can be converted to .asc easily enough. Commented Feb 28, 2016 at 11:12

3 Answers 3

4

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.

1

Just create a new text layer, whatever the file extension, find the correct parameters : enter image description here

And here is result: enter image description here

1
  • Thanks for your answer. Do you know how to convert this file to a tiff file?
    – yPennylane
    Commented Feb 28, 2016 at 18:00
1

In one of your comments you state:

When I try to convert it, the following message appears: ERROR 1: Ungridded dataset: At line 2, X spacing was -0.025000. Expected >0 value GDALOpen failed - 1 Ungridded dataset: At line 2, X spacing was -0.025000. Expected >0 value

You will get this if your coordinates not ordered correctly. According to the XYZ format documentation, your file must be sorted by Y coordinates first, either ascending or descending and then by X coordinates in ascending order.

So to open your .dat file directly in QGIS (or use GDAL tools, such as gdalinfo or gdal_translate), open your .dat in Excel,Libre Office Calc or a decent text editor such as Notepad++ and sort the coordinates appropriately.

i.e

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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