我正在使用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?
答案 0 :(得分:0)
在没有看到世界文件的情况下,我不确定具体细节是否正确,但是在读取带有世界文件的文件后,我使用以下内容将转换和CRS添加到栅格中: / p>
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') as src:
src.transform = transform
src.crs = crs