Skip to content

Instantly share code, notes, and snippets.

View kewgis's full-sized avatar

Karl-Erik Wilson kewgis

  • Ocean Winds
View GitHub Profile
@kewgis
kewgis / to_xyz.py
Created June 30, 2025 10:52
Re-order the values in the x,y and z columns of a text file (e.g. a bathymetry .pts/.xyz file) such that they conform to a true .xyz format readable by GDAL and openable in QGIS.
import csv
"""
This script re-orders the values in the x,y and z columns of a text file (e.g. a bathymetry .pts/.xyz file) such that they conform to a true .xyz format readable by GDAL and openable in QGIS.
In many cases the data in an "xyz" file falls foul of the GDAL requirement that:
“Cells with same Y coordinates must be placed on consecutive lines. For a same Y coordinate value, the lines in the dataset must be organized by increasing X values.”
https://gdal.org/en/stable/drivers/raster/xyz.html
"""