python - 为使用 rasterio 读取的文件设置 CRS

标签 python gis rasterio

我正在使用 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

关于python - 为使用 rasterio 读取的文件设置 CRS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52985957/

相关文章:

python - 检查字符串是否包含列表中单词的子集的单词

python - 使用 lambda 的 relu 激活函数

python - 如何将 netCDF4 文件转换为 geoTiff

python - 导入模块(rasterio)因 conda 或 pip 安装而失败

mysql - 哪些使用 PostGIS 可以完成而使用 MySQL 无法完成的事情?

python - 如何使用rasterio更改光栅的crs?

javascript - 将带有空格的文本从 python 后端传递到 html View

python - 如何自动更新 trac wiki 页面?

r - 使用 shapefile 使用 R 绘制等值线图

sql-server-2012 - 空间结果选项卡说 :One or more spatial objects were too large to display