gdal_translate creates images that are mirrored
The .xyz
file is sorted in an unusual way, X ascending and Y ascending. Most GDAL drivers can handle that orientation by flipping the image internally. Thus the "upper" and "lower" coordinates are flipped too:
Driver: XYZ/ASCII Gridded XYZ
Files: test.xyz
Size is 500, 2
Coordinate System is `'
Origin = (715000.000000000000000,6575000.000000000000000)
Pixel Size = (10.000000000000000,10.000000000000000)
Corner Coordinates:
Upper Left ( 715000.000, 6575000.000)
Lower Left ( 715000.000, 6575020.000)
Upper Right ( 720000.000, 6575000.000)
Lower Right ( 720000.000, 6575020.000)
Center ( 717500.000, 6575010.000)
Band 1 Block=500x1 Type=Float32, ColorInterp=Undefined
Min=28.452 Max=31.080
NoData Value=0
If you sort the .xyz
file by X ascending and Y descending, the metadata appears in a logical way:
Driver: XYZ/ASCII Gridded XYZ
Files: testsort.xyz
Size is 500, 2
Coordinate System is `'
Origin = (715000.000000000000000,6575020.000000000000000)
Pixel Size = (10.000000000000000,-10.000000000000000)
Corner Coordinates:
Upper Left ( 715000.000, 6575020.000)
Lower Left ( 715000.000, 6575000.000)
Upper Right ( 720000.000, 6575020.000)
Lower Right ( 720000.000, 6575000.000)
Center ( 717500.000, 6575010.000)
Band 1 Block=500x1 Type=Float32, ColorInterp=Undefined
Min=28.452 Max=31.080
NoData Value=0
Unfortunately, the AAIGrid format is not designed for the first orientation, and noone has implemented to catch this issue by an error message or internally flipping back the coordinates. As a consequence, the header for AAIGrid gets generated wrong:
ncols 500
nrows 2
xllcorner 715000.000000000000
yllcorner 6574980.000000000000
cellsize 10.000000000000
NODATA_value 0
The following data is always linewise from upper left to lower right.
As a kind of hack, you can use gdalwarp instead of gdal_translate to save your raster as tif, and then translate to AAIGrid:
gdalwarp test.xyz 3301.tif
gdalinfo 3301.tif
gdal_translate -of AAIGRID 3301.tif 3301.asc
which delivers the correct header:
ncols 500
nrows 2
xllcorner 715000.000000000000
yllcorner 6575000.000000000000
cellsize 10.000000000000
NODATA_value 0