[ncl-talk] fatal:Failed to open OGR file(shp)

Rick Brownrigg brownrig at ucar.edu
Tue Nov 3 06:49:27 MST 2015


Hi Grace,

The error suggests that the two support files that accompany a shapefile
are missing -- in addition to the "*.shp" file, there needs to be a "*.shx"
and a "*.dbf" files in the same directory with the same name prefix. Do you
have those?  If so, and you are still getting an error, can you send me
your shapefiles that are failing?

As a general comment, the word "shapefile" is unfortunate and causes
confusion; to the user, it appears as though its just the one file, ie.,
the "*.shp" file . It is really a collection of up to 5-6 files, 3 of which
(shp/shx/dbf) are critical.

Hope that helps...
Rick

On Tue, Nov 3, 2015 at 12:08 AM, grace <313695096 at qq.com> wrote:

> Hi all:
>    I am trying to plot precipitation with wrfout data and try to add .shp
> on the plot.
> But error happened:
> ERROR 4: Unable to open /public/home/huanglei/map/shaanxi_diqu.shx or
> /public/home/huanglei/map/shaanxi_diqu.SHX.
> fatal:Failed to open OGR file:
> fatal:/public/home/huanglei/map/shaanxi_diqu.shp
> fatal:Could not open (/public/home/huanglei/map/shaanxi_diqu.shp)
> I have changed different shp file,but the errors are same.
> My NCL version is 6.2.0.
>  How can I slove the problem?
>       This is my script:
> ;   Example script to produce plots for a WRF real-data run,
> ;   with the ARW coordinate dynamics option.
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> begin
> ;
> ; The WRF ARW input file.
> ; This needs to have a ".nc" appended, so just do it.
>   a =
> addfile("/public/home/huanglei/wrfdata/5km/wrfout_d03_2015-08-02_12:00:
> 00.nc","r")
> ; We generate plots, but what kind do we prefer?
>  ; type = "x11"
>  type = "pdf"
> ; type = "ps"
> ; type = "ncgm"
>   wks = gsn_open_wks(type,"plt_Precip_5km0802")
>
> ; Set some basic resources
>   res = True
>   res at MainTitle = "REAL-TIME WRF"
>   mpres  = True  ; Map resources
>   mpres at mpOutlineOn = False  ; Turn off map outlines
>   mpres at mpFillOn    = False  ; Turn off map fill
>   mpres at mpGridAndLimbOn = True
>  ;res at mpProjection          = "Lambert"
>   pltres = True ; Plot resources
>   pltres at PanelPlot  = True   ; Tells wrf_map_overlays not to remove
> overlays
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ; What times and how many time steps are in the data set?
>   FirstTime = True
>   times = wrf_user_getvar(a,"times",-1)  ; get all times in the file
>   ntimes = dimsizes(times)         ; number of times in the file
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>   do it = 0,24,3            ; TIME LOOP
>     print("Working on time: " + times(it) )
>     res at TimeLabel = times(it)   ; Set Valid time to use on plots
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ; First get the variables we will need
>
>   ; Get non-convective, convective and total precipitation of
> 5km
>     rain_exp = wrf_user_getvar(a,"RAINNC",it)
>     rain_con = wrf_user_getvar(a,"RAINC",it)
>     rain_tot = rain_exp + rain_con
>     rain_tot at description = "Total Precipitation"
>
>  ;calculate the precipitation
>       if ( it .eq. 0 ) then
>         rain_exp_save = rain_exp
>         rain_con_save = rain_con
>         rain_tot_save = rain_tot
>       else
>         rain_exp_save = wrf_user_getvar(a,"RAINNC",it-1)
>         rain_con_save = wrf_user_getvar(a,"RAINC",it-1)
>         rain_tot_save = rain_exp_save + rain_con_save
>
>         times_sav = times(it-1)
>       end if
>     rain_tot_tend = rain_tot - rain_tot_save
>     rain_tot_tend at description = "Precipitation of 5km"
>   ; Bookkeeping, just to allow the tendency at the next time step
>     rain_exp_save = rain_exp
>     rain_con_save = rain_con
>     rain_tot_save = rain_tot
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>       ; Plotting options for Precipitation
>         opts_r = res
>         opts_r at UnitLabel            = "mm"
>         opts_r at cnLevelSelectionMode = "ExplicitLevels"
>         opts_r at cnLevels             = (/ .1, .2, .4, .8, 1.6, 3.2, 6.4, \
>                                         12.8, 25.6, 51.2, 102.4/)
>         opts_r at cnFillColors         =
> (/"White","White","DarkOliveGreen1", \
>                                         "DarkOliveGreen3","Chartreuse", \
>
> "Chartreuse3","Green","ForestGreen", \
>                                         "Yellow","Orange","Red","Violet"/)
>         opts_r at cnInfoLabelOn        = False
>         opts_r at cnConstFLabelOn      = False
>         opts_r at cnFillOn             = True
>
>         opts_r at gsnDraw      =  False
>         opts_r at gsnFrame     =  False
>
>       ; Precipitation Tendencies
>        if(it .gt. 0)then
>         opts_r at SubFieldTitle = "from " + times(it-3) + " to " + times(it)
>     end if
>         contour_tend = wrf_contour(a,wks, rain_tot_tend,opts_r) ; total
> (color)
>         delete(opts_r)
>
>       ; MAKE PLOTS
>          plot = wrf_map_overlays(a,wks,contour_tend,pltres,mpres)
>
>
> ;>============================================================<
> ;                      add China map
> ;>------------------------------------------------------------<
>
>   shp_name1    = "/public/home/huanglei/map/shaanxi_diqu.shp"
>   lnres                  = True
>   lnres at gsLineColor      = "gray25"
>   lnres at gsLineThicknessF = 0.5
>  id = gsn_add_shapefile_polylines(wks,plot,shp_name1,lnres)
>  ; shp_name2    = "/home/huanglei/map/China/cnmap/cnhimap.shp"
> ;  prres=True
>  ; prres at gsLineThicknessF = 2.0
> ;  prres at gsLineColor = "black"
>  ; plotcn3 = gsn_add_shapefile_polylines(wks,plot,shp_name2,prres)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>  draw(plot)       ; This will draw the map and the shapefile outlines.
>   frame(wks)
>   end do        ; END OF TIME LOOP
> end
>
> _______________________________________________
> 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/20151103/f4ff6529/attachment.html 


More information about the ncl-talk mailing list