I have daily rainfall values in a NetCDF (.nc) file which is of larger extent covering a catchment area of a river basin. I want to crop it and extract the rainfall values that are within the catchment area. I have a shapefile of the catchment area. I am working in R and did like this:
crop(raster,e,filename="cropped_pr.nc",snap='near')
raster=source file
e<-extent(reference_raster) #extent of catchment area (rectangular boundary)
It crops the source file in a rectangular shape, as expected in the script, and includes values that are outside the catchment area too. However, the catchment area is not rectangular (polygon).
I want to make the values outside the catchment area as 0. It means I want the values which are within the catchment area only.