/[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 2603 - (hide annotations)
Tue Apr 26 15:04:22 2005 UTC (19 years, 10 months ago) by joey
Original Path: trunk/thuban/Extensions/wms/wms.py
File MIME type: text/x-python
File size: 4794 byte(s)
Adjusted the render function to the modified render engine

1 bh 2086 # Copyright (C) 2003, 2004 by Intevation GmbH
2 jan 1944 # Authors:
3 jan 2405 # Jan-Oliver Wagner <[email protected]> (2003, 2004)
4     # Bernhard Herzog <[email protected]> (2004)
5     # Martin Schulze <[email protected]> (2004)
6 jan 1944 #
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 jan 2203 # $Source$
22     # $Id$
23 jan 1944
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 joey 2361 from Thuban.UI.mainwindow import main_menu, layer_properties_dialogs
34 jan 1944 from Thuban import _
35     import Thuban.UI.baserenderer
36    
37 joey 2176 from layer import WMSLayer
38 jan 1944
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 joey 2154 img, format = layer.GetMapImg(width, height, (xmin, ymin, xmax, ymax))
57 jan 1944
58 joey 2603 data = (width, height, (img, None, None))
59    
60     renderer.draw_raster_data(layer, 0,0, data, format)
61    
62 jan 1944 return ()
63    
64     Thuban.UI.baserenderer.add_renderer_extension(WMSLayer, render_wms_layer)
65 joey 2361 from properties import wmsProperties
66     layer_properties_dialogs.add(WMSLayer, wmsProperties)
67 jan 1944
68    
69     class SelectWMSServer(wxDialog):
70    
71     ID_COMBOVALUE = 4003
72    
73     def __init__(self, parent):
74     wxDialog.__init__(self, parent, -1, _("Select WMS Server"),
75     style = wxDEFAULT_DIALOG_STYLE
76     | wxSYSTEM_MENU
77     | wxRESIZE_BORDER)
78    
79     self.combo_value = wxComboBox(self, self.ID_COMBOVALUE, size=(500,-1))
80     self.combo_value.Append("")
81     self.combo_value.Append('http://frida.intevation.org/cgi-bin/frida_wms?')
82     #self.combo_value.Append('http://wms.jpl.nasa.gov/wms.cgi?')
83     #self.combo_value.Append('http://eukrante.hq:9089/cgi-bin/wms_shg?')
84     #self.combo_value.Append('http://131.220.106.112:8080/deegree0.7/wms?')
85     #self.combo_value.Append('http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?CONFIG=gita&')
86     self.combo_value.SetSelection(0)
87    
88     button_ok = wxButton(self, wxID_OK, _("OK"))
89     button_ok.SetDefault()
90     button_close = wxButton(self, wxID_CANCEL, _("Close"))
91    
92     vbox = wxBoxSizer(wxVERTICAL)
93     vbox.Add(self.combo_value, 1, wxEXPAND|wxALL|wxCB_SORT, 10)
94     hbox = wxBoxSizer(wxHORIZONTAL)
95     hbox.Add(button_ok, 0, wxALL, 10)
96     hbox.Add(button_close, 0, wxALL, 10)
97     vbox.Add(hbox, 0, 10)
98    
99     self.SetAutoLayout(True)
100     self.SetSizer(vbox)
101     vbox.Fit(self)
102     vbox.SetSizeHints(self)
103     self.Layout()
104    
105     EVT_BUTTON(self, wxID_OK, self.OnOK)
106     EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
107    
108     def OnOK(self, event):
109     self.url = self.combo_value.GetValue()
110     self.EndModal(wxID_OK)
111    
112     def OnCancel(self, event):
113     self.EndModal(wxID_CANCEL)
114    
115     def wms_dialog(context):
116     """Request URL from user and add WMS Layer.
117    
118     context -- The Thuban context.
119     """
120     dialog = SelectWMSServer(context.mainwindow)
121    
122     if dialog.ShowModal() == wxID_OK:
123     url = dialog.url
124 joey 2172 if len(url) == 0:
125     url = None
126 jan 1944 else:
127     url = None
128     dialog.Destroy()
129    
130     if url is None:
131     return
132    
133     wms_layer = WMSLayer('A WMS Layer', url)
134     if wms_layer.error_msg is not None:
135     context.mainwindow.RunMessageBox(_('WMS'), wms_layer.error_msg)
136    
137     map = context.mainwindow.canvas.Map()
138     if map.projection is None:
139     map.SetProjection(wms_layer.projection)
140     has_layers = map.HasLayers()
141     map.AddLayer(wms_layer)
142     if not has_layers:
143     # if we're adding a layer to an empty map, fit the
144     # new map to the window
145     context.mainwindow.canvas.FitMapToWindow()
146    
147     wxInitAllImageHandlers()
148     wms_extension = WMSExtension('WMS')
149    
150     # register the new command
151     registry.Add(Command('wms', _('Add WMS layer ...'), wms_dialog,
152     helptext = _('Add a WMS Layer')))
153    
154     # find the experimental menu (create it anew if not found)
155 jan 2203 experimental_menu = main_menu.FindOrInsertMenu('experimental',
156     _('Experimenta&l'))
157 jan 1944
158     # finally add the new entry to the experimental menu
159     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