您可以使用GDAL执行此操作,它直接支持XYZ格式。坐标是否为UTM都无关紧要,gdal_translate将在同一坐标系中输出。
因此,转换为GeoTIFF很简单:
gdal_translate test.xyz test.tif
查看GeoTIFF文档以获取输出选项(例如压缩),并查看gdal_translate文档以获取更多使用信息。特别是,您应该使用-a_srs
参数指定坐标系。
-a_srs srs_def:
覆盖输出文件的投影。srs_def可以是任何常用的GDAL / OGR格式,完整的WKT,PROJ.4,EPSG:n或包含WKT的文件。
gdal_translate -a_srs EPSG:12345 test.xyz test.tif
支持以逗号/空格分隔和固定的列宽(带或不带标题行)。
支持的列分隔符是空格,逗号,分号和列表。
$ head -n 2 test_space.xyz
x y z
146.360047076550984 -39.0631214488636616 0.627969205379486084
$ gdalinfo test_space.xyz
Driver: XYZ/ASCII Gridded XYZ
Files: test_space.xyz
Size is 84, 66
Coordinate System is `'
Origin = (146.359922066953317,-39.062997159090934)
Pixel Size = (0.000250019195332,-0.000248579545455)
Corner Coordinates:
Upper Left ( 146.3599221, -39.0629972)
Lower Left ( 146.3599221, -39.0794034)
Upper Right ( 146.3809237, -39.0629972)
Lower Right ( 146.3809237, -39.0794034)
Center ( 146.3704229, -39.0712003)
Band 1 Block=84x1 Type=Float32, ColorInterp=Undefined
Min=0.336 Max=0.721
$ head -n 2 test_commas.xyz
x, y, z
146.360047076550984, -39.0631214488636616, 0.627969205379486084
$ gdalinfo test_commas.xyz
Driver: XYZ/ASCII Gridded XYZ
etc...
$ head -n 2 test_formatted.xyz
x y z
146.3600471 -39.06312145 0.627969205
$ gdalinfo test_formatted.xyz
Driver: XYZ/ASCII Gridded XYZ
etc...
我知道的唯一陷阱是:
- 大数据集的打开速度可能很慢,因为驱动程序必须扫描整个文件以确定数据集的大小和空间分辨率。和
该文件必须正确排序(按Y,然后按X)。
具有相同Y坐标的像元必须放在连续的行上。对于相同的Y坐标值,必须通过增加X值来组织数据集中的线。但是,Y坐标的值可以增加或减少。
$ head -n 5 test.csv
x,y,z
146.3707979,-39.07778764,0.491866767
146.3787985,-39.07157315,0.614820838
146.3637974,-39.07132457,0.555555582
146.3630473,-39.07579901,0.481217861
$ gdalinfo test.csv
ERROR 1: Ungridded dataset: At line 3, too many stepY values
gdalinfo failed - unable to open 'test.csv'.
$ tail -n +2 test.csv| sort -n -t ',' -k2 -k1 > test_sorted.xyz
$ head -n 5 test_sorted.xyz
146.3600471,-39.07927912,0.606096148
146.3602971,-39.07927912,0.603663027
146.3605471,-39.07927912,0.603663027
146.3607971,-39.07927912,0.589507282
146.3610472,-39.07927912,0.581049323
$ gdalinfo test_sorted.xyz
Driver: XYZ/ASCII Gridded XYZ
etc...