Project

General

Profile

extract region from shape file

Added by kunal bali over 6 years ago

Dear CDO users,

I am trying to extract the the region similar to the Tirpura shape file. So I am using the code given below but not working. I have attached Tirpura shape file and input file (var.nc).

var=cofire
cdo selname,$var var.nc Mask.nc

e=Tirpura.nc

cdo -L -div -addc,1 -abs $e -addc,1 -abs $e eMask.nc
cdo remapnn,var.nc eMask.nc e_region_Mask.nc
cdo div -selname,$var var.nc e_region_Mask.nc 2003_Tirpura.nc

Also, I have tried the same script for other shape file to extract the other region. And it worked fine for that region. So why it's not working for this shape file (Tirpura)

please provide some information on that.

Thank You

Tirpura.nc (3.6 MB) Tirpura.nc shape file
var.nc (6.21 MB) var.nc input file
Mask.nc (6.21 MB) Mask.nc mask for input file (not necessarily, but created)
e_region_Mask.nc (209 KB) e_region_Mask.nc getting problem here
eMask.nc (3.6 MB) eMask.nc
2003_Tirpura.nc (6.21 MB) 2003_Tirpura.nc output file

Replies (2)

RE: extract region from shape file - Added by Karin Meier-Fleischer over 6 years ago

Hi Kunal,

your var.nc file contains only the variable cofire, so you don't have to select the variable.

The shapefile Tirpura.nc contains only 0 and 255 where 255 is the missing value (missing_value is set to 255s!).

Following your script you want to remap the shapefile contents to the coarse grid of var.nc.

cdo -addc,1 -setctomiss,255 Tirpura.nc maskTirpura.nc              #-- set 255 to missing_value and add constant value 1

cdo remapbil,var.nc maskTirpura.nc e_region_Mask.nc                #-- remap the mask file to grid of var.nc

cdo ifthen e_region_Mask.nc var.nc 2003_var.nc                     #-- use cofire data when e_region_Mask.nc is 1

cdo sellonlatbox,91.1,92.4,22.4,24.6 2003_var.nc 2003_Tirpura.nc   #-- select the region of Tirpura

-Karin

RE: extract region from shape file - Added by kunal bali over 6 years ago

Thank You so much. It worked. 
    (1-2/2)