如何使用光谱python处理多光谱栅格文件?

Wra*_*raf 5 python raster gdal geotiff spectral-python

我有兴趣使用Spectral Python (SPy) 来可视化和分类多波段栅格 GeoTIFF(不是高光谱数据)。目前看来只有.lan文件.gis格式是可读的。

我尝试将文件转换为.lanwith gdal_translate,但不支持图像格式( IOError: Unable to determine file type or type not supported)。

知道如何将该库用于非超光谱数据集吗?

Mik*_*e T 4

将 GeoTIFF 文件转换为兼容格式(例如 LAN)。这可以通过两种方式之一完成。从系统 shell 中,使用gdal_translate

gdal_translate -of LAN file.tif file.lan
Run Code Online (Sandbox Code Playgroud)

或者在 Python 中类似:

from osgeo import gdal

src_fname = 'file.tif'
dst_fname = 'file.lan'
driver = gdal.GetDriverByName('LAN')

sds = gdal.Open(src_fname)
dst = driver.CreateCopy(dst_fname, sds)
dst = None  # close dataset; the file can now be used by other processes
Run Code Online (Sandbox Code Playgroud)

请注意,第一种方法实际上更好,因为它还传输其他元数据,例如空间参考系统和可能的其他数据。要在 Python 中正确执行相同操作,需要添加更多行代码。