Set Crs For A File Read With Rasterio
I am reading a jpg image and its associated world file in Python with Rasterio like this: import rasterio with rasterio.open('/path/to/file.jpg') as src: print(src.width, src.
Solution 1:
Without seeing the world file, I don't know for sure if this is correct in detail, but I've used the following to add the tranform and CRS to a raster after reading in a file with a world file:
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
Post a Comment for "Set Crs For A File Read With Rasterio"