I am new to GIS and I want to merge xyz tiles to one raster tiff.
Here is the source to the xyz files:
dgm1_05314000_Bonn_EPSG4647_XYZ.zip
I have downloaded the tiles as .xyz files, then sorted the coordinates with this bash command (since they are for some reason not in the standard format):
for file in *.xyz;
# sort coordinates
do sort -k2 -n -k1 "$file" -o "$file";
done
gdalinfo for one of the tiles gives me:
Driver: XYZ/ASCII Gridded XYZ
Files: dgm1_32372_5622_2_nw.xyz
Size is 2000, 2000
Coordinate System is `'
Origin = (32371999.500000000000000,5621999.500000000000000)
Pixel Size = (1.000000000000000,1.000000000000000)
Corner Coordinates:
Upper Left (32371999.500, 5621999.500)
Lower Left (32371999.500, 5623999.500)
Upper Right (32373999.500, 5621999.500)
Lower Right (32373999.500, 5623999.500)
Center (32372999.500, 5622999.500)
Band 1 Block=2000x1 Type=Float32, ColorInterp=Undefined
Min=87.800 Max=160.880
Then I want to run to get a .vrt file:
gdalbuildvrt mosaic.vrt *.xyz
But I am getting the following error:
Warning 6: gdalbuildvrt does not support positive NS resolution. Skipping (filename).xyz
How can I now merge these tiles to one raster tiff?
Any alternatives are also welcome.
Best Answer
So here is a full outline of my solution. It seems that the xyz. tiles have an odd formatting since the coordinates are not in the expected order and have a positive N-S pixel resolution. To fix the coordinates I first sorted the coordinates:
The positive N-S pixel resolution means that the origin of the images are not in the upper left corner of the image but in the lower left (which is quite unusual). To fix this issue I found a workaround here. The gdal warp command with the correct EPSG code fixes the issue:
Then I could build a .vrt and convert it to a tif: