/[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 2405 - (show annotations)
Sat Nov 20 21:26:35 2004 UTC (20 years, 3 months ago) by jan
Original Path: trunk/thuban/Extensions/wms/wms.py
File MIME type: text/x-python
File size: 4733 byte(s)
Removed registry entry (moved to __init__.py).

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