[GRASS-SVN] r39554 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 18 02:16:12 EDT 2009


Author: cmbarton
Date: 2009-10-18 02:16:08 -0400 (Sun, 18 Oct 2009)
New Revision: 39554

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py
Log:
Major enhancement and fix. All projection parameters now selectable by user. Summary page shows g.proj output (i.e., what will show up in GRASS). State Plane projection will bring up a warning box instructing user to use EPSG or custom PROJ4 string. Fixed a number of minor and a few major bugs.

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py	2009-10-17 20:14:31 UTC (rev 39553)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py	2009-10-18 06:16:08 UTC (rev 39554)
@@ -11,7 +11,7 @@
  - CoordinateSystemPage
  - ProjectionsPage
  - ItemList
- - ProjTypePage
+ - ProjParamsPage
  - DatumPage
  - EllipsePage
  - GeoreferencedFilePage
@@ -111,26 +111,24 @@
         self.title = wx.StaticText(parent=self, id=wx.ID_ANY, label=title)
         self.title.SetFont(wx.Font(13, wx.SWISS, wx.NORMAL, wx.BOLD))
 
-        # main sizer
+        # main sizers
+        self.pagesizer = wx.BoxSizer(wx.VERTICAL)
         self.sizer = wx.GridBagSizer(vgap=0, hgap=0)
         
     def DoLayout(self):
         """!Do page layout"""
       
-        tmpsizer = wx.BoxSizer(wx.VERTICAL)
 
-        tmpsizer.Add(item=self.title, proportion=0,
+        self.pagesizer.Add(item=self.title, proportion=0,
                      flag=wx.ALIGN_CENTRE | wx.ALL,
                      border=5)
-        tmpsizer.Add(item=wx.StaticLine(self, -1), proportion=0,
+        self.pagesizer.Add(item=wx.StaticLine(self, -1), proportion=0,
                      flag=wx.EXPAND | wx.ALL,
                      border=0)
-        tmpsizer.Add(item=self.sizer, proportion=1,
-                     flag=wx.EXPAND | wx.ALL,
-                     border=5)
+        self.pagesizer.Add(item=self.sizer)
 
         self.SetAutoLayout(True)
-        self.SetSizer(tmpsizer)
+        self.SetSizer(self.pagesizer)
         # tmpsizer.Fit(self)
         self.Layout()
 
@@ -300,8 +298,25 @@
 
     def OnEnterPage(self, event):
         global coordsys
-        if event.GetDirection() and not coordsys:
+        
+        if not coordsys:
             coordsys = "proj"
+            self.radio1.SetValue(True)
+        else:
+            if coordsys == 'proj':
+                self.radio1.SetValue(True)
+            if coordsys == "epsg":
+                self.radio2.SetValue(True)
+            if coordsys == "file":
+                self.radio3.SetValue(True)
+            if coordsys == "wkt":
+                self.radio4.SetValue(True)
+            if coordsys == "custom":
+                self.radio5.SetValue(True)
+            if coordsys == "xy":
+                self.radio6.SetValue(True)
+                
+        if event.GetDirection():
             self.SetNext(self.parent.projpage)
             self.parent.sumpage.SetPrev(self.parent.datumpage)
             
@@ -346,6 +361,7 @@
         self.parent = parent
         self.proj = ''
         self.projdesc = ''
+        self.p4proj = ''
 
         # text input
         self.tproj = self.MakeTextCtrl("", size=(200,-1))
@@ -355,7 +371,7 @@
                                      style=wx.TE_PROCESS_ENTER)
 
         # projection list
-        self.projlist = ItemList(self, data=self.parent.projections.items(),
+        self.projlist = ItemList(self, data=self.parent.projdesc.items(),
                                  columns=[_('Code'), _('Description')])
         self.projlist.resizeLastColumn(30) 
 
@@ -394,27 +410,31 @@
         # self.Layout()
 
     def OnPageChanging(self,event):
-        if event.GetDirection() and self.proj not in self.parent.projections:
+        if event.GetDirection() and self.proj not in self.parent.projections.keys():
             event.Veto()
-        if self.proj == 'utm':
-            self.parent.projtypepage.text_utm.SetEditable(True)
-            self.parent.projtypepage.hemischoices = ['north','south']
-        else:
-            self.parent.projtypepage.text_utm.SetValue('')
-            self.parent.projtypepage.text_utm.SetEditable(False)
-            self.parent.projtypepage.hemischoices = []
 
     def OnText(self, event):
         """!Projection name changed"""
         self.proj = event.GetString().lower()
+        self.p4proj = ''
         nextButton = wx.FindWindowById(wx.ID_FORWARD)
         if len(self.proj) == 0 and nextButton.IsEnabled():
             nextButton.Enable(False)
         
-        if self.proj in self.parent.projections:
-            self.projdesc = self.parent.projections[self.proj]
-            if not nextButton.IsEnabled():
-                nextButton.Enable()
+        if self.proj in self.parent.projections.keys():
+            if self.proj == 'stp':
+                wx.MessageBox('State Plan Projection must be entered as an EPSG code or a custom PROJ4 string', 
+                              'Warning', wx.ICON_WARNING)
+                self.proj = ''
+                self.tproj.SetValue(self.proj)
+                nextButton.Enable(False)
+                return
+            elif self.proj.lower() == 'll':
+                self.p4proj = '+proj=longlat'
+            else:
+                self.p4proj = '+proj=' + self.proj.lower()
+            self.projdesc = self.parent.projections[self.proj][0]
+            nextButton.Enable()
 
     def OnEnterPage(self, event):
         if len(self.proj) == 0:
@@ -432,7 +452,7 @@
             self.proj, self.projdesc = self.projlist.Search(index=[0,1], pattern=event.GetString())
         except:
             self.proj = self.projdesc = ''
-
+            
         event.Skip()
 
     def OnItemSelected(self, event):
@@ -441,8 +461,9 @@
 
         # set values
         self.proj = self.projlist.GetItem(index, 0).GetText().lower()
-        self.projdesc = self.projlist.GetItem(index, 0).GetText()
         self.tproj.SetValue(self.proj)
+        
+        event.Skip()
 
 class ItemList(wx.ListCtrl,
                listmix.ListCtrlAutoWidthMixin,
@@ -524,26 +545,15 @@
             self.DeleteAllItems()
             row = 0
             for value in data:
-                # index = self.InsertStringItem(sys.maxint, str(value[0]))
                 self.itemDataMap[row] = [value[0]]
                 for i in range(1, len(value)):
-                    # try:
-                    # self.SetStringItem(index, i, str(value[i]))
-                    # except:
-                    # self.SetStringItem(index, i, unicode(str(value[i]), 'latin1'))
-                    self.itemDataMap[row].append(value[i])
-                # self.SetItemData(index, row)
+                     self.itemDataMap[row].append(value[i])
                 self.itemIndexMap.append(row)
                 row += 1
 
             self.SetItemCount(row)
             
             # set column width
-#            for i in range(self.GetColumnCount()):
-#                self.SetColumnWidth(i, wx.LIST_AUTOSIZE)
-#            for i in range(self.GetColumnCount()):z
-#            if self.GetColumnWidth(i) < 80:
-#            self.SetColumnWidth(i, 80)
             self.SetColumnWidth(0, 80)
             self.SetColumnWidth(1, 300)
             
@@ -633,108 +643,174 @@
 
         data = []
         pattern = pattern.lower()
-        for idx in index:
-            for i in range(len(self.sourceData)):
+        for i in range(len(self.sourceData)):
+            for idx in index:
                 try:
                     value = str(self.sourceData[i][idx]).lower()
                     if pattern in value:
                         data.append(self.sourceData[i])
+                        break
                 except UnicodeDecodeError:
                     # osgeo4w problem (should be fixed)
                     pass
 
         self.Populate(data)
         if len(data) > 0:
-            
             return data[0]
         else:
 #            self.Populate(self.sourceData)
             return []
 
-class ProjTypePage(TitledPage):
+class ProjParamsPage(TitledPage):
     """
     Wizard page for selecting method of setting coordinate system parameters
     (select coordinate system option)
     """
 
     def __init__(self, wizard, parent):
-        TitledPage.__init__(self, wizard, _("Choose method of specifying georeferencing parameters"))
+        TitledPage.__init__(self, wizard, _("Choose projection parameters"))
         global coordsys
 
         self.utmzone = ''
         self.utmhemisphere = ''
         self.hemischoices = ["north","south"]
         self.parent = parent
+        self.panel = ''
+        self.prjparamsizer = ''
+        self.pentry = {}
+        self.pdesc = {}
+        self.ptype = {}
+        self.pval = {}
+        self.proj4param = {}
+        self.pcount = 0
+        self.paramlist = []
+        self.p4projparams = ''
+        self.projdesc = ''
+        
+        radioSBox = wx.StaticBox(parent=self, id=wx.ID_ANY,
+                               label=" %s " % _("Select datum or ellipsoid (next page)"))
+        radioSBSizer = wx.StaticBoxSizer(radioSBox)
+        self.sizer.Add(radioSBSizer, pos=(0,1), span=(1,2), 
+                           flag=wx.EXPAND | wx.ALIGN_TOP | wx.TOP, border=10)
 
-        self.radio1 = wx.RadioButton(parent=self, id=wx.ID_ANY, label=_("Select datum with associated ellipsoid"),
-                                     style = wx.RB_GROUP)
+        self.radio1 = wx.RadioButton(parent=self, id=wx.ID_ANY, 
+                                label=_("Datum with associated ellipsoid"),
+                                style = wx.RB_GROUP)
         self.radio2 = wx.RadioButton(parent=self, id=wx.ID_ANY,
-                                     label=_("Select ellipsoid"))
-        self.title_utm = self.MakeLabel(_("Set zone for UTM projection:"))
-        self.text_utm = self.MakeTextCtrl(size=(100,-1))
-        self.label_utm = self.MakeLabel(_("Zone:"))
-        self.hemisphere = wx.Choice(parent=self, id=wx.ID_ANY, size=(100, -1),
-                                    choices=self.hemischoices)
-        self.label_hemisphere = self.MakeLabel(_("Hemisphere for zone:"))
+                                label=_("Ellipsoid only"))   
 
-        # layout
-        self.sizer.AddGrowableCol(2)
-        self.sizer.Add(item=self.radio1,
-                       flag=wx.ALIGN_LEFT, pos=(1, 1), span=(1, 2))
-        self.sizer.Add(item=self.radio2,
-                       flag=wx.ALIGN_LEFT, pos=(2, 1), span=(1, 2))
-        self.sizer.Add(item=self.title_utm,
-                       flag=wx.ALIGN_LEFT | wx.ALL,
-                       border=5, pos=(4, 1), span=(1, 2))
-        self.sizer.Add(item=self.label_utm,
-                       flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
-                       border=5, pos=(5, 1), span=(1, 1))
-        self.sizer.Add(item=self.text_utm,
-                       flag=wx.ALIGN_LEFT | wx.ALL, border=5,
-                       pos=(5, 2), span=(1, 1))
-        self.sizer.Add(item=self.label_hemisphere,
-                       flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
-                       border=5, pos=(6, 1), span=(1, 1))
-        self.sizer.Add(item=self.hemisphere,
-                       flag=wx.ALIGN_LEFT|wx.ALL,
-                       border=5, pos=(6, 2), span=(1, 1))
+        radioSBSizer.Add(item=self.radio1,
+                         flag=wx.ALIGN_LEFT | wx.RIGHT, border=20)
+        radioSBSizer.Add(item=self.radio2,
+                         flag=wx.ALIGN_LEFT)
 
-        self.title_utm.Hide()
-        self.text_utm.Hide()
-        self.label_utm.Hide()
-        self.hemisphere.Hide()
-        self.label_hemisphere.Hide()
-
         # bindings
         self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.radio1.GetId())
         self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.radio2.GetId())
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChange)
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
+        
+    def OnParamEntry(self, event):
+        self.pval[event.GetId() - 2000] = event.GetString()
 
-        # do page layout
-        # self.DoLayout()
-
     def OnPageChange(self,event=None):
-        if event.GetDirection() and self.parent.projpage.proj == 'utm' and self.utmzone == '':
-            wx.MessageBox('You must set a zone for a UTM projection')
-            event.Veto()
-        self.title_utm.Hide()
-        self.text_utm.Hide()
-        self.label_utm.Hide()
-        self.hemisphere.Hide()
-        self.label_hemisphere.Hide()
+        if event.GetDirection():
+            self.p4projparams = ''
+            for num in range(self.pcount + 1):
+                if self.ptype[num] == 'bool':
+                    if self.pval[num] == 'N':
+                        continue
+                    else:
+                        self.p4projparams += (' +' + self.proj4param[num])
+                else:
+                    if self.pval[num] == '':
+                        wx.MessageBox('You must enter a value for %s' % self.pdesc[num],
+                                      'Something is missing!', wx.ICON_ERROR)
+                        event.Veto()
+                    else:
+                        self.p4projparams += (' +' + self.proj4param[num] + '=' + self.pval[num])
 
     def OnEnterPage(self,event):
-        if self.parent.projpage.proj == 'utm':
-            self.title_utm.Show()
-            self.text_utm.Show()
-            self.label_utm.Show()
-            self.hemisphere.Show()
-            self.label_hemisphere.Show()
+        self.projdesc = self.parent.projections[self.parent.projpage.proj][0]
+        try:
+            # page already formatted
+            if self.pagesizer.GetItem(self.panel) != '':
+                pass
+        except:
+            # entering page for the first time
+            paramSBox = wx.StaticBox(parent=self, id=wx.ID_ANY,
+                                   label=_(" Enter parameters for %s projection ") % self.projdesc)
+            paramSBSizer = wx.StaticBoxSizer(paramSBox)
+
+            self.panel = scrolled.ScrolledPanel(self, wx.ID_ANY)
+            self.prjparamsizer = wx.GridBagSizer(vgap=0, hgap=0) 
+
+            self.panel.SetupScrolling()
+
+#            this ought to work but it doesn't
+#            self.sizer.Add(paramSBSizer, pos=(2,1), span=(3,2), 
+#                           flag=wx.EXPAND )
+
+            self.pagesizer.Add(paramSBSizer, proportion=1, 
+                               flag=wx.EXPAND | wx.ALIGN_TOP | wx.ALL, border=10)
+            paramSBSizer.Add(self.panel, proportion=1, 
+                             flag=wx.ALIGN_CENTER|wx.EXPAND)
+
+            paramSBSizer.Fit(self.panel)
+            self.panel.SetSizer(self.prjparamsizer)
+                    
+        if event.GetDirection(): 
+            self.pcount = 0
+            self.prjparamsizer.Clear(True)
+            num = 0
             
-            self.Bind(wx.EVT_CHOICE, self.OnHemisphere, self.hemisphere)
-            self.Bind(wx.EVT_TEXT, self.GetUTM, self.text_utm)
+            for paramgrp in self.parent.projections[self.parent.projpage.proj][1]:
+                
+                # get parameters
+                self.pcount = num
+                self.ptype[num] = self.parent.paramdesc[paramgrp[0]][0]
+                self.proj4param[num] = self.parent.paramdesc[paramgrp[0]][1]
+                self.pdesc[num] = self.parent.paramdesc[paramgrp[0]][2]
 
+                # default values
+                if self.ptype[num] == 'bool': self.pval[num] = 'N'
+                elif self.ptype[num] == 'zone': self.pval[num] = '30' 
+                else: self.pval[num] = paramgrp[2]
+
+                label = wx.StaticText(self.panel, id=1000+num, label=self.pdesc[num], 
+                                      style=wx.ALIGN_RIGHT | wx.ST_NO_AUTORESIZE)
+                if self.ptype[num] == 'bool':
+                    self.pentry[num] = wx.Choice(self.panel, id=2000+num, size=(100,-1), 
+                                                 choices = ['N','Y'])  
+                    self.pentry[num].SetStringSelection(self.pval[num])
+                    self.Bind(wx.EVT_CHOICE, self.OnParamEntry)
+                elif self.ptype[num] == 'zone':
+                    zone = []
+                    for i in range(1, 61):
+                        zone.append(str(i))
+                    self.pentry[num] = wx.Choice(self.panel, id=2000+num, size=(100,-1), 
+                                                 choices = zone)  
+                    self.pentry[num].SetStringSelection(self.pval[num])
+                    self.Bind(wx.EVT_CHOICE, self.OnParamEntry)
+                else:
+                    self.pentry[num] = wx.TextCtrl(self.panel, id=2000+num, value=self.pval[num],
+                                                   size=(100,-1))
+                    self.Bind(wx.EVT_TEXT, self.OnParamEntry)
+                    if paramgrp[1] == 'noask':
+                        self.pentry[num].SetEditable(False)
+
+                self.prjparamsizer.Add(item=label, pos=(num, 1),
+                               flag=wx.ALIGN_RIGHT | wx.RIGHT, border=5)
+                self.prjparamsizer.Add(item=self.pentry[num], pos=(num, 2),
+                               flag=wx.ALIGN_LEFT | wx.LEFT, border=5)                
+                num += 1    
+                
+        self.panel.SetSize(self.panel.GetBestSize())
+        self.panel.Layout()
+        self.Layout()
+        self.Update()
+
+
         if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
             wx.FindWindowById(wx.ID_FORWARD).Enable()
 
@@ -827,45 +903,46 @@
 
     def OnPageChanging(self, event):
         self.proj4params = ''
-        if event.GetDirection() and self.datum not in self.parent.datums:
-            event.Veto()
-        else:
-            # check for datum tranforms            
-            proj4string = self.parent.CreateProj4String() + ' +datum=%s' % self.datum
-            ret = gcmd.RunCommand('g.proj',
-                                  read = True,
-                                  proj4 = proj4string, 
-                                  datumtrans = '-1')
-            
-            if ret != '':
-                dtrans = ''
-                # open a dialog to select datum transform number
-                dlg = SelectTransformDialog(self.parent.parent, transforms=ret)
+        if event.GetDirection():
+            if self.datum not in self.parent.datums:
+                event.Veto()
+            else:
+                # check for datum tranforms            
+                proj4string = self.parent.CreateProj4String() + ' +datum=%s' % self.datum
+                ret = gcmd.RunCommand('g.proj',
+                                      read = True,
+                                      proj4 = proj4string, 
+                                      datumtrans = '-1')
                 
-                if dlg.ShowModal() == wx.ID_OK:
-                    dtrans = dlg.GetTransform()
-                    if dtrans == '':
+                if ret != '':
+                    dtrans = ''
+                    # open a dialog to select datum transform number
+                    dlg = SelectTransformDialog(self.parent.parent, transforms=ret)
+                    
+                    if dlg.ShowModal() == wx.ID_OK:
+                        dtrans = dlg.GetTransform()
+                        if dtrans == '':
+                            dlg.Destroy()
+                            event.Veto()
+                            return 'Datum transform is required.'
+                    else:
                         dlg.Destroy()
                         event.Veto()
                         return 'Datum transform is required.'
-                else:
-                    dlg.Destroy()
-                    event.Veto()
-                    return 'Datum transform is required.'
+                    
+                    self.parent.datumtrans = dtrans
                 
-                self.parent.datumtrans = dtrans
-                
         self.GetNext().SetPrev(self)
-
-        self.GetNext().SetPrev(self)
         self.parent.ellipsepage.ellipseparams = self.parent.ellipsoids[self.ellipsoid][1]
 
     def OnEnterPage(self,event):
-        if len(self.datum) == 0:
-            # disable 'next' button by default
-            wx.FindWindowById(wx.ID_FORWARD).Enable(False)
-        else:
-            wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+        self.parent.datumtrans = 0
+        if event.GetDirection():
+            if len(self.datum) == 0:
+                # disable 'next' button by default when entering from previous page
+                wx.FindWindowById(wx.ID_FORWARD).Enable(False)
+            else:
+                wx.FindWindowById(wx.ID_FORWARD).Enable(True)
 
         event.Skip()
 
@@ -873,14 +950,17 @@
         self.datum = event.GetString().lower()
 
         nextButton = wx.FindWindowById(wx.ID_FORWARD)
-        if len(self.datum) == 0 and nextButton.IsEnabled():
+        if len(self.datum) == 0 or self.datum not in self.parent.datums:
             nextButton.Enable(False)
-        elif self.datum in self.parent.datums:
+        else:
             self.datumdesc = self.parent.datums[self.datum][0]
             self.ellipsoid = self.parent.datums[self.datum][1]
             self.datumparams = self.parent.datums[self.datum][2]
+            for p in self.datumparams:
+                if p in ['dx=0.0','dy=0.0','dz=0.0']: self.datumparams.remove(p)
             nextButton.Enable(True)
             
+        self.Update()    
         event.Skip()
 
     def OnDSearch(self, event):
@@ -892,14 +972,11 @@
 
         event.Skip()
 
-    def OnDatumSelected(self,event):
+    def OnDatumSelected(self, event):
         index = event.m_itemIndex
         item = event.GetItem()
 
         self.datum = self.datumlist.GetItem(index, 0).GetText()
-        self.datumdesc = self.parent.datums[self.datum][0]
-        self.ellipsoid = self.parent.datums[self.datum][1]
-        self.datumparams = self.parent.datums[self.datum][2]
         self.tdatum.SetValue(self.datum)
         
         event.Skip()
@@ -934,6 +1011,7 @@
 
         self.ellipselist = ItemList(self, data=data,
                                     columns=[_('Code'), _('Description')])
+        self.ellipselist.resizeLastColumn(30)                             
 
         # layout
         self.sizer.AddGrowableCol(4)
@@ -968,9 +1046,6 @@
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
 
-        # do page layout
-        # self.DoLayout()
-
     def OnEnterPage(self,event):
         if len(self.ellipse) == 0:
             # disable 'next' button by default
@@ -987,14 +1062,13 @@
         self.proj4params = ''
         self.GetNext().SetPrev(self)
         self.parent.datumpage.datumparams = ''
-        self.parent.datumpage.transparams = ''
         # self.GetNext().SetPrev(self) (???)
 
     def OnText(self, event):
         """!Ellipspoid code changed"""
         self.ellipse = event.GetString()
         nextButton = wx.FindWindowById(wx.ID_FORWARD)
-        if len(self.ellipse) == 0 and nextButton.IsEnabled():
+        if len(self.ellipse) == 0 or self.ellipse not in self.parent.ellipsoids:
             nextButton.Enable(False)
             self.ellipsedesc = ''
             self.ellipseparams = ''
@@ -1002,23 +1076,17 @@
         elif self.ellipse in self.parent.ellipsoids:
             self.ellipsedesc = self.parent.ellipsoids[self.ellipse][0]
             self.ellipseparams = self.parent.ellipsoids[self.ellipse][1]
-            if not nextButton.IsEnabled():
-                nextButton.Enable()
+            nextButton.Enable(True)
 
     def OnSearch(self, event):
         """!Search ellipsoid by desc"""
-        str =  event.GetString()
         try:
             self.ellipse, self.ellipsedesc = \
                 self.ellipselist.Search(index=[0,1], pattern=event.GetString())
             self.ellipseparams = self.parent.ellipsoids[self.ellipse][1]
-            self.proj4params = self.parent.ellipsoids[self.ellipse][2]
         except:
-            self.ellipse = self.ellipsedesc = ''
-            self.ellipseparams = self.proj4params = ''
+            self.ellipse = self.ellipsedesc = self.ellipseparams = ''
 
-        self.tellipse.SetValue(self.ellipse)
-
         event.Skip()
 
     def OnItemSelected(self,event):
@@ -1026,10 +1094,9 @@
         item = event.GetItem()
 
         self.ellipse = self.ellipselist.GetItem(index, 0).GetText()
-        self.ellipsedesc = self.parent.ellipsoids[self.ellipse][0]
-        self.ellipseparams = self.parent.ellipsoids[self.ellipse][1]
-
         self.tellipse.SetValue(self.ellipse)
+        
+        event.Skip()
 
 class GeoreferencedFilePage(TitledPage):
     """
@@ -1141,9 +1208,6 @@
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
 
-        # do page layout
-        # self.DoLayout()
-
     def OnEnterPage(self, event):
         if len(self.wktfile) == 0:
             # disable 'next' button by default
@@ -1284,15 +1348,14 @@
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
 
-        # do page layout
-        # self.DoLayout()
-
     def OnEnterPage(self, event):
-        if not self.epsgcode:
-            # disable 'next' button by default
-            wx.FindWindowById(wx.ID_FORWARD).Enable(False)
-        else:
-            wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+        self.parent.datumtrans = 0
+        if event.GetDirection():
+            if not self.epsgcode:
+                # disable 'next' button by default
+                wx.FindWindowById(wx.ID_FORWARD).Enable(False)
+            else:
+                wx.FindWindowById(wx.ID_FORWARD).Enable(True)
 
         # load default epsg database file
         self.OnBrowseCodes(None)
@@ -1444,9 +1507,6 @@
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
         self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
 
-        # do page layout
-        # self.DoLayout()
-
     def OnEnterPage(self, event):
         if len(self.customstring) == 0:
             # disable 'next' button by default
@@ -1557,13 +1617,6 @@
         self.sizer.Add(item=(10,20),
                        flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
                        border=5, pos=(5, 0), span=(1, 2))
-        # self.sizer.AddGrowableRow(6)
-        #self.sizer.Add(item=self.MakeLabel(_("You can set the default extents "
-        #                                     "and resolution after creating new location%s"
-        #                                     "or you can set them during a working session.") % os.linesep,
-        #                                   style=wx.ALIGN_CENTER),
-        #               flag=wx.ALIGN_CENTRE | wx.ALL, border=5, pos=(6, 0),
-        #               span=(1, 2))
 
     def OnEnterPage(self,event):
         """
@@ -1572,7 +1625,10 @@
 
         database = self.parent.startpage.grassdatabase
         location = self.parent.startpage.location
-
+        proj4string = self.parent.CreateProj4String()
+        epsgcode = self.parent.epsgpage.epsgcode
+        dtrans = self.parent.datumtrans
+        
         global coordsys
         if coordsys not in ['proj', 'epsg']:
             self.lproj4stringLabel.Hide()
@@ -1583,25 +1639,39 @@
             self.lproj4string.Show()
             self.lproj4stringLabel.SetLabel(_("PROJ.4 definition:"))
             if coordsys == 'proj':
-                self.lproj4string.SetLabel(self.parent.CreateProj4String())
+                ret, msg, err = gcmd.RunCommand('g.proj',
+                                       flags = 'j',
+                                       proj4 = proj4string,
+                                       datumtrans = dtrans,
+                                       location = location,
+                                       getErrorMsg = True,
+                                       read = True)
+            elif coordsys == 'epsg':
+                ret, msg, err = gcmd.RunCommand('g.proj',
+                                       flags = 'j',
+                                       epsg = epsgcode,
+                                       datumtrans = dtrans,
+                                       location = location,
+                                       getErrorMsg = True,
+                                       read = True)
+            
+            if ret == 0:
+                projlabel = ''
+                for line in msg.splitlines():
+                    projlabel = projlabel + '%s ' % line
+                self.lproj4string.SetLabel(projlabel)
             else:
-                self.lproj4string.SetLabel(self.parent.epsgpage.epsgCodeDict[self.parent.epsgpage.epsgcode][1])
+                wx.MessageBox(err, 'Error', wx.ICON_ERROR)
+
             self.lproj4string.Wrap(400)
             
-        projection = self.parent.projpage.proj
         projdesc = self.parent.projpage.projdesc
-        utmzone = self.parent.projtypepage.utmzone
-        utmhemisphere = self.parent.projtypepage.utmhemisphere
-        ellipse = self.parent.ellipsepage.ellipse
         ellipsedesc = self.parent.ellipsepage.ellipsedesc
-        datum = self.parent.datumpage.datum
         datumdesc = self.parent.datumpage.datumdesc
-        ellipsoid = self.parent.datumpage.ellipsoid
-        datumparams = self.parent.datumpage.datumparams
-
         self.ldatabase.SetLabel(str(database))
         self.llocation.SetLabel(str(location))
         label = ''
+        
         if coordsys == 'epsg':
             label = 'EPSG code %s (%s)' % (self.parent.epsgpage.epsgcode, self.parent.epsgpage.epsgdesc)
             self.lprojection.SetLabel(label)
@@ -1612,7 +1682,7 @@
             label = 'matches file %s' % self.parent.wktpage.wktfile
             self.lprojection.SetLabel(label)
         elif coordsys == 'proj':
-            label = ('%s, %s%s' % (projdesc, datumdesc, ellipsedesc))
+            label = ('%s, %s %s' % (projdesc, datumdesc, ellipsedesc))
             self.lprojection.SetLabel(label)
         elif coordsys == 'xy':
             label = ('XY coordinate system (not projected).')
@@ -1661,6 +1731,7 @@
         # datum transform number and list of datum transforms
         #
         self.datumtrans = 0
+        self.proj4string = ''
 
         #
         # define wizard pages
@@ -1671,7 +1742,7 @@
         self.csystemspage = CoordinateSystemPage(self.wizard, self)
         self.projpage = ProjectionsPage(self.wizard, self)
         self.datumpage = DatumPage(self.wizard, self)
-        self.projtypepage = ProjTypePage(self.wizard,self)
+        self.paramspage = ProjParamsPage(self.wizard,self)
         self.epsgpage = EPSGPage(self.wizard, self)
         self.filepage = GeoreferencedFilePage(self.wizard, self)
         self.wktpage = WKTPage(self.wizard, self)
@@ -1689,15 +1760,15 @@
         self.csystemspage.SetNext(self.sumpage)
 
         self.projpage.SetPrev(self.csystemspage)
-        self.projpage.SetNext(self.projtypepage)
+        self.projpage.SetNext(self.paramspage)
 
-        self.projtypepage.SetPrev(self.projpage)
-        self.projtypepage.SetNext(self.datumpage)
+        self.paramspage.SetPrev(self.projpage)
+        self.paramspage.SetNext(self.datumpage)
 
-        self.datumpage.SetPrev(self.projtypepage)
+        self.datumpage.SetPrev(self.paramspage)
         self.datumpage.SetNext(self.sumpage)
 
-        self.ellipsepage.SetPrev(self.projtypepage)
+        self.ellipsepage.SetPrev(self.paramspage)
         self.ellipsepage.SetNext(self.sumpage)
 
         self.epsgpage.SetPrev(self.csystemspage)
@@ -1721,7 +1792,7 @@
         self.csystemspage.DoLayout()
         self.projpage.DoLayout()
         self.datumpage.DoLayout()
-        self.projtypepage.DoLayout()
+        self.paramspage.DoLayout()
         self.epsgpage.DoLayout()
         self.filepage.DoLayout()
         self.wktpage.DoLayout()
@@ -1778,16 +1849,27 @@
     
     def __readData(self):
         """!Get georeferencing information from tables in $GISBASE/etc"""
-        # read projection definitions
-        f = open(os.path.join(globalvar.ETCDIR, "projections"), "r")
+
+        # read projection and parameters
+        f = open(os.path.join(globalvar.ETCDIR, "proj-parms.table"), "r")
         self.projections = {}
+        self.projdesc = {}
         for line in f.readlines():
-            line = line.expandtabs(1)
             line = line.strip()
-            if line == '' or line[0] == "#":
+            try:
+                proj, projdesc, params = line.split(':')
+                paramslist = params.split(';')
+                plist = []
+                for p in paramslist:
+                    if p == '': continue
+                    p1, pdefault = p.split(',')
+                    pterm, pask = p1.split('=')
+                    p = [pterm.strip(), pask.strip(), pdefault.strip()]
+                    plist.append(p)
+                self.projections[proj.lower().strip()] = (projdesc.strip(), plist)
+                self.projdesc[proj.lower().strip()] = projdesc.strip()
+            except:
                 continue
-            proj, projdesc = line.split(":", 1)
-            self.projections[proj.strip()] = projdesc.strip()
         f.close()
 
         # read datum definitions
@@ -1808,34 +1890,6 @@
             self.datums[datum] = (datumdesc.replace('_', ' '), ellipsoid, paramlist)
         f.close()
 
-        # read datum transforms parameters
-        f = open(os.path.join(globalvar.ETCDIR, "datumtransform.table"), "r")
-        self.transforms = {}
-        j = 1
-        for line in f.readlines():
-            if j < 10:
-                transcode = 'T0' + str(j)
-            else:
-               transcode = 'T' + str(j)
-            line = line.expandtabs(1)
-            line = line.strip()
-            if line == '' or line[0] == "#":
-                continue
-            datum, rest = line.split(" ", 1)
-            rest = rest.strip('" ')
-            params, rest = rest.split('"', 1)
-            params = params.strip()
-            rest = rest.strip('" ')
-            try:
-                region, info = rest.split('"', 1)
-                info = info.strip('" ')
-                info = region + ': ' + info
-            except:
-                info = rest
-            self.transforms[transcode] = (datum, info, params)
-            j += 1
-        f.close()
-
         # read ellipsiod definitions
         f = open(os.path.join(globalvar.ETCDIR, "ellipse.table"), "r")
         self.ellipsoids = {}
@@ -1851,6 +1905,18 @@
             paramslist = params.split()
             self.ellipsoids[ellipse] = (desc, paramslist)
         f.close()
+        
+        # read projection parameter description and parsing table
+        f = open(os.path.join(globalvar.ETCDIR, "proj-desc.table"), "r")
+        self.paramdesc = {}
+        for line in f.readlines():
+            line = line.strip()
+            try:
+                pparam, datatype, proj4term, desc = line.split(':')
+                self.paramdesc[pparam] = (datatype, proj4term, desc)
+            except:
+                continue
+        f.close()
 
     def OnWizFinished(self):
         database = self.startpage.grassdatabase
@@ -1965,19 +2031,16 @@
     def CreateProj4String(self):
         """!Constract PROJ.4 string"""
         location = self.startpage.location
-        proj = self.projpage.proj
+        proj = self.projpage.p4proj
         projdesc = self.projpage.projdesc
-        
-        utmzone = self.projtypepage.utmzone
-        utmhemisphere = self.projtypepage.utmhemisphere
-        
+        proj4params = self.paramspage.p4projparams
+                
         datum = self.datumpage.datum
         if self.datumpage.datumdesc:
             datumdesc = self.datumpage.datumdesc +' - ' + self.datumpage.ellipsoid
         else:
             datumdesc = ''
-        datumparams = self.datumpage.datumparams
-        
+        datumparams = self.datumpage.datumparams        
         ellipse = self.ellipsepage.ellipse
         ellipsedesc = self.ellipsepage.ellipsedesc
         ellipseparams = self.ellipsepage.ellipseparams
@@ -1985,34 +2048,24 @@
         #
         # creating PROJ.4 string
         #
-        if proj == 'll':
-            proj4string = '+proj=longlat'
-        elif proj == 'utm':
-            proj4string = '+proj=%s +zone=%s' % (proj, utmzone)
-            if utmhemisphere == 'south':
-                proj4string += ' +south'
-        else:
-            proj4string = '+proj=%s ' % (proj)
-            
-        self.shortproj4string = proj4string
+        proj4string = '%s %s' % (proj, proj4params)
                             
-        proj4params = ''
         # set ellipsoid parameters
         for item in ellipseparams:
             if item[:4] == 'f=1/':
                 item = '+rf='+item[4:]
             else:
                 item = '+'+item
-            proj4params = '%s %s' % (proj4params, item)
+            proj4string = '%s %s' % (proj4string, item)
         # set datum and transform parameters if relevant
         if datumparams:
             for item in datumparams:
-                proj4params = '%s +%s' % (proj4params,item)
+                proj4string = '%s +%s' % (proj4string,item)
 
-        proj4params = '%s +no_defs' % proj4params
-
-        return '%s %s' % (proj4string, proj4params)
+        proj4string = '%s +no_defs' % proj4string
         
+        return proj4string
+        
     def Proj4Create(self, proj4string):
         """!Create a new location for selected projection
         
@@ -2691,7 +2744,6 @@
 
         sizer.Fit(panel)
 
-
         self.SetSize(self.GetBestSize())
         self.Layout()
         



More information about the grass-commit mailing list