I am trying to clip a raster data with GDAL warp. I want data values of raster within the buffer.
import rasterio as rio import shapely as shp import geopandas as gp import numpy as np raster=rio.open('C:/Users/schol/montreal_500m.tif') band=raster.read() y=45.508888 x=-73.561668 poly=shp.geometry.Point(x,y).buffer(0.1) crs='EPSG:4326' my_poly=[poly] mydat=gp.GeoDataFrame(crs=crs,geometry=my_poly) mydat.to_file("C:/Users/schol/mypo.shp") import gdal ras_in='C:/Users/schol/montreal_500m.tif' shp_in="C:/Users/schol/mypo.shp" ras_out='C:/Users/schol/montreal_clip.tif' result=gdal.Warp(ras_out,ras_in,cutlineDSName=shp_in,dstNodata=np.nan) When I get the minimum and maximum value - minimum says -41.46 and the maximum says nan. When seeing the clipped raster array it has a maximum value of 200. Also the input raster and the clipped raster both have same dimension. How is this happening and where am I doing it wrong?
Also, when I use this line below, I am not getting the clipped raster as output at all. And I need to get the clipped output like this with gdal.
result=gdal.Warp(ras_out,ras_in,cutlineDSName=shp_in,cropToCutline=True,dstNodata=np.nan) 
