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.height)
print(src.crs)
print(src.indexes)
The image file and its associated world file are correctly read, however the CRS is undefined (I guess that's because world file doesn't contain the CRS). Here is the output:
5000 5000
None
(1, 2, 3)
How to set the CRS manually in Rasterio after reading the file?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With