/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/wms/wms.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Extensions/wms/wms.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2176 - (hide annotations)
Thu Apr 15 07:14:25 2004 UTC (20 years, 10 months ago) by joey
Original Path: trunk/thuban/Extensions/wms/wms.py
File MIME type: text/x-python
File size: 4562 byte(s)
Moved the WMS layer into layer.py in order to establish a clean
structure.

1 bh 2086 # Copyright (C) 2003, 2004 by Intevation GmbH
2 jan 1944 # Authors:
3     # Jan-Oliver Wagner <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9     Provide layers via OGC WMS.
10    
11     This extension is in a very experimental stage!
12     It just demonstrates how to add a special
13     layer into Thuban via an extension.
14     Some things are not wired, so be prepared for Exceptions
15     everywhere.
16     """
17    
18     __version__ = "$Revision$"
19    
20     import os, sys
21     import xml.dom.minidom
22     import tempfile
23    
24     from wxPython.wx import *
25    
26     from Thuban.Model.proj import Projection
27     from Thuban.Model.extension import Extension
28     from Thuban.UI.command import registry, Command
29     import Thuban.UI.mainwindow
30     from Thuban import _
31     import Thuban.UI.baserenderer
32    
33 joey 2176 from layer import WMSLayer
34 jan 1944
35    
36     class WMSExtension(Extension):
37     def TreeInfo(self):
38     return (_("Extension: %s") % self.title,
39     [ object.TreeInfo() for object in self.objects ])
40    
41    
42     def render_wms_layer(renderer, layer):
43     offx, offy = renderer.offset
44     width, height = renderer.dc.GetSizeTuple()
45    
46     scale = renderer.scale
47     xmin = (0 - offx) / scale
48     ymin = (offy - height) / scale
49     xmax = (width - offx) / scale
50     ymax = (offy - 0) / scale
51    
52 joey 2154 img, format = layer.GetMapImg(width, height, (xmin, ymin, xmax, ymax))
53     renderer.draw_raster_data(img, format)
54 jan 1944
55     return ()
56    
57     Thuban.UI.baserenderer.add_renderer_extension(WMSLayer, render_wms_layer)
58    
59    
60     class SelectWMSServer(wxDialog):
61    
62     ID_COMBOVALUE = 4003
63    
64     def __init__(self, parent):
65     wxDialog.__init__(self, parent, -1, _("Select WMS Server"),
66     style = wxDEFAULT_DIALOG_STYLE
67     | wxSYSTEM_MENU
68     | wxRESIZE_BORDER)
69    
70     self.combo_value = wxComboBox(self, self.ID_COMBOVALUE, size=(500,-1))
71     self.combo_value.Append("")
72     self.combo_value.Append('http://frida.intevation.org/cgi-bin/frida_wms?')
73     #self.combo_value.Append('http://wms.jpl.nasa.gov/wms.cgi?')
74     #self.combo_value.Append('http://eukrante.hq:9089/cgi-bin/wms_shg?')
75     #self.combo_value.Append('http://131.220.106.112:8080/deegree0.7/wms?')
76     #self.combo_value.Append('http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?CONFIG=gita&')
77     self.combo_value.SetSelection(0)
78    
79     button_ok = wxButton(self, wxID_OK, _("OK"))
80     button_ok.SetDefault()
81     button_close = wxButton(self, wxID_CANCEL, _("Close"))
82    
83     vbox = wxBoxSizer(wxVERTICAL)
84     vbox.Add(self.combo_value, 1, wxEXPAND|wxALL|wxCB_SORT, 10)
85     hbox = wxBoxSizer(wxHORIZONTAL)
86     hbox.Add(button_ok, 0, wxALL, 10)
87     hbox.Add(button_close, 0, wxALL, 10)
88     vbox.Add(hbox, 0, 10)
89    
90     self.SetAutoLayout(True)
91     self.SetSizer(vbox)
92     vbox.Fit(self)
93     vbox.SetSizeHints(self)
94     self.Layout()
95    
96     EVT_BUTTON(self, wxID_OK, self.OnOK)
97     EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
98    
99     def OnOK(self, event):
100     self.url = self.combo_value.GetValue()
101     self.EndModal(wxID_OK)
102    
103     def OnCancel(self, event):
104     self.EndModal(wxID_CANCEL)
105    
106     def wms_dialog(context):
107     """Request URL from user and add WMS Layer.
108    
109     context -- The Thuban context.
110     """
111     dialog = SelectWMSServer(context.mainwindow)
112    
113     if dialog.ShowModal() == wxID_OK:
114     url = dialog.url
115 joey 2172 if len(url) == 0:
116     url = None
117 jan 1944 else:
118     url = None
119     dialog.Destroy()
120    
121     if url is None:
122     return
123    
124     wms_layer = WMSLayer('A WMS Layer', url)
125     if wms_layer.error_msg is not None:
126     context.mainwindow.RunMessageBox(_('WMS'), wms_layer.error_msg)
127    
128     map = context.mainwindow.canvas.Map()
129     if map.projection is None:
130     map.SetProjection(wms_layer.projection)
131     has_layers = map.HasLayers()
132     map.AddLayer(wms_layer)
133     if not has_layers:
134     # if we're adding a layer to an empty map, fit the
135     # new map to the window
136     context.mainwindow.canvas.FitMapToWindow()
137    
138     wxInitAllImageHandlers()
139     wms_extension = WMSExtension('WMS')
140    
141     # register the new command
142     registry.Add(Command('wms', _('Add WMS layer ...'), wms_dialog,
143     helptext = _('Add a WMS Layer')))
144    
145     # find the experimental menu (create it anew if not found)
146     main_menu = Thuban.UI.mainwindow.main_menu
147     experimental_menu = main_menu.find_menu('experimental')
148     if experimental_menu is None:
149     experimental_menu = main_menu.InsertMenu('experimental', _('Experimenta&l'))
150    
151     # finally add the new entry to the experimental menu
152     experimental_menu.InsertItem('wms')

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26