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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2203 - (show annotations)
Tue May 11 22:34:49 2004 UTC (20 years, 9 months ago) by jan
Original Path: trunk/thuban/Extensions/wms/wms.py
File MIME type: text/x-python
File size: 4515 byte(s)
Use FindOrInsertMenu() instead of finding menu on its own.

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