[GIS] gdal_translate -a_nodata

gdalgdal-translateraster

I have an ESRI ASCII file with usual 6 rows of headers followed by elevation values in metres. The NO_DATA value in the header is set to -9999.

I am trying to convert this ASCII to XYZ using gdal_translate and do not want to include nodata values of -9999 in the output XYZ File. I am using the a_nodata command to ignore -a_nodata values in the output XYZ file however have so far been unsuccessful in getting this to work. I'm hoping someone can help me out as to where I am going wrong with the -a_nodata command. I've included my current code below which creates the XYZ file but does not ignore no data values.

gdal_translate -of XYZ D:\WORK\COASTAL_PRODUCTS\P_10853\ASCII_GRIDS\DSM\tq6575_20161005lidaru.asc D:\WORK\COASTAL_PRODUCTS\P_10853\ASCII_XYZ\DSM\tq6575_20161005lidaru.txt -a_nodata -9999 

Best Answer

The nodata values are part of a raster. The XYZ format is still a raster format and needs the nodata values to maintain a regular grid. This is why you can't get gdal not to write them out. If it did, it wouldn't be able to read it again.

However you can avoid writing NoData values to your output by stripping them out with an external program. To do this, write the output to stdout then pipe to findstr to filter it before writing to your csv:

gdal_translate -q -of xyz -co ADD_HEADER_LINE=YES -co COLUMN_SEPARATOR="," input_raster /vsistdout | findstr /V /C:"your_nodata_value" > output.csv 
Related Question