/[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 2361 - (show annotations)
Fri Oct 1 17:54:13 2004 UTC (20 years, 5 months ago) by joey
Original Path: trunk/thuban/Extensions/wms/wms.py
File MIME type: text/x-python
File size: 4904 byte(s)
Register the properties dialog class for the provided WMS layer

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