Reputation: 127
I'm working with some TIFF images, and I want to add another band to an existing image.
Here's the code that I use to read the image:
# Read the image
image = rasterio.open('input.tiff')
with rasterio.open("input.tiff", 'r+') as src:
crs = rasterio.crs.CRS({"init": "epsg:4326"})
src.crs = crs
With this code, I'm able to change the CRS: here's the meta of image:
{'driver': 'GTiff',
'dtype': 'uint8',
'nodata': None,
'width': 524,
'height': 499,
'count': 3,
'crs': CRS.from_epsg(4326),
'transform': Affine(1.0, 0.0, 0.0,
0.0, 1.0, 0.0)}
I want to change the count value from 3 to 4.
I'm using rasterio.
Thanks in advance.
Upvotes: 2
Views: 969
Reputation: 86
You can read the metadata using .profile
and then update it.
with rasterio.open('input.tiff') as r:
profile = r.profile
profile.update(count = 4)
profile.update(crs = 'EPSG:32643')
Upvotes: 2