0

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 -

enter image description here

But on viewing it using QGIS the raster layer is becoming a blank one.

enter image description here

Please let me know what is the correct way to clip or if I am missing a step?

3
  • Check band statistics in QGIS layer properties.
    – user2856
    Commented May 27 at 6:47
  • or check a different vizualization style under properties > symbology. it's likely all there, but not displayed correctly. either you choose different bands to be displayed or the Min-Max values need to be adjusted etc.
    – Vincé
    Commented May 27 at 7:06
  • If you share the output of print(profile), it make people easy to understand your issue.
    – AMA
    Commented May 27 at 17:04

0