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