如何将png文件转换为geotiff

时间:2019-10-22 13:19:08

标签: python png geotiff rasterio

我有一组png文件和每个文件边缘的EPSG:3006坐标。如何使用Python将这些png文件转换为geotiff文件,以便tiff文件包含geo元数据。
我想可以用Rasterio lib做到,但是我不确定它到底是怎么做到的。

1 个答案:

答案 0 :(得分:0)

找到解决方案:

dataset = rasterio.open(input_file_path, 'r')
bands = [1, 2, 3]
data = dataset.read(bands)
transform = rasterio.transform.from_bounds(west, south, east, north, data.shape[1], data.shape[2])
crs = {'init': 'epsg:3006'}

with rasterio.open(output_file_path, 'w', driver='GTiff',
                   width=data.shape[1], height=data.shape[2],
                   count=3, dtype=data.dtype, nodata=0,
                   transform=transform, crs=crs) as dst:
    dst.write(_data, indexes=bands)