[ncl-talk] Writing shapefile to netcdf

Karin Meier-Fleischer meier-fleischer at dkrz.de
Tue Jul 16 06:40:13 MDT 2019


Hi Josh,

as already answered at cdo support, the adapted script is running well. 
Just to explain why yours is not working:
   - your data variable is SST not time
   - the data is not on a curvilinear grid so you have to change the 
var at lon2d/var at lat2d part to var at lon1d/var at lat1d

load "$HOME/NCL/shapefiles/shapefile_utils.ncl" shpname = 
"ospar_polygon_wdpa_simplified.shp" maskname = 
"ospar_polygon_wdpa_simplified.nc" print_shapefile_info(shpname) f = 
addfile("SST.nc","r") var = f->*SST(0,:,:)* var@*lat1d* = f->LAT 
var@*lon1d* = f->LON opt = True opt at return_mask = True ;-- this forces 
the return of a 0s and 1s mask array mask_array = 
shapefile_mask_data(var, shpname, opt) mask_array!0 = "y" mask_array!1 = 
"x" mask_array at coordinates = "LAT LON" system("rm -f " + maskname) fout 
= addfile(maskname,"c") fout->mask_array = mask_array fout->LAT = f->LAT 
fout->LON = f->LON

-Karin

Am 16.07.19 um 13:25 schrieb JoshAB1995--- via ncl-talk:
>
> Hi guys,
>
> I’m brand new to NCL as I need to quickly use it to convert a 
> shapefile to a netcdf file. The idea is to create a mask of marine 
> protected areas included in the shapefile. I’ve tried using the 
> following code but as I’ve highlighted in the code I run into some 
> issues...
>
> load "shapefile_utils.ncl"
>
> shpname = "ospar_polygon_wdpa_simplified.shp"
>
> maskname = "MPA_Mask.nc"
>
> print_shapefile_info(shpname)
>
> f = addfile("SST1.nc","r")
>
> var =  f->time(0)
>
> var at lat2d =  f->LAT
>
> var at lon2d =  f->LON
>
> opt =  True
>
> opt at return_mask =  True
>
> mask_array =  shapefile_mask_data(var, shpname, opt) **
>
> mask_array!0 = "y"
>
> mask_array!1 = "x"
>
> mask_array at coordinates = "LAT LON"
>
> system("rm -f " + maskname)
>
> fout = addfile(maskname,"c")
>
> fout->mask_array =  mask_array
>
> fout->LAT =  f->LAT
>
> fout->LON =  f->LON
>
> Unfortunately I get the following error message halfway through:
>
> mask_array =  shapefile_mask_data(var, shpname, opt) **
>
> (0) shapefile_mask_data: Error: not a valid rectilinear, curvilinear, 
> or uns
>
> tructured grid
>
> Does anyone have any ideas as to why this happens? I’ve attached the 
> relevant data to this email (hoping that it will send through).
>
> Many thanks,
>
> Josh
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190716/ca564a61/attachment.html>


More information about the ncl-talk mailing list