I am trying to clip or crop out the area of interest from a multi-spectral tiff file downloaded from Sentinel-2, using Rasterio and GeoPandas. For reference here are the code snippets -
import geopandas as gpd
import rasterio
from rasterio.mask import mask
rast_path = "Square_1.tiff"
mask_path = "Ranchi.geojson"
geo = gpd.read_file(mask_path)
print(geo.crs)
with rasterio.open(rast_path) as src:
print(src.crs)
out_image, out_transform = mask(src, geo.geometry)
profile = src.profile
with rasterio.open("output.tif", "w", **profile) as dst:
dst.write(out_image)
Upon viewing it using Rasterio's show
, I am getting the correctly cropped image -
But on viewing it using QGIS the raster layer is becoming a blank one.
Please let me know what is the correct way to clip or if I am missing a step?
print(profile)
, it make people easy to understand your issue.