4

I have a series of text files that represent X,Y,Z elevation data. I'm trying to use the GDAL grid command line tool to convert these text files to raster GeoTIFs. My files are space delimited and so I have created VRT files that point to the data so that GDAL can read them OK. The VRT files work. I can load the layers into QGIS and I can use ogrinfo to describe the data OK.

Many of my text data files convert to raster just fine. These are typically longer files with > 10,000 lines of data. However, my small files (< 5,000 lines) produce a raster with only NoData values.

I am using the linear algorithm. My points are evenly spaced at 1m and I've tried several radius values. The command that I'm using is:

C:/OSGeo4W64/bin/gdal_grid.exe -ot Float32 -of GTiff -txe 239982.0 240207.0 -tye 647659.0 648667.0 -outsize 225 1008 -a linear:radius=1 D:\Temp\19900928.vrt D:\Temp\19900928.tif

I've also tried the nearest neighbour algorithm and get some weird, partial values in the output GeoTiFF for these small files.

A sample source text file is available here:

https://gist.github.com/philipbaileynar/c9eb76880b8ce6fa8c786ca53d892b26

The corresponding VRT file is:

<?xml version="1.0" ?>
<OGRVRTDataSource>
    <OGRVRTLayer name="elevation_points">
        <SrcDataSource>CSV:D:\Temp\elevation_points.txt</SrcDataSource>
        <SrcLayer>elevation_points</SrcLayer>
        <GeometryType>wkbPoint</GeometryType>
        <LayerSRS>EPSG:2762</LayerSRS>
        <GeometryField encoding="PointFromColumns" srs="EPSG:2762" x="field_2" y="field_3" z="field_4"/>
    </OGRVRTLayer>
</OGRVRTDataSource>

Can anyone help and figure out how to make GDAL grid produce a raster from these data please?

2

You can also try gdal_rasterize instead:

C:/OSGeo4W64/bin/gdal_rasterize.exe -ot Float32 -3d -tr 1 1 -of GTiff -te 239982.0 647659.0 240207.0 648667.0 -ts 225 1008 -a_nodata -9999 D:\Temp\19900928.vrt D:\Temp\199009.tif

The '-tr 1 1' will set the resolution at 1m which is what you want. Only problem with gdal_rasterize though is that if there's no points in the space, there won't be any raster pixels there. I.e. it won't do any extrapolation to fill in holes in your data, which may or may not be what you want.

enter image description here

  • Thanks but I intend to experiment with different spatial resolutions and so the empty space issue that you pointed out would be an issue. – user2723146 Jul 29 '16 at 19:25
0

I must say that I do not understand the parameters which are documented in http://www.gdal.org/gdal_grid.html

linear

(Since GDAL 2.1) Linear interpolation algorithm.

The Linear method performs linear interpolation by computing a Delaunay triangulation of the point cloud, finding in which triangle of the triangulation the point is, and by doing linear interpolation from its barycentric coordinates within the triangle. If the point is not in any triangle, depending on the radius, the algorithm will use the value of the nearest point or the nodata value.

It has following parameters:

radius: In case the point to be interpolated does not fit into a triangle of the Delaunay triangulation, use that maximum distance to search a nearest neighbour, or use nodata otherwise. If set to -1, the search distance is infinite. If set to 0, nodata value will be always used. Default is -1. nodata: NODATA marker to fill empty points (default 0.0).

However, it seems that using -a linear:radius=1 is wrong. If I remove the radius and let GDAL to use the defaults I get this result:

enter image description here

Command was:

gdal_grid -ot Float32 -of GTiff -txe 239982.0 240207.0 -tye 647659.0 648667.0 -outsize 225 1008  elevation_points.vrt elavation_points2.tif
  • This works and I get the same result. It's a pity that the linear doesn't work. If I get time, I'll download the GDAL source and try and debug it with these data. – user2723146 Jul 29 '16 at 20:19
  • Is there any progress on the linear interpolation? For me, it also seems not to be working.. – Willem van Opstal Sep 5 '17 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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