1
# Copyright (c) 2001, 2003 by Intevation GmbH
3
# Frank Koormann <frank.koormann@intevation.de>
5
# This program is free software under the GPL (>=v2)
6
# Read the file COPYING coming with Thuban for details.
9
Dialogs to the geographic projection library PROJ
12
__version__ = "$Revision: 1.9 $"
14
from wxPython.wx import *
18
ID_PROJECTION_EDIT = 4010
19
ID_PROJECTION_SELECT = 4011
20
ID_PROJECTION_OK = 4001
21
ID_PROJECTION_CANCEL = 4002
23
ID_UTM_DIALOG_OK = 4101
24
ID_UTM_DIALOG_CANCEL = 4102
25
ID_UTM_DIALOG_PROPOSE_ZONE = 4103
27
ID_UTM_PROPOSE_ZONE_DIALOG_TAKE = 4201
28
ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4202
30
projectionDict = {'None' : 'None', 'UTM' : 'utm'}
31
projectionMapping = {'None' : 'None', 'utm' : 'UTM'}
33
class Proj4Dialog(wxDialog):
35
"""Let the user select a projection and specify related parameters"""
37
def __init__(self, parent, projectionParamsList, map_bounding_box):
38
wxDialog.__init__(self, parent, -1, _("Projection"),
39
style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
41
self.map_bounding_box = map_bounding_box
43
self.projectionParams={}
44
combo = self.projection
45
if projectionParamsList is not None:
46
for element in projectionParamsList:
47
key, val = element.split('=')
48
self.projectionParams[key] = val
49
if self.projectionParams.has_key('proj'):
50
proj = projectionMapping[self.projectionParams['proj']]
51
combo.SetSelection(combo.FindString(proj))
53
combo.SetSelection(combo.FindString('None'))
54
self.UpdateProjectionInfo()
56
self.projection.SetValue('None')
57
self.UpdateProjectionInfo()
60
def dialogLayout(self):
61
topBox = wxBoxSizer(wxVERTICAL)
63
# Projection selection:
64
projectionBox = wxBoxSizer(wxHORIZONTAL)
65
projectionBox.Add(wxStaticText(self, -1, _("Projection")),
66
0, wxALIGN_CENTER|wxALL, 4)
68
self.projection = wxComboBox(self, ID_PROJECTION_SELECT, "",
69
style = wxCB_READONLY)
70
for projection in projectionDict.keys():
71
self.projection.Append(projection)
72
projectionBox.Add(self.projection, 0, wxALL, 4)
73
projectionBox.Add(wxButton(self, ID_PROJECTION_EDIT, _("Edit")),
75
EVT_COMBOBOX(self, ID_PROJECTION_SELECT, self.OnProj4Select)
76
EVT_BUTTON(self, ID_PROJECTION_EDIT, self.OnEdit)
78
topBox.Add(projectionBox, 0, 0)
80
# Info about current projection:
81
self.projectionInfo = wxTextCtrl(self, -1, "",
82
style = wxTE_MULTILINE|wxTE_READONLY,
84
topBox.Add(self.projectionInfo,1,wxEXPAND|wxALL, 4)
87
buttonBox = wxBoxSizer( wxHORIZONTAL )
88
buttonBox.Add(wxButton(self, ID_PROJECTION_OK, _("OK")),
90
buttonBox.Add(wxButton(self, ID_PROJECTION_CANCEL, _("Cancel")),
92
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
94
EVT_BUTTON(self, ID_PROJECTION_OK, self.OnProj4OK)
95
EVT_BUTTON(self, ID_PROJECTION_CANCEL, self.OnProj4Cancel)
97
self.SetAutoLayout(True)
100
topBox.SetSizeHints(self)
102
def OnProj4Select(self, event):
103
projection = self.projection.GetStringSelection()
104
if projection == 'None':
105
self.projectionParams = {}
106
self.UpdateProjectionInfo()
108
def OnEdit(self, event):
109
projection = self.projection.GetStringSelection()
110
if projection is not 'None':
111
dialogname = getattr(self, 'launch' + projection + 'Dialog', None)
112
if dialogname is not None:
114
self.UpdateProjectionInfo()
118
self.projectionParams = {}
120
def UpdateProjectionInfo(self):
121
self.projectionInfo.Clear()
122
for key in self.projectionParams.keys():
123
self.projectionInfo.AppendText(key+": "
124
+str(self.projectionParams[key])+"\n")
127
def OnProj4OK(self, event):
128
self.EndModal(wxID_OK)
130
def OnProj4Cancel(self, event):
131
self.EndModal(wxID_CANCEL)
133
def launchUTMDialog(self, parent):
134
dlg = UTMDialog(parent, parent.projectionInfo )
141
if len(self.projectionParams.keys()) > 0:
143
for key in self.projectionParams.keys():
144
projection.append(key+"="+str(self.projectionParams[key]))
152
class UTMDialog(wxDialog):
154
"""Let the user specify parameters for UTM projection (Zone, Spheroid)"""
156
def __init__(self, parent, projection):
157
wxDialog.__init__(self, parent, -1, _("Projection: UTM Parameters"),
158
wxDefaultPosition, wxSize(200, 100))
161
if self.parent.projectionParams.has_key('zone'):
162
text = str(self.parent.projectionParams['zone'])
163
self.zone.SetSelection(self.zone.FindString(text))
164
if self.parent.projectionParams.has_key('ellps'):
165
text = str(self.parent.projectionParams['ellps'])
166
self.ellps.SetSelection(self.ellps.FindString(text))
168
def dialogLayout(self):
169
topBox = wxBoxSizer(wxVERTICAL)
171
zoneBox = wxBoxSizer(wxHORIZONTAL)
172
zoneBox.Add(wxStaticText(self, -1, _("UTM Zone")),
173
0, wxALIGN_CENTER|wxALL, 4)
174
self.zone = wxComboBox(self, -1, "", style = wxCB_READONLY)
175
for zone in range(1,61):
176
self.zone.Append(str(zone))
177
zoneBox.Add(self.zone, 0, wxALIGN_CENTER|wxALL, 4)
178
zoneBox.Add(wxButton(self, ID_UTM_DIALOG_PROPOSE_ZONE, _("Propose")),
180
EVT_BUTTON(self, ID_UTM_DIALOG_PROPOSE_ZONE, self.OnProposeZone)
182
topBox.Add(zoneBox, 1, wxEXPAND|wxALL, 4)
184
ellipsoidBox = wxBoxSizer(wxHORIZONTAL)
185
ellipsoidBox.Add(wxStaticText(self, -1, _("Ellipsoid")),
186
0, wxALIGN_CENTER|wxALL, 4)
187
self.ellps = wxComboBox(self, -1, "", style = wxCB_READONLY)
188
for ellps in ["clrk66", "GRS80"]:
189
self.ellps.Append(ellps)
190
ellipsoidBox.Add(self.ellps, 0, wxALIGN_CENTER|wxALL, 4)
192
topBox.Add(ellipsoidBox, 1, wxEXPAND|wxALL, 4)
194
buttonBox = wxBoxSizer(wxHORIZONTAL)
195
buttonBox.Add(wxButton(self, ID_UTM_DIALOG_OK, _("OK")),
197
buttonBox.Add(wxButton(self, ID_UTM_DIALOG_CANCEL, _("Cancel")),
199
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
200
EVT_BUTTON(self, ID_UTM_DIALOG_OK, self.OnOK)
201
EVT_BUTTON(self, ID_UTM_DIALOG_CANCEL, self.OnCancel)
203
self.SetAutoLayout(True)
204
self.SetSizer(topBox)
206
topBox.SetSizeHints(self)
208
def OnProposeZone(self, event):
209
dlg = UTMProposeZoneDialog(self)
215
def OnOK(self, event):
216
self.parent.projectionParams = {}
217
self.parent.projectionParams['zone'] = self.zone.GetStringSelection()
218
self.parent.projectionParams['ellps'] = self.ellps.GetStringSelection()
219
self.parent.projectionParams['proj'] = "utm"
222
def OnCancel(self, event):
225
class UTMProposeZoneDialog(wxDialog):
227
"""Propose a sensible Zone considering the current map extent."""
229
def __init__(self, parent):
230
wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),
231
wxDefaultPosition, wxSize(200, 100))
233
x, y, x2, y2 = self.parent.parent.map_bounding_box
236
center = (x2 - x) / 2 + x
237
self.proposedZone = str(int(center / 6 + 1))
240
def dialogLayout(self):
241
topBox = wxBoxSizer(wxVERTICAL)
243
textBox = wxBoxSizer(wxVERTICAL)
244
textBox.Add(wxStaticText(self, -1, _("The current map extent center "
245
"lies in UTM Zone")),
246
0, wxALIGN_CENTER|wxALL, 4)
247
textBox.Add(wxStaticText(self, -1, self.proposedZone),
248
0, wxALIGN_CENTER|wxALL, 4)
250
topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)
252
buttonBox = wxBoxSizer(wxHORIZONTAL)
253
buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,
254
_("Take")), 0, wxALL, 4)
255
buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL,
256
_("Cancel")), 0, wxALL, 4)
257
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
258
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)
259
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)
261
self.SetAutoLayout(True)
262
self.SetSizer(topBox)
264
topBox.SetSizeHints(self)
266
def OnTake(self, event):
267
self.parent.zone.SetSelection(self.parent.zone.FindString(self.proposedZone))
270
def OnCancel(self, event):