Welcome, Guest
Username: Password: Remember me

TOPIC: Converting .tif to .xyz

Converting .tif to .xyz 2 years 4 months ago #39589

  • R.Wei
  • R.Wei's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
  • Thank you received: 7
Hi everyone,

Happy new year!

I have a primitive and basic question regarding converting DEM data to XYZ data. I normally use QGIS 3.20 to extract xyz file, the operation step is "Raster => extraction => clip raster by mask layer". However, the size of generated xyz file sometimes can be 4 GB while the original dem file is 200 Mb. This is really crazy. Is there any solution to reduce the size of xyz file during operation?

Regards,
Wei
The administrator has disabled public write access.

Converting .tif to .xyz 2 years 4 months ago #39591

  • nicogodet
  • nicogodet's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 128
  • Thank you received: 31
Hi,

DEM files (especially .tif) can be created using compression methods (see GDAL documentation) that help to reduce the file size.
XYZ files are just a plain text file and these compression methods can not be applied.

Few ways of size optimisation:
  • reduce the resolution of the DEM (ex: from 1 meter to 5 meters) but you lose info
  • reduce decimal precision (GDAL XYZ Creation options)

Hope it helps
The administrator has disabled public write access.

Converting .tif to .xyz 2 years 4 months ago #39592

  • R.Wei
  • R.Wei's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
  • Thank you received: 7
Hi,

Thank you for your answer. According to the doc, it provides 4 options and I tried the 4th one "DECIMAL_PRECISION=4", yet qgis reported an error. It seems gdal doesn't understand it. Attached please find the snapshot of qgis input and the error log.


input_qgis.png



By the way, I found this post (gis.stackexchange.com/questions/201224/c...raster-value-in-qgis). It offered a solution to erase nodata_values by using command (gdal_translate -q -of xyz -co ADD_HEADER_LINE=YES -co COLUMN_SEPARATOR="," input_raster /vsistdout | grep -v "your_nodata_value" > output.csv ). This seems promising as well. But as you may tell from the above words, I'm new to qgis command. Tried to typing the command in "ADDITIONAL COMMAND-LINE PARAMETERS" , but it failed. Any chance you may know the proper way to do it?
Attachments:
The administrator has disabled public write access.
The following user(s) said Thank You: Sorrymaker

Converting .tif to .xyz 2 years 4 months ago #39593

  • nicogodet
  • nicogodet's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 128
  • Thank you received: 31
Instead of
DECIMAL_PRECISION=4
It should be
-co DECIMAL_PRECISION=4

Regarding your second issue, the command have to be executed in a terminal, not in QGIS.
gdal_translate -q -of xyz -co ADD_HEADER_LINE=YES -co COLUMN_SEPARATOR="," -co DECIMAL_PRECISION=4 path/to/your/raster.tif /vsistdout | grep -v "your_nodata_value" > output.csv
The administrator has disabled public write access.
The following user(s) said Thank You: R.Wei

Converting .tif to .xyz 2 years 4 months ago #39612

  • R.Wei
  • R.Wei's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
  • Thank you received: 7
Thank you sooooo much. It really helped me a lot.
The administrator has disabled public write access.

The open TELEMAC-MASCARET template for Joomla!2.5, the HTML 4 version.