Kartoza - Generating an XYZ ASCII File from a QGIS Raster
Someone wrote to me asking if it would be possible to generate an XYZ ASCII file from a single band raster layer in QGIS.
Someone wrote to me asking if it would be possible to generate an XYZ ASCII file from a single band raster layer in QGIS. No doubt there are more efficient ways (this approach is pretty slow but it works), but I thought it would be fun to show how you can iterate over a raster, writing out the value of each cell into a text file (along with the centroid coordinates for that cell).
To use the script, you should save it to your local machine, then open the python console and load the script in the python editor. Next select a single band raster and then run the script in the editor. If your raster is quite large, it will take some time to run. I have spent zero time trying to optimise the script - if someone has an idea for doing it faster, send me a patch and I will update the example above.
The generated output dataset will look something like this:
Longitude,Latitude,VI8.31259406548,7.86128343221,108.31264849753,7.86128343221,168.31270292958,7.86128343221,188.31248520138,7.8613378416,158.31253963343,7.8613378416,178.31259406548,7.8613378416,248.31264849753,7.8613378416,468.31270292958,7.8613378416,47...
The resulting script can be used with programs like gdal_grid or loaded back into QGIS as a vector layer using the Delimited Text provider:
No comments yet. Login to start a new discussion Start a new discussion