Exemple #1
0
 def gui_addgeos(self,website='http://wms.gsfc.nasa.gov/cgi-bin/wms.cgi?project=GEOS.fp.fcst.inst1_2d_hwl_Nx'):
     'GUI handler for adding the figures from WMS support of GEOS'
     from gui import Popup_list
     try:
         from owslib.wms import WebMapService
         from owslib.util import openURL
         from StringIO import StringIO
         from PIL import Image
         self.line.tb.set_message('Loading WMS from :'+website.split('/')[2])
         wms = WebMapService(website)
         cont = list(wms.contents)
     except Exception as ie:
         print ie
         import tkMessageBox
         tkMessageBox.showwarning('Sorry','Loading WMS map file from '+website.split('/')[2]+' servers not working...')
         return
     titles = [wms[c].title for c in cont]
     arr = [x.split('-')[-1]+':  '+y for x,y in zip(cont,titles)]
     i = Popup_list(arr)
     self.line.tb.set_message('Selected WMS map: '+titles[i].split(',')[-1])
     if wms[cont[i]].timepositions:
         times = wms[cont[i]].timepositions
         j = Popup_list(times)
         time_sel = times[j]
     else:
         time_sel = None
     try:
         if not time_sel:
             time_sel = self.line.ex.datestr+'T12:00'
         ylim = self.line.line.axes.get_ylim()
         xlim = self.line.line.axes.get_xlim()
         #img = wms.getdata(layers=[cont[i]],
         #                  bbox=(ylim[0],xlim[0],ylim[1],xlim[1]),
         #                  size=(480,240),
         #                  transparent=True,
         #                  time=time_sel,
         #                  srs='EPSG:4326',
         #                  format='image/png')
         #leg_call = openURL(img.geturl().replace('GetMap','GetLegend'))
         img = wms.getdata(layers=[cont[i],'countries'],
                           bbox=(ylim[0],xlim[0],ylim[1],xlim[1]),
                           size=(480,240),
                           transparent=True,
                           time=time_sel,
                           srs='EPSG:4326',
                           format='image/png')
         geos = Image.open(StringIO(img.read()))
         self.line.addfigure_under(geos,xlim[0],ylim[0],xlim[1],ylim[1])
         #self.line.line.figure.add
         #leg = Image.open(StringIO(leg_call.read()))
         #self.line.addfigure_under(leg,xlim[0],ylim[0],xlim[1],ylim[1],outside=True)
     except:
         import tkMessageBox
         tkMessageBox.showwarning('Sorry','Problem getting the image to load')
         return