GDAL – Processing Slovenian LiDAR DTM in QGIS with Error Fix

demgdallidarqgis

If I want to apply GDAL (version 2.2.3) on the LiDAR derived DTM (ASCII) from Slovenia (Link to Slovenian DTM below), I run into this error:

gdalinfo input.asc

ERROR 1: Ungridded dataset: At line 214, too many stepY values
gdalinfo failed - unable to open 'input.asc'.

The files can neither be loaded into QGIS (3.4.12).

I read here, that there is a XY swap in the files and sort can be used to get rid of the XY swap:

sort -k2 -n -k1 -t ';' input.asc -o output.xyz

However, after applying this to the .asc, I run into the following error:

gdalinfo output.xyz 

ERROR 1: Ungridded dataset: At line 1002, too many stepY values
gdalinfo failed - unable to open 'output.xyz'.

What can I do to apply GDAL to the data?

The LiDAR can be accessed for free here: ARSO. Here is a direct download link to a sample ASCII file (D48GK projection): GK1_444_106.asc

Best Answer

Your data is not a regular grid, you have missing points. The XYZ format description specifies "no missing value is supported".

Below is an image of a small section of the western edge of the data visualised as points showing the missing values.

enter image description here

To convert your data to raster, you can use gdal_grid. gdal_grid doesn't support the full range of OGR open options syntax (i.e see the CSV format description) so you need to create a VRT that tells gdal_grid how to create geometry from the X and Y fields.

<OGRVRTDataSource>
    <OGRVRTLayer name="GK1_444_106">
        <SrcDataSource>CSV:GK1_444_106.asc</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <LayerSRS>EPSG:3794</LayerSRS>
        <GeometryField encoding="PointFromColumns" x="field_1" y="field_2"/>
    </OGRVRTLayer>
</OGRVRTDataSource>

You can then use gdal_grid to output a raster:

gdal_grid -a_srs EPSG:3912 -a nearest -txe 443999.5 445000.5 -tye 106999.65 105999.65 -outsize 1001 1000 -zfield field_3 -l GK1_444_106 GK1_444_106.vrt GK1_444_106.tif

enter image description here

Related Question