1

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 
  • Comments are correct on my answer - this will only assign no data values to these (as opposed to removing them entirely). @Luke's answer will work, or else you can use gdal_calc and avoid setting nodata values entirely: gis.stackexchange.com/questions/121110/… – AlecZ Nov 13 '17 at 18:57
2

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 
0

You're almost there - also need quotes on the output format but this should work fine.

gdal_translate -of "XYZ" D:\WORK\COASTAL_PRODUCTS\P_10853\ASCII_XYZ\DSM\tq6575_20161005lidaru.asc D:\WORK\COASTAL_PRODUCTS\P_10853\ASCII_GRIDS\DSM\tq6575_20161005lidaru.xyz -a_nodata "value [-9999]" 
  • This won't work . Nodata will still get written. . – user2856 Nov 13 '17 at 18:54
0

This task can be accomplished in two steps: first, convert the ESRI ASCII file into an XYZ one, adding the header line and using the csv extension in the output file. Finally, use a bit of OGR SQL to skip records with NoData values:

gdal_translate -of XYZ input_ASCII_with_NoData.asc output_XYZ_with_NoData.csv -co ADD_HEADER_LINE=YES
ogr2ogr -f CSV -sql "SELECT x, y, z FROM output_XYZ_with_NoData WHERE z != '-9999'" output_XYZ_without_NoData.csv output_XYZ_with_NoData.csv -lco SEPARATOR=SPACE

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.