如何将 png 文件转换为 geotiff [英] How to convert png files to geotiff

查看:149
本文介绍了如何将 png 文件转换为 geotiff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组 png 文件和 EPSG:3006 每个文件边缘的坐标.如何使用 Python 将这些 png 文件转换为 geotiff 文件,以便 tiff 文件包含地理元数据.
我想它可以用 Rasterio lib 来完成,但我不确定具体如何.

I have set of png files and EPSG:3006 coordinates of the edges of each file. How can I convert those png files to geotiff files using Python so the tiff files would contain the geo metadata.
I guess it can be done with Rasterio lib, but I'm not sure how exactly.

推荐答案

找到了解决方案:

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'}

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

这篇关于如何将 png 文件转换为 geotiff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆