2 @package location_wizard.py
4 @brief Location wizard - creates a new GRASS Location. User can choose
11 - CoordinateSystemPage
17 - GeoreferencedFilePage
23 - SelectTransformDialog
25 (C) 2007-2011 by the GRASS Development Team
27 This program is free software under the GNU General Public License
28 (>=v2). Read the file COPYING that comes with GRASS for details.
30 @author Michael Barton
31 @author Jachym Cepicky
32 @author Martin Landa <landa.martin gmail.com>
42 import wx.lib.mixins.listctrl
as listmix
43 import wx.wizard
as wiz
44 import wx.lib.scrolledpanel
as scrolled
54 CompatPath = os.path.join(globalvar.ETCWXDIR)
55 sys.path.append(CompatPath)
56 from compat
import subprocess
68 """!Base class providing basic methods"""
72 def MakeLabel(self, text = "", style = wx.ALIGN_LEFT, parent = None):
73 """!Make aligned label"""
76 return wx.StaticText(parent = parent, id = wx.ID_ANY, label = text,
79 def MakeTextCtrl(self, text = '', size = (100,-1), style = 0, parent =
None):
80 """!Generic text control"""
83 return wx.TextCtrl(parent = parent, id = wx.ID_ANY, value = text,
84 size = size, style = style)
86 def MakeButton(self, text, id = wx.ID_ANY, size = (-1,-1), parent =
None):
90 return wx.Button(parent = parent, id = id, label = text,
94 """!Class to make wizard pages. Generic methods to make labels,
95 text entries, and buttons.
99 self.
page = wiz.WizardPageSimple.__init__(self, parent)
102 self.
title = wx.StaticText(parent = self, id = wx.ID_ANY, label = title)
103 self.title.SetFont(wx.Font(13, wx.SWISS, wx.NORMAL, wx.BOLD))
107 self.
sizer = wx.GridBagSizer(vgap = 0, hgap = 0)
110 """!Do page layout"""
111 self.pagesizer.Add(item = self.
title, proportion = 0,
112 flag = wx.ALIGN_CENTRE | wx.ALL,
114 self.pagesizer.Add(item = wx.StaticLine(self, -1), proportion = 0,
115 flag = wx.EXPAND | wx.ALL,
117 self.pagesizer.Add(item = self.
sizer, proportion = 1,
120 self.SetAutoLayout(
True)
125 """!Wizard page for setting GIS data directory and location name"""
127 TitledPage.__init__(self, wizard, _(
"Define GRASS Database and Location Name"))
142 self.sizer.AddGrowableCol(3)
143 self.sizer.Add(item = self.
MakeLabel(_(
"GIS Data Directory:")),
144 flag = wx.ALIGN_RIGHT |
145 wx.ALIGN_CENTER_VERTICAL |
149 flag = wx.ALIGN_LEFT |
150 wx.ALIGN_CENTER_VERTICAL |
153 self.sizer.Add(item = self.
bbrowse,
154 flag = wx.ALIGN_LEFT |
155 wx.ALIGN_CENTER_VERTICAL |
159 self.sizer.Add(item = self.
MakeLabel(
"%s:" % _(
"Project Location")),
160 flag = wx.ALIGN_RIGHT |
161 wx.ALIGN_CENTER_VERTICAL |
165 flag = wx.ALIGN_LEFT |
166 wx.ALIGN_CENTER_VERTICAL |
170 self.sizer.Add(item = self.
MakeLabel(
"%s:" % _(
"Location Title")),
171 flag = wx.ALIGN_RIGHT |
172 wx.ALIGN_TOP | wx.ALIGN_CENTER_VERTICAL |
176 flag = wx.ALIGN_LEFT |
177 wx.ALIGN_CENTER_VERTICAL |
179 pos = (3, 2), span = (1, 2))
188 """!Name for new location was changed"""
189 nextButton = wx.FindWindowById(wx.ID_FORWARD)
190 if len(event.GetString()) > 0:
191 if not nextButton.IsEnabled():
199 """!Choose GRASS data directory"""
200 dlg = wx.DirDialog(self, _(
"Choose GRASS data directory:"),
201 os.getcwd(), wx.DD_DEFAULT_STYLE)
202 if dlg.ShowModal() == wx.ID_OK:
210 if os.path.isdir(os.path.join(self.tgisdbase.GetValue(), self.tlocation.GetValue())):
211 error = _(
"Location already exists in GRASS Database.")
215 message=
"%s <%s>.%s%s" % (_(
"Unable to create location"),
216 str(self.tlocation.GetValue()),
222 self.
location = self.tlocation.GetValue()
224 self.
locTitle = self.tlocTitle.GetValue()
228 message = _(
"Title of the location is limited only to one line and "
229 "256 characters. The rest of the text will be ignored."))
230 self.
locTitle = self.locTitle.split(os.linesep)[0][:255]
233 """!Wizard page for choosing method for location creation"""
235 TitledPage.__init__(self, wizard, _(
"Choose method for creating a new location"))
241 self.
radio1 = wx.RadioButton(parent = self, id = wx.ID_ANY,
242 label = _(
"Select coordinate system parameters from a list"),
244 self.
radio2 = wx.RadioButton(parent = self, id = wx.ID_ANY,
245 label = _(
"Select EPSG code of spatial reference system"))
246 self.
radio3 = wx.RadioButton(parent = self, id = wx.ID_ANY,
247 label = _(
"Read projection and datum terms from a "
248 "georeferenced data file"))
249 self.
radio4 = wx.RadioButton(parent = self, id = wx.ID_ANY,
250 label = _(
"Read projection and datum terms from a "
252 self.
radio5 = wx.RadioButton(parent = self, id = wx.ID_ANY,
253 label = _(
"Specify projection and datum terms using custom "
254 "PROJ.4 parameters"))
255 self.
radio6 = wx.RadioButton(parent = self, id = wx.ID_ANY,
256 label = _(
"Create an arbitrary non-earth coordinate system (XY)"))
259 self.sizer.AddGrowableCol(1)
260 self.sizer.SetVGap(10)
261 self.sizer.Add(item = self.
radio1,
262 flag = wx.ALIGN_LEFT, pos = (1, 1))
263 self.sizer.Add(item = self.
radio2,
264 flag = wx.ALIGN_LEFT, pos = (2, 1))
265 self.sizer.Add(item = self.
radio3,
266 flag = wx.ALIGN_LEFT, pos = (3, 1))
267 self.sizer.Add(item = self.
radio4,
268 flag = wx.ALIGN_LEFT, pos = (4, 1))
269 self.sizer.Add(item = self.
radio5,
270 flag = wx.ALIGN_LEFT, pos = (5, 1))
271 self.sizer.Add(item = self.
radio6,
272 flag = wx.ALIGN_LEFT, pos = (6, 1))
275 self.Bind(wx.EVT_RADIOBUTTON, self.
SetVal, id = self.radio1.GetId())
276 self.Bind(wx.EVT_RADIOBUTTON, self.
SetVal, id = self.radio2.GetId())
277 self.Bind(wx.EVT_RADIOBUTTON, self.
SetVal, id = self.radio3.GetId())
278 self.Bind(wx.EVT_RADIOBUTTON, self.
SetVal, id = self.radio4.GetId())
279 self.Bind(wx.EVT_RADIOBUTTON, self.
SetVal, id = self.radio5.GetId())
280 self.Bind(wx.EVT_RADIOBUTTON, self.
SetVal, id = self.radio6.GetId())
281 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
288 self.radio1.SetValue(
True)
290 if coordsys ==
'proj':
291 self.radio1.SetValue(
True)
292 if coordsys ==
"epsg":
293 self.radio2.SetValue(
True)
294 if coordsys ==
"file":
295 self.radio3.SetValue(
True)
296 if coordsys ==
"wkt":
297 self.radio4.SetValue(
True)
298 if coordsys ==
"custom":
299 self.radio5.SetValue(
True)
301 self.radio6.SetValue(
True)
303 if event.GetDirection():
304 if coordsys ==
'proj':
305 self.SetNext(self.parent.projpage)
306 self.parent.sumpage.SetPrev(self.parent.datumpage)
307 if coordsys ==
"epsg":
308 self.SetNext(self.parent.epsgpage)
309 self.parent.sumpage.SetPrev(self.parent.epsgpage)
310 if coordsys ==
"file":
311 self.SetNext(self.parent.filepage)
312 self.parent.sumpage.SetPrev(self.parent.filepage)
313 if coordsys ==
"wkt":
314 self.SetNext(self.parent.wktpage)
315 self.parent.sumpage.SetPrev(self.parent.wktpage)
316 if coordsys ==
"custom":
317 self.SetNext(self.parent.custompage)
318 self.parent.sumpage.SetPrev(self.parent.custompage)
320 self.SetNext(self.parent.sumpage)
321 self.parent.sumpage.SetPrev(self.parent.csystemspage)
323 if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
324 wx.FindWindowById(wx.ID_FORWARD).Enable()
329 if event.GetId() == self.radio1.GetId():
331 self.SetNext(self.parent.projpage)
332 self.parent.sumpage.SetPrev(self.parent.datumpage)
333 elif event.GetId() == self.radio2.GetId():
335 self.SetNext(self.parent.epsgpage)
336 self.parent.sumpage.SetPrev(self.parent.epsgpage)
337 elif event.GetId() == self.radio3.GetId():
339 self.SetNext(self.parent.filepage)
340 self.parent.sumpage.SetPrev(self.parent.filepage)
341 elif event.GetId() == self.radio4.GetId():
343 self.SetNext(self.parent.wktpage)
344 self.parent.sumpage.SetPrev(self.parent.wktpage)
345 elif event.GetId() == self.radio5.GetId():
347 self.SetNext(self.parent.custompage)
348 self.parent.sumpage.SetPrev(self.parent.custompage)
349 elif event.GetId() == self.radio6.GetId():
351 self.SetNext(self.parent.sumpage)
352 self.parent.sumpage.SetPrev(self.parent.csystemspage)
355 """!Wizard page for selecting projection (select coordinate system option)"""
357 TitledPage.__init__(self, wizard, _(
"Choose projection"))
368 self.
searchb = wx.SearchCtrl(self, size = (200,-1),
369 style = wx.TE_PROCESS_ENTER)
373 columns = [_(
'Code'), _(
'Description')])
374 self.projlist.resizeLastColumn(30)
377 self.sizer.AddGrowableCol(3)
378 self.sizer.Add(item = self.
MakeLabel(_(
"Projection code:")),
379 flag = wx.ALIGN_LEFT |
380 wx.ALIGN_CENTER_VERTICAL |
381 wx.ALL, border = 5, pos = (1, 1))
382 self.sizer.Add(item = self.
tproj,
383 flag = wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL,
384 border = 5, pos = (1, 2))
386 self.sizer.Add(item = self.
MakeLabel(_(
"Search in description:")),
387 flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
388 border = 5, pos = (2, 1))
389 self.sizer.Add(item = self.
searchb,
390 flag = wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL,
391 border = 5, pos = (2, 2))
393 self.sizer.AddGrowableRow(3)
394 self.sizer.Add(item = self.
projlist,
397 wx.ALL, border = 5, pos = (3, 1), span = (1, 3))
400 self.tproj.Bind(wx.EVT_TEXT, self.
OnText)
401 self.tproj.Bind(wx.EVT_TEXT_ENTER, self.
OnText)
402 self.searchb.Bind(wx.EVT_TEXT_ENTER, self.
OnSearch)
403 self.projlist.Bind(wx.EVT_LIST_ITEM_SELECTED, self.
OnItemSelected)
405 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
408 if event.GetDirection()
and self.
proj not in self.parent.projections.keys():
412 """!Projection name changed"""
413 self.
proj = event.GetString().lower()
415 nextButton = wx.FindWindowById(wx.ID_FORWARD)
416 if self.
proj not in self.parent.projections.keys()
and nextButton.IsEnabled():
417 nextButton.Enable(
False)
419 if self.
proj in self.parent.projections.keys():
420 if self.
proj ==
'stp':
421 wx.MessageBox(
'Currently State Plane projections must be selected using the '
422 'text-based setup (g.setproj), or entered by EPSG code or '
423 'custom PROJ.4 terms.',
424 'Warning', wx.ICON_WARNING)
426 self.tproj.SetValue(self.
proj)
427 nextButton.Enable(
False)
429 elif self.proj.lower() ==
'll':
430 self.
p4proj =
'+proj=longlat'
432 self.
p4proj =
'+proj=' + self.proj.lower()
437 if len(self.
proj) == 0:
439 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
441 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
446 """!Search projection by desc"""
447 str = event.GetString()
449 self.
proj, self.
projdesc = self.projlist.Search(index = [0,1], pattern = event.GetString())
456 """!Projection selected"""
457 index = event.m_itemIndex
460 self.
proj = self.projlist.GetItem(index, 0).GetText().lower()
461 self.tproj.SetValue(self.
proj)
466 listmix.ListCtrlAutoWidthMixin,
467 listmix.ColumnSorterMixin):
468 """!Generic list (for projections, ellipsoids, etc.)"""
471 wx.ListCtrl.__init__(self, parent = parent, id = wx.ID_ANY,
472 style = wx.LC_REPORT |
477 wx.LC_SORT_ASCENDING, size = (550, 125))
486 for column
in columns:
487 self.InsertColumn(i, column)
493 for i
in range(self.GetColumnCount()):
494 self.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER)
495 if self.GetColumnWidth(i) < 80:
496 self.SetColumnWidth(i, 80)
501 listmix.ListCtrlAutoWidthMixin.__init__(self)
502 listmix.ColumnSorterMixin.__init__(self, self.GetColumnCount())
508 self.attr1.SetBackgroundColour(wx.Colour(238,238,238))
510 self.attr2.SetBackgroundColour(
"white")
511 self.
il = wx.ImageList(16, 16)
512 self.
sm_up = self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_GO_UP, wx.ART_TOOLBAR,
514 self.
sm_dn = self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_GO_DOWN, wx.ART_TOOLBAR,
516 self.SetImageList(self.
il, wx.IMAGE_LIST_SMALL)
522 self.SortListItems(col = 0, ascending =
True)
541 self.DeleteAllItems()
545 for i
in range(1, len(value)):
547 self.itemIndexMap.append(row)
550 self.SetItemCount(row)
553 self.SetColumnWidth(0, 80)
554 self.SetColumnWidth(1, 300)
558 except StandardError, e:
559 wx.MessageBox(parent = self,
560 message = _(
"Unable to read list: %s") % e,
561 caption = _(
"Error"), style = wx.OK | wx.ICON_ERROR)
564 """!Sort by column"""
565 self.
_col = event.GetColumn()
570 info.m_mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE
572 for column
in range(self.GetColumnCount()):
573 info.m_text = self.GetColumn(column).GetText()
574 self.SetColumn(column, info)
579 """!Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py"""
589 """!Get item attributes"""
591 if ( index % 2) == 0:
598 items = list(self.itemDataMap.keys())
606 colName = self.GetColumn(self.
_col).GetText()
607 ascending = self._colSortFlag[self.
_col]
613 cmpVal = locale.strcoll(str(item1), str(item2))
615 cmpVal = cmp(item1, item2)
620 cmpVal = apply(cmp, self.GetSecondarySortValues(self.
_col, key1, key2))
628 """!Used by listmix.ColumnSorterMixin"""
632 """!Search projection by description
633 Return first found item or None
640 pattern = pattern.lower()
648 except UnicodeDecodeError:
659 """!Wizard page for selecting method of setting coordinate system
660 parameters (select coordinate system option)
663 TitledPage.__init__(self, wizard, _(
"Choose projection parameters"))
675 self.sizer.AddGrowableCol(1)
676 self.sizer.AddGrowableRow(1)
678 radioSBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
679 label =
" %s " % _(
"Select datum or ellipsoid (next page)"))
680 radioSBSizer = wx.StaticBoxSizer(radioSBox)
681 self.sizer.Add(item = radioSBSizer, pos = (0, 1),
682 flag = wx.EXPAND | wx.ALIGN_TOP | wx.TOP, border = 10)
684 self.
radio1 = wx.RadioButton(parent = self, id = wx.ID_ANY,
685 label = _(
"Datum with associated ellipsoid"),
687 self.
radio2 = wx.RadioButton(parent = self, id = wx.ID_ANY,
688 label = _(
"Ellipsoid only"))
691 if self.radio1.GetValue() ==
False and self.radio2.GetValue() ==
False:
692 self.radio1.SetValue(
True)
693 self.SetNext(self.parent.datumpage)
696 radioSBSizer.Add(item = self.
radio1,
697 flag = wx.ALIGN_LEFT | wx.RIGHT, border = 20)
698 radioSBSizer.Add(item = self.
radio2,
699 flag = wx.ALIGN_LEFT)
702 self.Bind(wx.EVT_RADIOBUTTON, self.
SetVal, id = self.radio1.GetId())
703 self.Bind(wx.EVT_RADIOBUTTON, self.
SetVal, id = self.radio2.GetId())
704 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.
OnPageChange)
705 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
708 """!Parameter value changed"""
710 val = event.GetString()
717 win = self.FindWindowById(id)
718 if param[
'type'] ==
'zone':
725 if param[
'type'] ==
'bool':
726 param[
'value'] = event.GetSelection()
733 """!Go to next page"""
734 if event.GetDirection():
736 for id, param
in self.pparam.iteritems():
737 if param[
'type'] ==
'bool':
738 if param[
'value'] ==
False:
743 if param[
'value']
is None:
744 wx.MessageBox(parent = self,
745 message = _(
'You must enter a value for %s') % param[
'desc'],
746 caption = _(
'Error'), style = wx.ICON_ERROR | wx.CENTRE)
749 self.
p4projparams += (
' +' + param[
'proj4'] +
'=' + str(param[
'value']))
753 self.
projdesc = self.parent.projections[self.parent.projpage.proj][0]
756 self.
paramSBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
757 label = _(
" Enter parameters for %s projection ") % self.
projdesc)
758 paramSBSizer = wx.StaticBoxSizer(self.
paramSBox)
760 self.
panel = scrolled.ScrolledPanel(parent = self, id = wx.ID_ANY)
761 self.panel.SetupScrolling()
765 self.sizer.Add(item = paramSBSizer, pos = (1, 1),
767 paramSBSizer.Add(item = self.
panel, proportion = 1,
768 flag = wx.ALIGN_CENTER | wx.EXPAND)
770 paramSBSizer.Fit(self.
panel)
773 if event.GetDirection():
774 self.prjParamSizer.Clear(
True)
775 self.paramSBox.SetLabel(_(
" Enter parameters for %s projection ") % self.
projdesc)
778 for paramgrp
in self.parent.projections[self.parent.projpage.proj][1]:
781 param = self.
pparam[id] = {
'type' : self.parent.paramdesc[paramgrp[0]][0],
782 'proj4': self.parent.paramdesc[paramgrp[0]][1],
783 'desc' : self.parent.paramdesc[paramgrp[0]][2] }
786 if param[
'type'] ==
'bool':
788 elif param[
'type'] ==
'zone':
790 param[
'desc'] +=
' (1-60)'
792 param[
'value'] = paramgrp[2]
794 label = wx.StaticText(parent = self.
panel, id = wx.ID_ANY, label = param[
'desc'],
795 style = wx.ALIGN_RIGHT | wx.ST_NO_AUTORESIZE)
796 if param[
'type'] ==
'bool':
797 win = wx.Choice(parent = self.
panel, id = id, size = (100,-1),
798 choices = [_(
'No'), _(
'Yes')])
799 win.SetSelection(param[
'value'])
801 elif param[
'type'] ==
'zone':
802 win = wx.SpinCtrl(parent = self.
panel, id = id,
804 style = wx.SP_ARROW_KEYS | wx.SP_WRAP,
806 win.SetValue(param[
'value'])
810 win = wx.TextCtrl(parent = self.
panel, id = id,
811 value = param[
'value'],
814 if paramgrp[1] ==
'noask':
817 self.prjParamSizer.Add(item = label, pos = (row, 1),
818 flag = wx.ALIGN_RIGHT |
819 wx.ALIGN_CENTER_VERTICAL |
820 wx.RIGHT, border = 5)
821 self.prjParamSizer.Add(item = win, pos = (row, 2),
822 flag = wx.ALIGN_LEFT |
823 wx.ALIGN_CENTER_VERTICAL |
827 self.panel.SetSize(self.panel.GetBestSize())
832 if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
833 wx.FindWindowById(wx.ID_FORWARD).Enable()
839 if event.GetId() == self.radio1.GetId():
840 self.SetNext(self.parent.datumpage)
841 self.parent.sumpage.SetPrev(self.parent.datumpage)
842 elif event.GetId() == self.radio2.GetId():
843 self.SetNext(self.parent.ellipsepage)
844 self.parent.sumpage.SetPrev(self.parent.ellipsepage)
847 """!Wizard page for selecting datum (with associated ellipsoid)
848 and datum transformation parameters (select coordinate system option)
852 TitledPage.__init__(self, wizard, _(
"Specify geodetic datum"))
865 self.
searchb = wx.SearchCtrl(self, size = (200,-1),
866 style = wx.TE_PROCESS_ENTER)
870 for key
in self.parent.datums.keys():
871 data.append([key, self.parent.datums[key][0], self.parent.datums[key][1]])
874 columns = [_(
'Code'), _(
'Ellipsoid'), _(
'Description')])
875 self.datumlist.resizeLastColumn(10)
878 self.sizer.AddGrowableCol(4)
879 self.sizer.Add(item = self.
MakeLabel(_(
"Datum code:")),
880 flag = wx.ALIGN_LEFT |
881 wx.ALIGN_CENTER_VERTICAL |
882 wx.ALL, border = 5, pos = (1, 1))
883 self.sizer.Add(item = self.
tdatum,
884 flag = wx.ALIGN_LEFT |
885 wx.ALIGN_CENTER_VERTICAL |
886 wx.ALL, border = 5, pos = (1, 2))
888 self.sizer.Add(item = self.
MakeLabel(_(
"Search in description:")),
889 flag = wx.ALIGN_LEFT |
890 wx.ALIGN_CENTER_VERTICAL |
891 wx.ALL, border = 5, pos = (2, 1))
892 self.sizer.Add(item = self.
searchb,
893 flag = wx.ALIGN_LEFT |
894 wx.ALIGN_CENTER_VERTICAL |
895 wx.ALL, border = 5, pos = (2, 2))
897 self.sizer.AddGrowableRow(3)
901 wx.ALL, border = 5, pos = (3, 1), span = (1, 4))
905 self.searchb.Bind(wx.EVT_TEXT_ENTER, self.
OnDSearch)
906 self.tdatum.Bind(wx.EVT_TEXT, self.
OnDText)
907 self.tdatum.Bind(wx.EVT_TEXT_ENTER, self.
OnDText)
909 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
916 proj = self.parent.projpage.p4proj
918 if event.GetDirection():
919 if self.
datum not in self.parent.datums:
924 ret = gcmd.RunCommand(
'g.proj',
926 proj4 =
'%s +datum=%s' % (proj, self.
datum),
933 if dlg.ShowModal() == wx.ID_OK:
934 dtrans = dlg.GetTransform()
938 return 'Datum transform is required.'
942 return 'Datum transform is required.'
944 self.parent.datumtrans = dtrans
946 self.GetNext().SetPrev(self)
947 self.parent.ellipsepage.ellipse = self.
ellipse
948 self.parent.ellipsepage.ellipseparams = self.parent.ellipsoids[self.
ellipse][1]
951 self.parent.datumtrans =
None
952 if event.GetDirection():
953 if len(self.
datum) == 0:
955 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
957 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
962 """!Datum code changed"""
963 self.
datum = event.GetString()
965 nextButton = wx.FindWindowById(wx.ID_FORWARD)
966 if len(self.
datum) == 0
or self.
datum not in self.parent.datums:
967 nextButton.Enable(
False)
973 self.datumparams.remove(
'dx=0.0')
977 self.datumparams.remove(
'dy=0.0')
981 self.datumparams.remove(
'dz=0.0')
985 nextButton.Enable(
True)
991 """!Search geodetic datum by desc"""
992 str = self.searchb.GetValue()
1001 """!Datum selected"""
1002 index = event.m_itemIndex
1003 item = event.GetItem()
1005 self.
datum = self.datumlist.GetItem(index, 0).GetText()
1006 self.tdatum.SetValue(self.
datum)
1011 """!Wizard page for selecting ellipsoid (select coordinate system option)"""
1014 TitledPage.__init__(self, wizard, _(
"Specify ellipsoid"))
1027 self.
searchb = wx.SearchCtrl(self, size = (200,-1),
1028 style = wx.TE_PROCESS_ENTER)
1033 for key
in self.parent.ellipsoids.keys():
1034 data.append([key, self.parent.ellipsoids[key][0]])
1037 columns = [_(
'Code'), _(
'Description')])
1038 self.ellipselist.resizeLastColumn(30)
1041 self.sizer.AddGrowableCol(4)
1042 self.sizer.Add(item = self.
MakeLabel(_(
"Ellipsoid code:")),
1043 flag = wx.ALIGN_RIGHT |
1044 wx.ALIGN_CENTER_VERTICAL |
1045 wx.ALL, border = 5, pos = (1, 1))
1046 self.sizer.Add(item = self.
tellipse,
1047 flag = wx.ALIGN_LEFT |
1048 wx.ALIGN_CENTER_VERTICAL |
1049 wx.ALL, border = 5, pos = (1, 2))
1050 self.sizer.Add(item = self.
MakeLabel(_(
"Search in description:")),
1051 flag = wx.ALIGN_RIGHT |
1052 wx.ALIGN_CENTER_VERTICAL |
1053 wx.ALL, border = 5, pos = (2, 1))
1054 self.sizer.Add(item = self.
searchb,
1055 flag = wx.ALIGN_LEFT |
1056 wx.ALIGN_CENTER_VERTICAL |
1057 wx.ALL, border = 5, pos = (2, 2))
1059 self.sizer.AddGrowableRow(3)
1063 wx.ALL, border = 5, pos = (3, 1), span = (1, 4))
1066 self.ellipselist.Bind(wx.EVT_LIST_ITEM_SELECTED, self.
OnItemSelected)
1067 self.tellipse.Bind(wx.EVT_TEXT, self.
OnText)
1068 self.tellipse.Bind(wx.EVT_TEXT_ENTER, self.
OnText)
1069 self.searchb.Bind(wx.EVT_TEXT_ENTER, self.
OnSearch)
1070 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
1076 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
1078 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
1083 if event.GetDirection()
and self.
ellipse not in self.parent.ellipsoids:
1087 self.GetNext().SetPrev(self)
1088 self.parent.datumpage.datumparams =
''
1092 """!Ellipspoid code changed"""
1093 self.
ellipse = event.GetString()
1094 nextButton = wx.FindWindowById(wx.ID_FORWARD)
1095 if len(self.
ellipse) == 0
or self.
ellipse not in self.parent.ellipsoids:
1096 nextButton.Enable(
False)
1100 elif self.
ellipse in self.parent.ellipsoids:
1103 nextButton.Enable(
True)
1106 """!Search ellipsoid by desc"""
1109 self.ellipselist.Search(index=[0,1], pattern=event.GetString())
1117 """!Ellipsoid selected"""
1118 index = event.m_itemIndex
1119 item = event.GetItem()
1121 self.
ellipse = self.ellipselist.GetItem(index, 0).GetText()
1122 self.tellipse.SetValue(self.
ellipse)
1127 """!Wizard page for selecting georeferenced file to use
1128 for setting coordinate system parameters"""
1131 TitledPage.__init__(self, wizard, _(
"Select georeferenced file"))
1141 self.sizer.AddGrowableCol(3)
1142 self.sizer.Add(item = self.
lfile, flag = wx.ALIGN_LEFT |
1143 wx.ALIGN_CENTRE_VERTICAL |
1144 wx.ALL, border = 5, pos = (1, 1))
1145 self.sizer.Add(item = self.
tfile, flag = wx.ALIGN_LEFT |
1146 wx.ALIGN_CENTRE_VERTICAL |
1147 wx.ALL, border = 5, pos = (1, 2))
1148 self.sizer.Add(item = self.
bbrowse, flag = wx.ALIGN_LEFT |
1149 wx.ALL, border = 5, pos = (1, 3))
1151 self.bbrowse.Bind(wx.EVT_BUTTON, self.
OnBrowse)
1152 self.tfile.Bind(wx.EVT_TEXT, self.
OnText)
1154 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
1162 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
1164 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
1169 if event.GetDirection()
and not os.path.isfile(self.
georeffile):
1171 self.GetNext().SetPrev(self)
1178 nextButton = wx.FindWindowById(wx.ID_FORWARD)
1180 if not nextButton.IsEnabled():
1181 nextButton.Enable(
True)
1183 if nextButton.IsEnabled():
1184 nextButton.Enable(
False)
1190 dlg = wx.FileDialog(self,
1191 _(
"Select georeferenced file"),
1192 os.getcwd(),
"",
"*.*", wx.OPEN)
1193 if dlg.ShowModal() == wx.ID_OK:
1194 path = dlg.GetPath()
1195 self.tfile.SetValue(path)
1201 """!Wizard page for selecting WKT file to use
1202 for setting coordinate system parameters"""
1205 TitledPage.__init__(self, wizard, _(
"Select WKT file"))
1215 self.sizer.AddGrowableCol(3)
1216 self.sizer.Add(item = self.
lfile, flag = wx.ALIGN_LEFT |
1217 wx.ALIGN_CENTRE_VERTICAL |
1218 wx.ALL, border = 5, pos = (1, 1))
1219 self.sizer.Add(item = self.
tfile, flag = wx.ALIGN_LEFT |
1220 wx.ALIGN_CENTRE_VERTICAL |
1221 wx.ALL, border = 5, pos = (1, 2))
1222 self.sizer.Add(item = self.
bbrowse, flag = wx.ALIGN_LEFT |
1223 wx.ALL, border = 5, pos = (1, 3))
1225 self.bbrowse.Bind(wx.EVT_BUTTON, self.
OnBrowse)
1226 self.tfile.Bind(wx.EVT_TEXT, self.
OnText)
1228 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
1233 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
1235 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
1240 if event.GetDirection()
and not os.path.isfile(self.
wktfile):
1242 self.GetNext().SetPrev(self)
1248 self.
wktfile = event.GetString()
1249 nextButton = wx.FindWindowById(wx.ID_FORWARD)
1251 if not nextButton.IsEnabled():
1252 nextButton.Enable(
True)
1254 if nextButton.IsEnabled():
1255 nextButton.Enable(
False)
1261 dlg = wx.FileDialog(self,
1262 _(
"Select WKT file"),
1263 os.getcwd(),
"",
"*.*", wx.OPEN)
1264 if dlg.ShowModal() == wx.ID_OK:
1265 path = dlg.GetPath()
1266 self.tfile.SetValue(path)
1272 """!Wizard page for selecting EPSG code for
1273 setting coordinate system parameters"""
1276 TitledPage.__init__(self, wizard, _(
"Choose EPSG Code"))
1285 style = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
1287 style = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
1289 epsgdir = utils.PathJoin(os.environ[
"GRASS_PROJSHARE"],
'epsg')
1291 style = wx.TE_PROCESS_ENTER)
1298 self.
searchb = wx.SearchCtrl(self, size = (200,-1),
1299 style = wx.TE_PROCESS_ENTER)
1302 columns = [_(
'Code'), _(
'Description'), _(
'Parameters')])
1305 self.sizer.AddGrowableCol(3)
1306 self.sizer.Add(item = self.
lfile,
1307 flag = wx.ALIGN_LEFT |
1308 wx.ALIGN_CENTER_VERTICAL |
1309 wx.ALL, border = 5, pos = (1, 1), span = (1, 2))
1310 self.sizer.Add(item = self.
tfile,
1311 flag = wx.ALIGN_LEFT |
1312 wx.ALIGN_CENTER_VERTICAL |
1313 wx.ALL, border = 5, pos = (1, 3))
1314 self.sizer.Add(item = self.
bbrowse,
1315 flag = wx.ALIGN_LEFT |
1316 wx.ALIGN_CENTER_VERTICAL |
1317 wx.ALL, border = 5, pos = (1, 4))
1318 self.sizer.Add(item = self.
lcode,
1319 flag = wx.ALIGN_LEFT |
1320 wx.ALIGN_CENTER_VERTICAL |
1321 wx.ALL, border = 5, pos = (2, 1), span = (1, 2))
1322 self.sizer.Add(item = self.
tcode,
1323 flag = wx.ALIGN_LEFT |
1324 wx.ALIGN_CENTER_VERTICAL |
1325 wx.ALL, border = 5, pos = (2, 3))
1326 self.sizer.Add(item = self.
searchb,
1327 flag = wx.ALIGN_LEFT |
1328 wx.ALIGN_CENTER_VERTICAL |
1329 wx.ALL, border = 5, pos = (3, 3))
1331 self.sizer.AddGrowableRow(4)
1332 self.sizer.Add(item = self.
epsglist,
1333 flag = wx.ALIGN_LEFT | wx.EXPAND, pos = (4, 1),
1337 self.bbrowse.Bind(wx.EVT_BUTTON, self.
OnBrowse)
1339 self.tcode.Bind(wx.EVT_TEXT, self.
OnText)
1340 self.tcode.Bind(wx.EVT_TEXT_ENTER, self.
OnText)
1341 self.epsglist.Bind(wx.EVT_LIST_ITEM_SELECTED, self.
OnItemSelected)
1342 self.searchb.Bind(wx.EVT_TEXT_ENTER, self.
OnSearch)
1344 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
1347 self.parent.datumtrans =
None
1348 if event.GetDirection():
1351 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
1353 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
1361 if event.GetDirection():
1367 ret = gcmd.RunCommand(
'g.proj',
1377 if dlg.ShowModal() == wx.ID_OK:
1378 dtrans = dlg.GetTransform()
1382 return 'Datum transform is required.'
1386 return 'Datum transform is required.'
1388 self.parent.datumtrans = dtrans
1389 self.GetNext().SetPrev(self)
1398 nextButton = wx.FindWindowById(wx.ID_FORWARD)
1403 if not nextButton.IsEnabled():
1404 nextButton.Enable(
True)
1407 if nextButton.IsEnabled():
1408 nextButton.Enable(
False)
1412 value = self.searchb.GetValue()
1417 self.tcode.SetValue(
'')
1418 self.searchb.SetValue(
'')
1423 self.epsglist.Search(index=[0,1,2], pattern=value)
1424 except (IndexError, ValueError):
1427 self.tcode.SetValue(
'')
1428 self.searchb.SetValue(
'')
1433 """!Define path for EPSG code file"""
1434 path = os.path.dirname(self.tfile.GetValue())
1438 dlg = wx.FileDialog(parent = self, message = _(
"Choose EPSG codes file"),
1439 defaultDir = path, defaultFile =
"", wildcard =
"*", style = wx.OPEN)
1441 if dlg.ShowModal() == wx.ID_OK:
1442 path = dlg.GetPath()
1443 self.tfile.SetValue(path)
1451 """!EPSG code selected from the list"""
1452 index = event.m_itemIndex
1453 item = event.GetItem()
1455 self.
epsgcode = int(self.epsglist.GetItem(index, 0).GetText())
1456 self.
epsgdesc = self.epsglist.GetItem(index, 1).GetText()
1457 self.tcode.SetValue(str(self.
epsgcode))
1462 """!Browse EPSG codes"""
1463 self.
epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
1466 wx.MessageBox(parent = self,
1467 message = _(
"Unable to read EPGS codes: %s") % self.
epsgCodeDict,
1468 caption = _(
"Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
1469 self.epsglist.Populate(list(), update =
True)
1473 for code, val
in self.epsgCodeDict.iteritems():
1474 if code
is not None:
1475 data.append((code, val[0], val[1]))
1477 self.epsglist.Populate(data, update =
True)
1480 """!Wizard page for entering custom PROJ.4 string
1481 for setting coordinate system parameters"""
1484 TitledPage.__init__(self, wizard,
1485 _(
"Choose method of specifying georeferencing parameters"))
1492 style = wx.TE_MULTILINE)
1496 self.sizer.AddGrowableCol(2)
1498 flag = wx.ALIGN_LEFT | wx.ALL,
1499 border = 5, pos = (1, 1))
1500 self.sizer.AddGrowableRow(2)
1502 flag = wx.ALIGN_LEFT | wx.ALL | wx.EXPAND,
1503 border = 5, pos = (2, 1), span = (1, 2))
1507 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
1512 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
1514 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
1517 if event.GetDirection():
1519 ret, out, err = gcmd.RunCommand(
'g.proj',
1520 read =
True, getErrorMsg =
True,
1524 wx.MessageBox(parent = self,
1526 caption = _(
"Error"),
1527 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
1536 if dlg.ShowModal() == wx.ID_OK:
1537 dtrans = dlg.GetTransform()
1538 if len(dtrans) == 0:
1541 return _(
'Datum transform is required.')
1545 return _(
'Datum transform is required.')
1547 self.parent.datumtrans = dtrans
1549 self.GetNext().SetPrev(self)
1552 """!Change proj string"""
1555 nextButton = wx.FindWindowById(wx.ID_FORWARD)
1557 if nextButton.IsEnabled():
1558 nextButton.Enable(
False)
1560 if not nextButton.IsEnabled():
1564 """!Shows summary result of choosing coordinate system parameters
1565 prior to creating location"""
1567 TitledPage.__init__(self, wizard, _(
"Summary"))
1570 self.
panelTitle = scrolled.ScrolledPanel(parent = self, id = wx.ID_ANY)
1572 self.
panelProj = scrolled.ScrolledPanel(parent = self, id = wx.ID_ANY)
1581 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
1586 def _doLayout(self):
1587 """!Do page layout"""
1588 self.sizer.AddGrowableCol(1)
1589 self.sizer.AddGrowableRow(3, 1)
1590 self.sizer.AddGrowableRow(4, 1)
1591 self.sizer.AddGrowableRow(5, 5)
1593 titleSizer = wx.BoxSizer(wx.VERTICAL)
1594 titleSizer.Add(item = self.
llocTitle, proportion = 1,
1595 flag = wx.EXPAND | wx.ALL, border = 5)
1596 self.panelTitle.SetSizer(titleSizer)
1598 projSizer = wx.BoxSizer(wx.VERTICAL)
1599 projSizer.Add(item = self.
lprojection, proportion = 1,
1600 flag = wx.EXPAND | wx.ALL, border = 5)
1601 self.panelProj.SetSizer(projSizer)
1603 proj4stringSizer = wx.BoxSizer(wx.VERTICAL)
1604 proj4stringSizer.Add(item = self.
lproj4string, proportion = 1,
1605 flag = wx.EXPAND | wx.ALL, border = 5)
1606 self.panelProj4string.SetSizer(proj4stringSizer)
1608 self.panelProj4string.SetupScrolling()
1609 self.panelProj.SetupScrolling(scroll_y =
False)
1610 self.panelTitle.SetupScrolling(scroll_y =
False)
1612 self.sizer.Add(item = self.
MakeLabel(_(
"GRASS Database:")),
1613 flag = wx.ALIGN_LEFT | wx.ALL,
1614 border = 5, pos = (1, 0))
1616 flag = wx.ALIGN_LEFT | wx.ALL,
1617 border = 5, pos = (1, 1))
1618 self.sizer.Add(item = self.
MakeLabel(_(
"Location Name:")),
1619 flag = wx.ALIGN_LEFT | wx.ALL,
1620 border = 5, pos = (2, 0))
1622 flag = wx.ALIGN_LEFT | wx.ALL,
1623 border = 5, pos = (2, 1))
1624 self.sizer.Add(item = self.
MakeLabel(_(
"Location Title:")),
1625 flag = wx.ALIGN_LEFT | wx.ALL,
1626 border = 5, pos = (3, 0))
1628 flag = wx.ALIGN_LEFT | wx.ALL | wx.EXPAND,
1629 border = 0, pos = (3, 1))
1630 self.sizer.Add(item = self.
MakeLabel(_(
"Projection:")),
1631 flag = wx.ALIGN_LEFT | wx.ALL,
1632 border = 5, pos = (4, 0))
1634 flag = wx.ALIGN_LEFT | wx.ALL | wx.EXPAND,
1635 border = 0, pos = (4, 1))
1636 self.sizer.Add(item = self.
MakeLabel(_(
"PROJ.4 definition:")),
1637 flag = wx.ALIGN_LEFT | wx.ALL,
1638 border = 5, pos = (5, 0))
1640 flag = wx.ALIGN_LEFT | wx.ALL | wx.EXPAND,
1641 border = 0, pos = (5, 1))
1644 """!Insert values into text controls for summary of location
1647 database = self.parent.startpage.grassdatabase
1648 location = self.parent.startpage.location
1649 proj4string = self.parent.CreateProj4String()
1650 epsgcode = self.parent.epsgpage.epsgcode
1651 dtrans = self.parent.datumtrans
1654 if coordsys
in (
'proj',
'epsg'):
1655 if coordsys ==
'proj':
1656 ret, projlabel, err = gcmd.RunCommand(
'g.proj',
1658 proj4 = proj4string,
1659 datumtrans = dtrans,
1660 location = location,
1663 elif coordsys ==
'epsg':
1664 ret, projlabel, err = gcmd.RunCommand(
'g.proj',
1667 datumtrans = dtrans,
1668 location = location,
1672 finishButton = wx.FindWindowById(wx.ID_FORWARD)
1674 self.lproj4string.SetLabel(projlabel.replace(
' ', os.linesep))
1675 finishButton.Enable(
True)
1678 self.lproj4string.SetLabel(
'')
1679 finishButton.Enable(
False)
1681 projdesc = self.parent.projpage.projdesc
1682 ellipsedesc = self.parent.ellipsepage.ellipsedesc
1683 datumdesc = self.parent.datumpage.datumdesc
1684 self.ldatabase.SetLabel(database)
1685 self.llocation.SetLabel(location)
1686 self.llocTitle.SetLabel(self.parent.startpage.locTitle)
1689 if coordsys ==
'epsg':
1690 label =
'EPSG code %s (%s)' % (self.parent.epsgpage.epsgcode, self.parent.epsgpage.epsgdesc)
1691 elif coordsys ==
'file':
1692 label =
'matches file %s' % self.parent.filepage.georeffile
1693 self.lproj4string.SetLabel(
"")
1694 elif coordsys ==
'wkt':
1695 label =
'matches file %s' % self.parent.wktpage.wktfile
1696 self.lproj4string.SetLabel(
"")
1697 elif coordsys ==
'proj':
1698 label = (
'%s, %s %s' % (projdesc, datumdesc, ellipsedesc))
1699 elif coordsys ==
'xy':
1700 label = (
'XY coordinate system (not projected).')
1701 self.lproj4string.SetLabel(
"")
1702 elif coordsys ==
'custom':
1704 self.lproj4string.SetLabel((
'%s' % self.parent.custompage.customstring.replace(
' ', os.linesep)))
1705 self.lprojection.SetLabel(label)
1708 dlg = wx.MessageDialog(parent = self.wizard,
1709 message = _(
"Do you want to create GRASS location <%s>?") % location,
1710 caption = _(
"Create new location?"),
1711 style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
1713 if dlg.ShowModal() == wx.ID_NO:
1721 """!Start wizard here and finish wizard here
1732 imagePath = os.path.join(globalvar.ETCIMGDIR,
"loc_wizard_qgis.png")
1733 wizbmp = wx.Image(imagePath, wx.BITMAP_TYPE_PNG)
1734 wizbmp = wizbmp.ConvertToBitmap()
1750 self.
wizard = wiz.Wizard(parent, id = wx.ID_ANY, title = _(
"Define new GRASS Location"),
1751 bitmap = wizbmp, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
1770 self.csystemspage.SetPrev(self.
startpage)
1771 self.csystemspage.SetNext(self.
sumpage)
1776 self.paramspage.SetPrev(self.
projpage)
1780 self.datumpage.SetNext(self.
sumpage)
1783 self.ellipsepage.SetNext(self.
sumpage)
1786 self.epsgpage.SetNext(self.
sumpage)
1789 self.filepage.SetNext(self.
sumpage)
1792 self.wktpage.SetNext(self.
sumpage)
1795 self.custompage.SetNext(self.
sumpage)
1802 self.startpage.DoLayout()
1803 self.csystemspage.DoLayout()
1804 self.projpage.DoLayout()
1805 self.datumpage.DoLayout()
1806 self.paramspage.DoLayout()
1807 self.epsgpage.DoLayout()
1808 self.filepage.DoLayout()
1809 self.wktpage.DoLayout()
1810 self.ellipsepage.DoLayout()
1811 self.custompage.DoLayout()
1812 self.sumpage.DoLayout()
1814 size = self.wizard.GetPageSize()
1815 self.wizard.SetPageSize((size[0], size[1] + 75))
1827 if self.wizard.RunWizard(self.
startpage):
1830 self.wizard.Destroy()
1831 self.
location = self.startpage.location
1833 if self.
altdb ==
False:
1834 dlg = wx.MessageDialog(parent = self.
parent,
1835 message = _(
"Do you want to set the default "
1836 "region extents and resolution now?"),
1837 caption = _(
"Location <%s> created") % self.
location,
1838 style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
1839 dlg.CenterOnScreen()
1840 if dlg.ShowModal() == wx.ID_YES:
1843 defineRegion.CenterOnScreen()
1848 self.wizard.Destroy()
1850 message =
"%s" % _(
"Unable to create new location. "
1851 "Location <%(loc)s> not created.\n\n"
1852 "Details: %(err)s") % \
1853 {
'loc' : self.startpage.location,
1856 self.wizard.Destroy()
1858 message = _(
"Location wizard canceled. "
1859 "Location not created."))
1863 def __cleanUp(self):
1879 transformlist = list()
1881 def __readData(self):
1882 """!Get georeferencing information from tables in $GISBASE/etc"""
1885 f = open(os.path.join(globalvar.ETCDIR,
"proj-parms.table"),
"r")
1888 for line
in f.readlines():
1891 proj, projdesc, params = line.split(
':')
1892 paramslist = params.split(
';')
1894 for p
in paramslist:
1895 if p ==
'':
continue
1896 p1, pdefault = p.split(
',')
1897 pterm, pask = p1.split(
'=')
1898 p = [pterm.strip(), pask.strip(), pdefault.strip()]
1900 self.
projections[proj.lower().strip()] = (projdesc.strip(), plist)
1901 self.
projdesc[proj.lower().strip()] = projdesc.strip()
1907 f = open(os.path.join(globalvar.ETCDIR,
"datum.table"),
"r")
1910 for line
in f.readlines():
1911 line = line.expandtabs(1)
1913 if line ==
'' or line[0] ==
"#":
1915 datum, info = line.split(
" ", 1)
1917 datumdesc, params = info.split(
" ", 1)
1918 datumdesc = datumdesc.strip(
'"')
1919 paramlist = params.split()
1920 ellipsoid = paramlist.pop(0)
1921 self.
datums[datum] = (ellipsoid, datumdesc.replace(
'_',
' '), paramlist)
1925 f = open(os.path.join(globalvar.ETCDIR,
"ellipse.table"),
"r")
1927 for line
in f.readlines():
1928 line = line.expandtabs(1)
1930 if line ==
'' or line[0] ==
"#":
1932 ellipse, rest = line.split(
" ", 1)
1933 rest = rest.strip(
'" ')
1934 desc, params = rest.split(
'"', 1)
1935 desc = desc.strip(
'" ')
1936 paramslist = params.split()
1937 self.
ellipsoids[ellipse] = (desc, paramslist)
1941 f = open(os.path.join(globalvar.ETCDIR,
"proj-desc.table"),
"r")
1943 for line
in f.readlines():
1946 pparam, datatype, proj4term, desc = line.split(
':')
1947 self.
paramdesc[pparam] = (datatype, proj4term, desc)
1953 """!Wizard finished, create new location
1955 @return error message on error
1956 @return None on success
1958 database = self.startpage.grassdatabase
1959 location = self.startpage.location
1962 if os.path.isdir(os.path.join(database,location)):
1964 message =
"%s <%s>: %s" % \
1965 (_(
"Unable to create new location"),
1966 os.path.join(database, location),
1967 _(
"Location already exists in GRASS Database.")))
1971 current_gdb = grass.gisenv()[
'GISDBASE']
1972 if current_gdb != database:
1974 if os.path.isdir(database) !=
True:
1979 gcmd.RunCommand(
'g.gisenv',
1981 set =
'GISDBASE=%s' % database)
1983 wx.MessageBox(parent = self.
wizard,
1984 message = _(
"Location <%(loc)s> will be created "
1985 "in GIS data directory <%(dir)s>. "
1986 "You will need to change the default GIS "
1987 "data directory in the GRASS startup screen.") % \
1988 {
'loc' : location,
'dir' : database},
1989 caption = _(
"New GIS data directory"),
1990 style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
1997 if coordsys ==
"xy":
1998 grass.create_location(dbase = self.startpage.grassdatabase,
1999 location = self.startpage.location,
2000 desc = self.startpage.locTitle)
2001 elif coordsys ==
"proj":
2002 grass.create_location(dbase = self.startpage.grassdatabase,
2003 location = self.startpage.location,
2006 desc = self.startpage.locTitle)
2007 elif coordsys ==
'custom':
2008 grass.create_location(dbase = self.startpage.grassdatabase,
2009 location = self.startpage.location,
2010 proj4 = self.custompage.customstring,
2011 desc = self.startpage.locTitle)
2012 elif coordsys ==
"epsg":
2013 if not self.epsgpage.epsgcode:
2014 return _(
'EPSG code missing.')
2016 grass.create_location(dbase = self.startpage.grassdatabase,
2017 location = self.startpage.location,
2018 epsg = self.epsgpage.epsgcode,
2020 desc = self.startpage.locTitle)
2021 elif coordsys ==
"file":
2022 if not self.filepage.georeffile
or \
2023 not os.path.isfile(self.filepage.georeffile):
2024 return _(
"File <%s> not found." % self.filepage.georeffile)
2026 grass.create_location(dbase = self.startpage.grassdatabase,
2027 location = self.startpage.location,
2028 filename = self.filepage.georeffile,
2029 desc = self.startpage.locTitle)
2030 elif coordsys ==
"wkt":
2031 if not self.wktpage.wktfile
or \
2032 not os.path.isfile(self.wktpage.wktfile):
2033 return _(
"File <%s> not found." % self.wktpage.wktfile)
2035 grass.create_location(dbase = self.startpage.grassdatabase,
2036 location = self.startpage.location,
2037 wkt = self.wktpage.wktfile,
2038 desc = self.startpage.locTitle)
2040 except grass.ScriptError, e:
2046 """!Constract PROJ.4 string"""
2047 location = self.startpage.location
2048 proj = self.projpage.p4proj
2049 projdesc = self.projpage.projdesc
2050 proj4params = self.paramspage.p4projparams
2052 datum = self.datumpage.datum
2053 if self.datumpage.datumdesc:
2054 datumdesc = self.datumpage.datumdesc +
' - ' + self.datumpage.ellipse
2057 datumparams = self.datumpage.datumparams
2058 ellipse = self.ellipsepage.ellipse
2059 ellipsedesc = self.ellipsepage.ellipsedesc
2060 ellipseparams = self.ellipsepage.ellipseparams
2065 proj4string =
'%s %s' % (proj, proj4params)
2069 proj4string =
'%s +ellps=%s' % (proj4string, ellipse)
2070 for item
in ellipseparams:
2071 if item[:4] ==
'f=1/':
2072 item =
' +rf=' + item[4:]
2075 proj4string =
'%s %s' % (proj4string, item)
2079 proj4string =
'%s +datum=%s' % (proj4string, datum)
2081 for item
in datumparams:
2082 proj4string =
'%s +%s' % (proj4string,item)
2084 proj4string =
'%s +no_defs' % proj4string
2089 """!Page for setting default region extents and resolution
2091 def __init__(self, parent, id = wx.ID_ANY,
2092 title = _(
"Set default region extent and resolution"), location =
None):
2093 wx.Frame.__init__(self, parent, id, title, size = (650,300))
2094 panel = wx.Panel(self, id = wx.ID_ANY)
2096 self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR,
'grass.ico'), wx.BITMAP_TYPE_ICO))
2140 self.
bcancel = wx.Button(panel, id = wx.ID_CANCEL)
2141 self.bset.SetDefault()
2146 self.
img = wx.Image(os.path.join(globalvar.ETCIMGDIR,
"qgis_world.png"),
2147 wx.BITMAP_TYPE_PNG).ConvertToBitmap()
2154 ret = gcmd.RunCommand(
'g.gisenv',
2157 for line
in ret.splitlines():
2158 key, val = line.split(
'=')
2163 gcmd.RunCommand(
'g.gisenv',
2164 set =
'LOCATION_NAME=%s' % self.
location)
2165 gcmd.RunCommand(
'g.gisenv',
2166 set =
'MAPSET=PERMANENT')
2168 dlg = wx.MessageBox(parent = self,
2169 message = _(
'Invalid location selected.'),
2170 caption = _(
"Error"), style = wx.ID_OK | wx.ICON_ERROR)
2177 ret = gcmd.RunCommand(
'g.region',
2181 for line
in ret.splitlines():
2182 key, val = line.split(
'=')
2183 region[key] = float(val)
2185 dlg = wx.MessageBox(parent = self,
2186 message = _(
"Invalid region"),
2187 caption = _(
"Error"), style = wx.ID_OK | wx.ICON_ERROR)
2195 self.
north = float(region[
'n'])
2196 self.
south = float(region[
's'])
2197 self.
east = float(region[
'e'])
2198 self.
west = float(region[
'w'])
2199 self.
nsres = float(region[
'nsres'])
2200 self.
ewres = float(region[
'ewres'])
2205 self.
top = float(region[
't'])
2206 self.
bottom = float(region[
'b'])
2209 self.
tbres = float(region[
'tbres'])
2220 style = wx.CP_DEFAULT_STYLE |
2221 wx.CP_NO_TLW_RESIZE | wx.EXPAND)
2223 self.settings3D.Collapse(
False)
2229 self.tnorth.SetValue(str(self.
north))
2230 self.tsouth.SetValue(str(self.
south))
2231 self.twest.SetValue(str(self.
west))
2232 self.teast.SetValue(str(self.
east))
2233 self.tnsres.SetValue(str(self.
nsres))
2234 self.tewres.SetValue(str(self.
ewres))
2235 self.ttop.SetValue(str(self.
top))
2236 self.tbottom.SetValue(str(self.
bottom))
2239 self.ttbres.SetValue(str(self.
tbres))
2240 self.lrows.SetLabel(_(
"Rows: %d") % self.
rows)
2241 self.lcols.SetLabel(_(
"Cols: %d") % self.
cols)
2242 self.lcells.SetLabel(_(
"Cells: %d") % self.
cells)
2249 self.tnorth.Bind(wx.EVT_TEXT, self.
OnValue)
2250 self.tsouth.Bind(wx.EVT_TEXT, self.
OnValue)
2251 self.teast.Bind(wx.EVT_TEXT, self.
OnValue)
2252 self.twest.Bind(wx.EVT_TEXT, self.
OnValue)
2253 self.tnsres.Bind(wx.EVT_TEXT, self.
OnValue)
2254 self.tewres.Bind(wx.EVT_TEXT, self.
OnValue)
2255 self.ttop.Bind(wx.EVT_TEXT, self.
OnValue)
2256 self.tbottom.Bind(wx.EVT_TEXT, self.
OnValue)
2259 self.ttbres.Bind(wx.EVT_TEXT, self.
OnValue)
2262 self.SetMinSize(self.GetBestSize())
2266 """!Create 3D region settings pane"""
2267 border = wx.BoxSizer(wx.VERTICAL)
2268 gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
2271 self.
ttop = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.
top),
2273 self.
tbottom = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.
bottom),
2275 self.
ttbres = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.
tbres),
2283 self.
ldepth = wx.StaticText(parent = pane, label = _(
"Depth: %d") % self.
depth)
2284 self.
lcells3 = wx.StaticText(parent = pane, label = _(
"3D Cells: %d") % self.
cells3)
2287 gridSizer.Add(item = wx.StaticText(parent = pane, label = _(
"Top")),
2288 flag = wx.ALIGN_CENTER |
2289 wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
2291 gridSizer.Add(item = self.
ttop,
2292 flag = wx.ALIGN_CENTER_HORIZONTAL |
2293 wx.ALL, border = 5, pos = (1, 1))
2295 gridSizer.Add(item = wx.StaticText(parent = pane, label = _(
"Bottom")),
2296 flag = wx.ALIGN_CENTER |
2297 wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
2299 gridSizer.Add(item = self.
tbottom,
2300 flag = wx.ALIGN_CENTER_HORIZONTAL |
2301 wx.ALL, border = 5, pos = (1, 2))
2303 gridSizer.Add(item = wx.StaticText(parent = pane, label = _(
"T-B resolution")),
2304 flag = wx.ALIGN_CENTER |
2305 wx.LEFT | wx.RIGHT | wx.TOP, border = 5,
2307 gridSizer.Add(item = self.
ttbres,
2308 flag = wx.ALIGN_CENTER_HORIZONTAL |
2309 wx.ALL, border = 5, pos = (1, 3))
2328 gridSizer.Add(item = self.
ldepth,
2329 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
2330 wx.ALL, border = 5, pos = (2, 1))
2332 gridSizer.Add(item = self.
lcells3,
2333 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
2334 wx.ALL, border = 5, pos = (2, 2))
2336 border.Add(item = gridSizer, proportion = 1,
2337 flag = wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border = 5)
2339 pane.SetSizer(border)
2343 """!Collapse 3D settings box"""
2345 if self.settings3D.IsExpanded():
2348 self.SetSize(self.GetBestSize())
2349 self.SetMinSize(self.GetSize())
2356 self.SendSizeEvent()
2358 def __DoLayout(self, panel):
2359 """!Window layout"""
2360 frameSizer = wx.BoxSizer(wx.VERTICAL)
2361 gridSizer = wx.GridBagSizer(vgap = 0, hgap = 0)
2362 settings3DSizer = wx.BoxSizer(wx.VERTICAL)
2363 buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
2366 gridSizer.Add(item = self.
MakeLabel(text = _(
"North"), parent = panel),
2367 flag = wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL |
2368 wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (0, 2))
2369 gridSizer.Add(item = self.
tnorth,
2370 flag = wx.ALIGN_CENTER_HORIZONTAL |
2371 wx.ALIGN_CENTER_VERTICAL |
2372 wx.ALL, border = 5, pos = (1, 2))
2374 gridSizer.Add(item = self.
MakeLabel(text = _(
"West"), parent = panel),
2375 flag = wx.ALIGN_RIGHT |
2376 wx.ALIGN_CENTER_VERTICAL |
2377 wx.LEFT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 0))
2378 gridSizer.Add(item = self.
twest,
2379 flag = wx.ALIGN_RIGHT |
2380 wx.ALIGN_CENTER_VERTICAL |
2381 wx.ALL, border = 5, pos = (2, 1))
2383 gridSizer.Add(item = wx.StaticBitmap(panel, wx.ID_ANY, self.
img, (-1, -1),
2384 (self.img.GetWidth(), self.img.GetHeight())),
2385 flag = wx.ALIGN_CENTER |
2386 wx.ALIGN_CENTER_VERTICAL |
2387 wx.ALL, border = 5, pos = (2, 2))
2390 gridSizer.Add(item = self.
teast,
2391 flag = wx.ALIGN_CENTER_HORIZONTAL |
2392 wx.ALIGN_CENTER_VERTICAL |
2393 wx.ALL, border = 5, pos = (2, 3))
2394 gridSizer.Add(item = self.
MakeLabel(text = _(
"East"), parent = panel),
2395 flag = wx.ALIGN_LEFT |
2396 wx.ALIGN_CENTER_VERTICAL |
2397 wx.RIGHT | wx.TOP | wx.BOTTOM, border = 5, pos = (2, 4))
2399 gridSizer.Add(item = self.
tsouth,
2400 flag = wx.ALIGN_CENTER_HORIZONTAL |
2401 wx.ALIGN_CENTER_VERTICAL |
2402 wx.ALL, border = 5, pos = (3, 2))
2403 gridSizer.Add(item = self.
MakeLabel(text = _(
"South"), parent = panel),
2404 flag = wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL |
2405 wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5, pos = (4, 2))
2407 gridSizer.Add(item = self.
MakeLabel(text = _(
"N-S resolution"), parent = panel),
2408 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
2409 wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 1))
2410 gridSizer.Add(item = self.
tnsres,
2411 flag = wx.ALIGN_RIGHT |
2412 wx.ALIGN_CENTER_VERTICAL |
2413 wx.ALL, border = 5, pos = (6, 1))
2415 gridSizer.Add(item = self.
MakeLabel(text = _(
"E-W resolution"), parent = panel),
2416 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
2417 wx.TOP | wx.LEFT | wx.RIGHT, border = 5, pos = (5, 3))
2418 gridSizer.Add(item = self.
tewres,
2419 flag = wx.ALIGN_RIGHT |
2420 wx.ALIGN_CENTER_VERTICAL |
2421 wx.ALL, border = 5, pos = (6, 3))
2423 gridSizer.Add(item = self.
lrows,
2424 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
2425 wx.ALL, border = 5, pos = (7, 1))
2427 gridSizer.Add(item = self.
lcells,
2428 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
2429 wx.ALL, border = 5, pos = (7, 2))
2431 gridSizer.Add(item = self.
lcols,
2432 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER |
2433 wx.ALL, border = 5, pos = (7, 3))
2441 buttonSizer.Add(item = self.
bcancel, proportion = 1,
2442 flag = wx.ALIGN_RIGHT |
2443 wx.ALIGN_CENTER_VERTICAL |
2444 wx.ALL, border = 10)
2445 buttonSizer.Add(item = self.
bset, proportion = 1,
2446 flag = wx.ALIGN_CENTER |
2447 wx.ALIGN_CENTER_VERTICAL |
2448 wx.ALL, border = 10)
2450 frameSizer.Add(item = gridSizer, proportion = 1,
2451 flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
2452 frameSizer.Add(item = settings3DSizer, proportion = 0,
2453 flag = wx.ALL | wx.ALIGN_CENTER, border = 5)
2454 frameSizer.Add(item = buttonSizer, proportion = 0,
2455 flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
2457 self.SetAutoLayout(
True)
2458 panel.SetSizer(frameSizer)
2459 frameSizer.Fit(panel)
2463 """!Set given value"""
2465 if event.GetId() == self.tnorth.GetId():
2466 self.
north = float(event.GetString())
2467 elif event.GetId() == self.tsouth.GetId():
2468 self.
south = float(event.GetString())
2469 elif event.GetId() == self.teast.GetId():
2470 self.
east = float(event.GetString())
2471 elif event.GetId() == self.twest.GetId():
2472 self.
west = float(event.GetString())
2473 elif event.GetId() == self.tnsres.GetId():
2474 self.
nsres = float(event.GetString())
2475 elif event.GetId() == self.tewres.GetId():
2476 self.
ewres = float(event.GetString())
2477 elif event.GetId() == self.ttop.GetId():
2478 self.
top = float(event.GetString())
2479 elif event.GetId() == self.tbottom.GetId():
2480 self.
bottom = float(event.GetString())
2485 elif event.GetId() == self.ttbres.GetId():
2486 self.
tbres = float(event.GetString())
2490 except ValueError, e:
2491 if len(event.GetString()) > 0
and event.GetString() !=
'-':
2492 dlg = wx.MessageBox(parent = self,
2493 message = _(
"Invalid value: %s") % e,
2494 caption = _(
"Error"),
2495 style = wx.OK | wx.ICON_ERROR)
2497 self.tnorth.SetValue(str(self.
north))
2498 self.tsouth.SetValue(str(self.
south))
2499 self.teast.SetValue(str(self.
east))
2500 self.twest.SetValue(str(self.
west))
2501 self.tnsres.SetValue(str(self.
nsres))
2502 self.tewres.SetValue(str(self.
ewres))
2503 self.ttop.SetValue(str(self.
top))
2504 self.tbottom.SetValue(str(self.
bottom))
2505 self.ttbres.SetValue(str(self.
tbres))
2511 def __UpdateInfo(self):
2512 """!Update number of rows/cols/cells"""
2521 self.lrows.SetLabel(_(
"Rows: %d") % self.
rows)
2522 self.lcols.SetLabel(_(
"Cols: %d") % self.
cols)
2523 self.lcells.SetLabel(_(
"Cells: %d") % self.
cells)
2525 self.ldepth.SetLabel(_(
"Depth: %d" % self.
depth))
2526 self.lcells3.SetLabel(_(
"3D Cells: %d" % self.
cells3))
2529 """!Set default region"""
2530 ret = gcmd.RunCommand(
'g.region',
2548 """!Creates a multiline listbox for selecting datum transforms"""
2551 if self.GetSelection() == n:
2552 c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
2554 c = self.GetForegroundColour()
2555 dc.SetFont(self.GetFont())
2556 dc.SetTextForeground(c)
2558 wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
2565 w, h = self.GetTextExtent(line)
2569 def _getItemText(self, item):
2570 global transformlist
2571 transitem = transformlist[item]
2572 if transitem.strip() !=
'':
2577 """!Dialog for selecting datum transformations"""
2578 def __init__(self, parent, transforms, title = _(
"Select datum transformation"),
2579 pos = wx.DefaultPosition, size = wx.DefaultSize,
2580 style = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
2582 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
2584 global transformlist
2585 self.CentreOnParent()
2590 panel = scrolled.ScrolledPanel(self, wx.ID_ANY)
2591 sizer = wx.BoxSizer(wx.VERTICAL)
2596 panel.SetSizer(sizer)
2597 panel.SetupScrolling()
2602 bodyBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
2603 label =
" %s " % _(
"Select from list of datum transformations"))
2604 bodySizer = wx.StaticBoxSizer(bodyBox)
2607 transforms =
'---\n\n0\nDo not apply any datum transformations\n\n' + transforms
2609 transformlist = transforms.split(
'---')
2610 tlistlen = len(transformlist)
2615 for line
in transforms.splitlines():
2616 w, h = self.GetTextExtent(line)
2618 width =
max(width, w)
2621 if height > 400: height = 400
2623 if width > 400: width = 400
2629 self.translist.SetItemCount(tlistlen)
2630 self.translist.SetSelection(2)
2631 self.translist.SetFocus()
2635 bodySizer.Add(item = self.
translist, proportion = 1, flag = wx.ALIGN_CENTER|wx.ALL|wx.EXPAND)
2640 btnsizer = wx.StdDialogButtonSizer()
2642 btn = wx.Button(parent = panel, id = wx.ID_OK)
2644 btnsizer.AddButton(btn)
2646 btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
2647 btnsizer.AddButton(btn)
2650 sizer.Add(item = bodySizer, proportion = 1,
2651 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
2653 sizer.Add(item = btnsizer, proportion = 0,
2654 flag = wx.ALL | wx.ALIGN_RIGHT, border = 5)
2658 self.SetSize(self.GetBestSize())
2662 """!Get the number of the datum transform to use in g.proj"""
2663 self.
transnum = event.GetSelection()
2667 """!Get the number of the datum transform to use in g.proj"""
2668 self.
transnum = self.translist.GetSelection()
2672 if __name__ ==
"__main__":
2674 gettext.install(
'grasswxpy', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode =
True)
2675 app = wx.PySimpleApp()