[GIS] How to remove nodata values from XYZ output with GDAL

gdalgdal-translatenodatarasterxyz

I have a buffered line route that is overlayed on a DEM:

enter image description here

I've clipped the DEM to the buffered line, and exported it as an ADF ESRI grid file. I then used gdal_translate to convert it from the Arc/Info ASCII Grid to the ASCII Gridded XYZ. This all works fine, but the output XYZ has tens of thousands of entries for elevation marked as -32768 which I assume is nodata.

enter image description here

How can I have the output XYZ file only contain values that aren't -32768? Is there a tool or parameter in GDAL I'm missing?

And why are there nodata values? Is the raster I export after clipping really a rectangle with nodata values where the buffered line isn't present?

The XYZ file is going to be used in PLS-CADD.

Best Answer

The output XYZ file can be filtered in order to exclude NoData (-32768) values using ogr2ogrchanging the layer extension to .csv (to make it recognizable as CSV by ogr2ogr):

ogr2ogr -f CSV -sql "SELECT x, y, z FROM output_XYZ_with_NoData WHERE z != '-32768'" output_XYZ_without_NoData.csv output_XYZ_with_NoData.csv -lco SEPARATOR=SPACE
Related Question