为使用rasterio读取的文件设置CRS [英] Set CRS for a file read with rasterio

查看:21
本文介绍了为使用rasterio读取的文件设置CRS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rasterio在Python中读取jpg图像及其关联的坐标文件,如下所示:

import rasterio
with rasterio.open('/path/to/file.jpg') as src:
    print(src.width, src.height)
    print(src.crs)
    print(src.indexes)
正确读取图像文件及其关联的坐标文件,但未定义CRS(I guess that's because world file doesn't contain the CRS)。以下是输出:

5000 5000
None
(1, 2, 3)

读取文件后如何在Rasterio中手动设置CRS?

推荐答案

在没有看到坐标文件的情况下,我不确定这是否详细正确,但我已经使用以下内容在读取包含坐标文件的文件后将变换和crs添加到栅格中:

from affine import Affine
import rasterio.crs

a, d, b, e, c, f = np.loadtxt(world_filename)    # order depends on convention
transform = Affine(a, b, c, d, e, f)
crs = rasterio.crs.CRS({"init": "epsg:4326"})    # or whatever CRS you know the image is in    
with rasterio.open('/path/to/file.jpg', mode='r+') as src:
    src.transform = transform
    src.crs = crs

这篇关于为使用rasterio读取的文件设置CRS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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