6

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.

  • I have noticed that too, I wrote a python script to remove values from the XYZ file, would that interest you? – Michael Stimson Sep 9 '15 at 1:32
  • @MichaelMiles-Stimson thanks for the offer, but that's what I've done for now. I was hoping there'd be way to remove that step. Because my scenario above is just an example. The DEM is from lidar and has 1m resolution. The output XYZ is over 1GB with millions of points, and 90% are probably nodata. I'm just really surprised there's (apparently) no parameter in GDAL to do this. – geogeogeo Sep 9 '15 at 1:39
  • 1
    So was I. There's nothing in the driver that would allow for skipping NoData records. It seems like a waste of time and space writing a file that contains 90% unused information but that's how it goes... the other side of the coin is perhaps a python script to go through each cell and only export the valid values, GDAL has python bindings and you can read individual rows or columns (or even cells, but that's slow) then using the GeoTransform for origin and cell size write each record. – Michael Stimson Sep 9 '15 at 2:34
  • For GDAL XYZ is another raster format just like tiff or jpeg and the behavior of creating a rectangle full or pixels is not so odd. Perhaps GDAL could be made to use nodata=NULL. Ask from gdal-dev. – user30184 Sep 9 '15 at 4:20
  • 2
    The core of the problem is that you are using a 'gridded ascii xyz' and not a regular 'ascii xyz'. If you open your 'gridded ascii xyz' file in a decent text editor capable of working on large files, you will notice that it is not a xyz-file in the traditional sense. Instead it contains a header with projection information etc, and then a bulk with z-information, but no x and y. This is in essence a raster. What you want is a xyz file, where each point has all three coordinates and no no-data points remain. To create such a file, I usually use R-scripts, but it is reasonably easy to implement. – Mikkel Lydholm Rasmussen Sep 9 '15 at 8:05
2

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

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.