r.li.setup.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. """
  2. MODULE: r_li_setup_GUI.py
  3. AUTHOR(S): Anne Ghisla <a.ghisla AT gmail.com>
  4. PURPOSE: Dedicated GUI for r.li.setup, translated and reshaped from original TclTk.
  5. DEPENDS: []
  6. COPYRIGHT: (C) 2010 by the GRASS Development Team
  7. This program is free software under the GNU General Public
  8. License (>=v2). Read the file COPYING that comes with GRASS
  9. for details.
  10. """
  11. # bulk import from location_wizard.py.
  12. import os
  13. import shutil
  14. import re
  15. import string
  16. import sys
  17. import locale
  18. import platform
  19. GUIModulesPath = os.path.join(os.getenv("GISBASE"), "etc", "gui", "wxpython", "gui_modules")
  20. sys.path.append(GUIModulesPath)
  21. import globalvar
  22. import wx
  23. import wx.lib.mixins.listctrl as listmix
  24. import wx.wizard as wiz
  25. import wx.lib.scrolledpanel as scrolled
  26. import time
  27. import gcmd
  28. import utils
  29. from grass.script import core as grass
  30. #@TODO create wizard instead of progressively increasing window
  31. print >> sys.stderr, "TODO: implement r.li.setup wizard..."
  32. class BaseClass(wx.Object):
  33. """!Base class providing basic methods"""
  34. def __init__(self):
  35. pass
  36. def MakeLabel(self, text="", style=wx.ALIGN_LEFT, parent=None):
  37. """!Make aligned label"""
  38. if not parent:
  39. parent = self
  40. return wx.StaticText(parent=parent, id=wx.ID_ANY, label=text,
  41. style=style)
  42. def MakeTextCtrl(self, text='', size=(100,-1), style=0, parent=None):
  43. """!Generic text control"""
  44. if not parent:
  45. parent = self
  46. return wx.TextCtrl(parent=parent, id=wx.ID_ANY, value=text,
  47. size=size, style=style)
  48. def MakeButton(self, text, id=wx.ID_ANY, size=(-1,-1), parent=None):
  49. """!Generic button"""
  50. if not parent:
  51. parent = self
  52. return wx.Button(parent=parent, id=id, label=text,
  53. size=size)
  54. class TitledPage(BaseClass, wiz.WizardPageSimple):
  55. """
  56. Class to make wizard pages. Generic methods to make
  57. labels, text entries, and buttons.
  58. """
  59. def __init__(self, parent, title):
  60. self.page = wiz.WizardPageSimple.__init__(self, parent)
  61. # page title
  62. self.title = wx.StaticText(parent=self, id=wx.ID_ANY, label=title)
  63. self.title.SetFont(wx.Font(13, wx.SWISS, wx.NORMAL, wx.BOLD))
  64. # main sizers
  65. self.pagesizer = wx.BoxSizer(wx.VERTICAL)
  66. self.sizer = wx.GridBagSizer(vgap=0, hgap=0)
  67. def DoLayout(self):
  68. """!Do page layout"""
  69. self.pagesizer.Add(item=self.title, proportion=0,
  70. flag=wx.ALIGN_CENTRE | wx.ALL,
  71. border=5)
  72. self.pagesizer.Add(item=wx.StaticLine(self, -1), proportion=0,
  73. flag=wx.EXPAND | wx.ALL,
  74. border=0)
  75. self.pagesizer.Add(item=self.sizer)
  76. self.SetAutoLayout(True)
  77. self.SetSizer(self.pagesizer)
  78. # tmpsizer.Fit(self)
  79. self.Layout()
  80. class LocationWizard(wx.Object):
  81. """
  82. Start wizard here and finish wizard here
  83. """
  84. def __init__(self, parent):
  85. # global coordsys
  86. self.parent = parent
  87. #
  88. # define wizard image
  89. #
  90. # file = "loc_wizard.png"
  91. file = "loc_wizard_qgis.png"
  92. imagePath = os.path.join(globalvar.ETCWXDIR, "images", file)
  93. wizbmp = wx.Image(imagePath, wx.BITMAP_TYPE_PNG)
  94. # wizbmp.Rescale(250,600)
  95. wizbmp = wizbmp.ConvertToBitmap()
  96. #
  97. # get georeferencing information from tables in $GISBASE/etc
  98. #
  99. # self.__readData()
  100. #
  101. # #
  102. # # datum transform number and list of datum transforms
  103. # #
  104. # self.datumtrans = 0
  105. # self.proj4string = ''
  106. #
  107. # #
  108. # # define wizard pages
  109. # #
  110. self.wizard = wiz.Wizard(parent, id=wx.ID_ANY, title=_("I m!"),
  111. bitmap=wizbmp)
  112. self.startpage = SummaryPage(self.wizard, self)
  113. # self.csystemspage = CoordinateSystemPage(self.wizard, self)
  114. # self.projpage = ProjectionsPage(self.wizard, self)
  115. # self.datumpage = DatumPage(self.wizard, self)
  116. # self.paramspage = ProjParamsPage(self.wizard,self)
  117. # self.epsgpage = EPSGPage(self.wizard, self)
  118. # self.filepage = GeoreferencedFilePage(self.wizard, self)
  119. # self.wktpage = WKTPage(self.wizard, self)
  120. # self.ellipsepage = EllipsePage(self.wizard, self)
  121. # self.custompage = CustomPage(self.wizard, self)
  122. # self.sumpage = SummaryPage(self.wizard, self)
  123. #
  124. # #
  125. # # set the initial order of the pages
  126. # # (should follow the epsg line)
  127. # #
  128. # self.startpage.SetNext(self.csystemspage)
  129. #
  130. # self.csystemspage.SetPrev(self.startpage)
  131. # self.csystemspage.SetNext(self.sumpage)
  132. #
  133. # self.projpage.SetPrev(self.csystemspage)
  134. # self.projpage.SetNext(self.paramspage)
  135. #
  136. # self.paramspage.SetPrev(self.projpage)
  137. # self.paramspage.SetNext(self.datumpage)
  138. #
  139. # self.datumpage.SetPrev(self.paramspage)
  140. # self.datumpage.SetNext(self.sumpage)
  141. #
  142. # self.ellipsepage.SetPrev(self.paramspage)
  143. # self.ellipsepage.SetNext(self.sumpage)
  144. #
  145. # self.epsgpage.SetPrev(self.csystemspage)
  146. # self.epsgpage.SetNext(self.sumpage)
  147. #
  148. # self.filepage.SetPrev(self.csystemspage)
  149. # self.filepage.SetNext(self.sumpage)
  150. #
  151. # self.wktpage.SetPrev(self.csystemspage)
  152. # self.wktpage.SetNext(self.sumpage)
  153. #
  154. # self.custompage.SetPrev(self.csystemspage)
  155. # self.custompage.SetNext(self.sumpage)
  156. #
  157. # self.sumpage.SetPrev(self.csystemspage)
  158. #
  159. # #
  160. # # do pages layout
  161. # #
  162. # self.startpage.DoLayout()
  163. # self.csystemspage.DoLayout()
  164. # self.projpage.DoLayout()
  165. # self.datumpage.DoLayout()
  166. # self.paramspage.DoLayout()
  167. # self.epsgpage.DoLayout()
  168. # self.filepage.DoLayout()
  169. # self.wktpage.DoLayout()
  170. # self.ellipsepage.DoLayout()
  171. # self.custompage.DoLayout()
  172. # self.sumpage.DoLayout()
  173. # self.wizard.FitToPage(self.datumpage)
  174. #
  175. # # new location created?
  176. # self.location = None
  177. # success = False
  178. #
  179. # # location created in different GIS database?
  180. # self.altdb = False
  181. #
  182. # run wizard...
  183. #
  184. if self.wizard.RunWizard(self.startpage):
  185. pass
  186. # msg = self.OnWizFinished()
  187. # if len(msg) < 1:
  188. # self.wizard.Destroy()
  189. # self.location = self.startpage.location
  190. #
  191. # if self.altdb == False:
  192. # dlg = wx.MessageDialog(parent=self.parent,
  193. # message=_("Do you want to set the default "
  194. # "region extents and resolution now?"),
  195. # caption=_("Location <%s> created") % self.location,
  196. # style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  197. # dlg.CenterOnScreen()
  198. # if dlg.ShowModal() == wx.ID_YES:
  199. # dlg.Destroy()
  200. # defineRegion = RegionDef(self.parent, location=self.location)
  201. # defineRegion.CenterOnScreen()
  202. # defineRegion.Show()
  203. # else:
  204. # dlg.Destroy()
  205. # else: # -> error
  206. # self.wizard.Destroy()
  207. # wx.MessageBox(parent=self.parent,
  208. # message="%s" % _("Unable to create new location. "
  209. # "Location <%(loc)s> not created.\n\n"
  210. # "Details: %(err)s") % \
  211. # { 'loc' : self.startpage.location,
  212. # 'err' : msg },
  213. # caption=_("Location wizard"),
  214. # style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  215. # else:
  216. # win = wx.MessageBox(parent=self.parent,
  217. # message=_("Location wizard canceled. "
  218. # "Location not created."),
  219. # caption=_("Location wizard"))
  220. def __readData(self):
  221. """!Get georeferencing information from tables in $GISBASE/etc"""
  222. # read projection and parameters
  223. f = open(os.path.join(globalvar.ETCDIR, "proj-parms.table"), "r")
  224. self.projections = {}
  225. self.projdesc = {}
  226. for line in f.readlines():
  227. line = line.strip()
  228. try:
  229. proj, projdesc, params = line.split(':')
  230. paramslist = params.split(';')
  231. plist = []
  232. for p in paramslist:
  233. if p == '': continue
  234. p1, pdefault = p.split(',')
  235. pterm, pask = p1.split('=')
  236. p = [pterm.strip(), pask.strip(), pdefault.strip()]
  237. plist.append(p)
  238. self.projections[proj.lower().strip()] = (projdesc.strip(), plist)
  239. self.projdesc[proj.lower().strip()] = projdesc.strip()
  240. except:
  241. continue
  242. f.close()
  243. # read datum definitions
  244. f = open(os.path.join(globalvar.ETCDIR, "datum.table"), "r")
  245. self.datums = {}
  246. paramslist = []
  247. for line in f.readlines():
  248. line = line.expandtabs(1)
  249. line = line.strip()
  250. if line == '' or line[0] == "#":
  251. continue
  252. datum, info = line.split(" ", 1)
  253. info = info.strip()
  254. datumdesc, params = info.split(" ", 1)
  255. datumdesc = datumdesc.strip('"')
  256. paramlist = params.split()
  257. ellipsoid = paramlist.pop(0)
  258. self.datums[datum] = (ellipsoid, datumdesc.replace('_', ' '), paramlist)
  259. f.close()
  260. # read ellipsiod definitions
  261. f = open(os.path.join(globalvar.ETCDIR, "ellipse.table"), "r")
  262. self.ellipsoids = {}
  263. for line in f.readlines():
  264. line = line.expandtabs(1)
  265. line = line.strip()
  266. if line == '' or line[0] == "#":
  267. continue
  268. ellipse, rest = line.split(" ", 1)
  269. rest = rest.strip('" ')
  270. desc, params = rest.split('"', 1)
  271. desc = desc.strip('" ')
  272. paramslist = params.split()
  273. self.ellipsoids[ellipse] = (desc, paramslist)
  274. f.close()
  275. # read projection parameter description and parsing table
  276. f = open(os.path.join(globalvar.ETCDIR, "proj-desc.table"), "r")
  277. self.paramdesc = {}
  278. for line in f.readlines():
  279. line = line.strip()
  280. try:
  281. pparam, datatype, proj4term, desc = line.split(':')
  282. self.paramdesc[pparam] = (datatype, proj4term, desc)
  283. except:
  284. continue
  285. f.close()
  286. def OnWizFinished(self):
  287. database = self.startpage.grassdatabase
  288. location = self.startpage.location
  289. global coordsys
  290. msg = '' # error message (empty on success)
  291. # location already exists?
  292. if os.path.isdir(os.path.join(database,location)):
  293. dlg = wx.MessageDialog(parent=self.wizard,
  294. message="%s <%s>: %s" % \
  295. (_("Unable to create new location"),
  296. os.path.join(database, location),
  297. _("Location already exists in GRASS Database.")),
  298. caption=_("Error"),
  299. style=wx.OK | wx.ICON_ERROR)
  300. dlg.ShowModal()
  301. dlg.Destroy()
  302. return False
  303. # current GISDbase or a new one?
  304. current_gdb = grass.gisenv()['GISDBASE']
  305. if current_gdb != database:
  306. # change to new GISDbase or create new one
  307. if os.path.isdir(database) != True:
  308. # create new directory
  309. os.mkdir(database)
  310. # change to new GISDbase directory
  311. gcmd.RunCommand('g.gisenv',
  312. parent = self.wizard,
  313. set='GISDBASE=%s' % database)
  314. wx.MessageBox(parent=self.wizard,
  315. message=_("Location <%(loc)s> will be created "
  316. "in GIS data directory <%(dir)s>."
  317. "You will need to change the default GIS "
  318. "data directory in the GRASS startup screen.") % \
  319. { 'loc' : location, 'dir' : database},
  320. caption=_("New GIS data directory"),
  321. style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
  322. # location created in alternate GISDbase
  323. self.altdb = True
  324. if coordsys == "xy":
  325. msg = self.XYCreate()
  326. elif coordsys == "proj":
  327. proj4string = self.CreateProj4String()
  328. msg = self.Proj4Create(proj4string)
  329. elif coordsys == 'custom':
  330. msg = self.CustomCreate()
  331. elif coordsys == "epsg":
  332. msg = self.EPSGCreate()
  333. elif coordsys == "file":
  334. msg = self.FileCreate()
  335. elif coordsys == "wkt":
  336. msg = self.WKTCreate()
  337. return msg
  338. def XYCreate(self):
  339. """!Create an XY location
  340. @return error message (empty string on success)
  341. """
  342. database = self.startpage.grassdatabase
  343. location = self.startpage.location
  344. # create location directory and PERMANENT mapset
  345. try:
  346. os.mkdir(os.path.join(database, location))
  347. os.mkdir(os.path.join(database, location, 'PERMANENT'))
  348. # create DEFAULT_WIND and WIND files
  349. regioninfo = ['proj: 0',
  350. 'zone: 0',
  351. 'north: 1',
  352. 'south: 0',
  353. 'east: 1',
  354. 'west: 0',
  355. 'cols: 1',
  356. 'rows: 1',
  357. 'e-w resol: 1',
  358. 'n-s resol: 1',
  359. 'top: 1',
  360. 'bottom: 0',
  361. 'cols3: 1',
  362. 'rows3: 1',
  363. 'depths: 1',
  364. 'e-w resol3: 1',
  365. 'n-s resol3: 1',
  366. 't-b resol: 1']
  367. defwind = open(os.path.join(database, location,
  368. "PERMANENT", "DEFAULT_WIND"), 'w')
  369. for param in regioninfo:
  370. defwind.write(param + '%s' % os.linesep)
  371. defwind.close()
  372. shutil.copy(os.path.join(database, location, "PERMANENT", "DEFAULT_WIND"),
  373. os.path.join(database, location, "PERMANENT", "WIND"))
  374. # create MYNAME file
  375. myname = open(os.path.join(database, location, "PERMANENT",
  376. "MYNAME"), 'w')
  377. myname.write('%s' % os.linesep)
  378. myname.close()
  379. except OSError, e:
  380. return e
  381. return ''
  382. def CreateProj4String(self):
  383. """!Constract PROJ.4 string"""
  384. location = self.startpage.location
  385. proj = self.projpage.p4proj
  386. projdesc = self.projpage.projdesc
  387. proj4params = self.paramspage.p4projparams
  388. datum = self.datumpage.datum
  389. if self.datumpage.datumdesc:
  390. datumdesc = self.datumpage.datumdesc +' - ' + self.datumpage.ellipse
  391. else:
  392. datumdesc = ''
  393. datumparams = self.datumpage.datumparams
  394. ellipse = self.ellipsepage.ellipse
  395. ellipsedesc = self.ellipsepage.ellipsedesc
  396. ellipseparams = self.ellipsepage.ellipseparams
  397. #
  398. # creating PROJ.4 string
  399. #
  400. proj4string = '%s %s' % (proj, proj4params)
  401. # set ellipsoid parameters
  402. if ellipse != '': proj4string = '%s +ellps=%s' % (proj4string, ellipse)
  403. for item in ellipseparams:
  404. if item[:4] == 'f=1/':
  405. item = ' +rf='+item[4:]
  406. else:
  407. item = ' +'+item
  408. proj4string = '%s %s' % (proj4string, item)
  409. # set datum and transform parameters if relevant
  410. if datum != '': proj4string = '%s +datum=%s' % (proj4string, datum)
  411. if datumparams:
  412. for item in datumparams:
  413. proj4string = '%s +%s' % (proj4string,item)
  414. proj4string = '%s +no_defs' % proj4string
  415. return proj4string
  416. def Proj4Create(self, proj4string):
  417. """!Create a new location for selected projection
  418. @return error message (empty string on success)
  419. """
  420. ret, msg = gcmd.RunCommand('g.proj',
  421. flags = 'c',
  422. proj4 = proj4string,
  423. location = self.startpage.location,
  424. datumtrans = self.datumtrans,
  425. getErrorMsg = True)
  426. if ret == 0:
  427. return ''
  428. return msg
  429. def CustomCreate(self):
  430. """!Create a new location based on given proj4 string
  431. @return error message (empty string on success)
  432. """
  433. proj4string = self.custompage.customstring
  434. location = self.startpage.location
  435. ret, msg = gcmd.RunCommand('g.proj',
  436. flags = 'c',
  437. proj4 = proj4string,
  438. location = location,
  439. getErrorMsg = True)
  440. if ret == 0:
  441. return ''
  442. return msg
  443. def EPSGCreate(self):
  444. """!Create a new location from an EPSG code.
  445. @return error message (empty string on success)
  446. """
  447. epsgcode = self.epsgpage.epsgcode
  448. epsgdesc = self.epsgpage.epsgdesc
  449. location = self.startpage.location
  450. # should not happend
  451. if epsgcode == '':
  452. return _('EPSG code missing.')
  453. ret, msg = gcmd.RunCommand('g.proj',
  454. flags = 'c',
  455. epsg = epsgcode,
  456. location = location,
  457. datumtrans = self.datumtrans,
  458. getErrorMsg = True)
  459. if ret == 0:
  460. return ''
  461. return msg
  462. def FileCreate(self):
  463. """!Create a new location from a georeferenced file
  464. @return error message (empty string on success)
  465. """
  466. georeffile = self.filepage.georeffile
  467. location = self.startpage.location
  468. # this should not happen
  469. if not georeffile or not os.path.isfile(georeffile):
  470. return _("File not found.")
  471. # creating location
  472. ret, msg = gcmd.RunCommand('g.proj',
  473. flags = 'c',
  474. georef = georeffile,
  475. location = location,
  476. getErrorMsg = True)
  477. if ret == 0:
  478. return ''
  479. return msg
  480. def WKTCreate(self):
  481. """!Create a new location from a WKT file
  482. @return error message (empty string on success)
  483. """
  484. wktfile = self.wktpage.wktfile
  485. location = self.startpage.location
  486. # this should not happen
  487. if not wktfile or not os.path.isfile(wktfile):
  488. return _("File not found.")
  489. # creating location
  490. ret, msg = gcmd.RunCommand('g.proj',
  491. flags = 'c',
  492. wkt = wktfile,
  493. location = location,
  494. getErrorMsg = True)
  495. if ret == 0:
  496. return ''
  497. return msg
  498. class SummaryPage(TitledPage):
  499. """
  500. Shows summary result of choosing coordinate system parameters
  501. prior to creating location
  502. """
  503. def __init__(self, wizard, parent):
  504. TitledPage.__init__(self, wizard, _("Summary"))
  505. self.parent = parent
  506. # labels
  507. self.ldatabase = self.MakeLabel("")
  508. self.llocation = self.MakeLabel("")
  509. self.lprojection = self.MakeLabel("")
  510. self.lproj4string = self.MakeLabel("")
  511. self.lproj4stringLabel = self.MakeLabel("")
  512. self.lprojection.Wrap(400)
  513. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  514. # self.Bind(wx.EVT_BUTTON, self.OnFinish, wx.ID_FINISH)
  515. # do sub-page layout
  516. self.__DoLayout()
  517. def __DoLayout(self):
  518. """!Do page layout"""
  519. self.sizer.AddGrowableCol(1)
  520. self.sizer.Add(item=self.MakeLabel(_("GRASS Database:")),
  521. flag=wx.ALIGN_LEFT | wx.ALL,
  522. border=5, pos=(1, 0))
  523. self.sizer.Add(item=self.ldatabase,
  524. flag=wx.ALIGN_LEFT | wx.ALL,
  525. border=5, pos=(1, 1))
  526. self.sizer.Add(item=self.MakeLabel(_("Location Name:")),
  527. flag=wx.ALIGN_LEFT | wx.ALL,
  528. border=5, pos=(2, 0))
  529. self.sizer.Add(item=self.llocation,
  530. flag=wx.ALIGN_LEFT | wx.ALL,
  531. border=5, pos=(2, 1))
  532. self.sizer.Add(item=self.MakeLabel(_("Projection:")),
  533. flag=wx.ALIGN_LEFT | wx.ALL,
  534. border=5, pos=(3, 0))
  535. self.sizer.Add(item=self.lprojection,
  536. flag=wx.ALIGN_LEFT | wx.ALL,
  537. border=5, pos=(3, 1))
  538. self.sizer.Add(item=self.lproj4stringLabel,
  539. flag=wx.ALIGN_LEFT | wx.ALL,
  540. border=5, pos=(4, 0))
  541. self.sizer.Add(item=self.lproj4string,
  542. flag=wx.ALIGN_LEFT | wx.ALL,
  543. border=5, pos=(4, 1))
  544. self.sizer.Add(item=(10,20),
  545. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
  546. border=5, pos=(5, 0), span=(1, 2))
  547. def OnEnterPage(self,event):
  548. """
  549. Insert values into text controls for summary of location creation options
  550. """
  551. # database = self.parent.startpage.grassdatabase
  552. # location = self.parent.startpage.location
  553. proj4string = self.parent.CreateProj4String()
  554. epsgcode = self.parent.epsgpage.epsgcode
  555. dtrans = self.parent.datumtrans
  556. global coordsys
  557. if coordsys not in ['proj', 'epsg']:
  558. self.lproj4stringLabel.Hide()
  559. self.lproj4string.Hide()
  560. self.lproj4stringLabel.SetLabel('')
  561. self.lproj4string.SetLabel('')
  562. else:
  563. self.lproj4string.Show()
  564. self.lproj4stringLabel.SetLabel(_("PROJ.4 definition:"))
  565. if coordsys == 'proj':
  566. ret, msg, err = gcmd.RunCommand('g.proj',
  567. flags = 'j',
  568. proj4 = proj4string,
  569. datumtrans = dtrans,
  570. location = location,
  571. getErrorMsg = True,
  572. read = True)
  573. elif coordsys == 'epsg':
  574. ret, msg, err = gcmd.RunCommand('g.proj',
  575. flags = 'j',
  576. epsg = epsgcode,
  577. datumtrans = dtrans,
  578. location = location,
  579. getErrorMsg = True,
  580. read = True)
  581. if ret == 0:
  582. projlabel = ''
  583. for line in msg.splitlines():
  584. projlabel = projlabel + '%s ' % line
  585. self.lproj4string.SetLabel(projlabel)
  586. else:
  587. wx.MessageBox(err, 'Error', wx.ICON_ERROR)
  588. self.lproj4string.Wrap(400)
  589. projdesc = self.parent.projpage.projdesc
  590. ellipsedesc = self.parent.ellipsepage.ellipsedesc
  591. datumdesc = self.parent.datumpage.datumdesc
  592. # self.ldatabase.SetLabel(database)
  593. # self.llocation.SetLabel(location)
  594. label = ''
  595. if coordsys == 'epsg':
  596. label = 'EPSG code %s (%s)' % (self.parent.epsgpage.epsgcode, self.parent.epsgpage.epsgdesc)
  597. self.lprojection.SetLabel(label)
  598. elif coordsys == 'file':
  599. label = 'matches file %s' % self.parent.filepage.georeffile
  600. self.lprojection.SetLabel(label)
  601. elif coordsys == 'wkt':
  602. label = 'matches file %s' % self.parent.wktpage.wktfile
  603. self.lprojection.SetLabel(label)
  604. elif coordsys == 'proj':
  605. label = ('%s, %s %s' % (projdesc, datumdesc, ellipsedesc))
  606. self.lprojection.SetLabel(label)
  607. elif coordsys == 'xy':
  608. label = ('XY coordinate system (not projected).')
  609. self.lprojection.SetLabel(label)
  610. elif coordsys == 'custom':
  611. label = ('%s' % self.parent.custompage.customstring)
  612. self.lprojection.SetLabel(label)
  613. def OnFinish(self, event):
  614. dlg = wx.MessageDialog(parent=self.wizard,
  615. message=_("Do you want to create GRASS location <%s>?") % location,
  616. caption=_("Create new location?"),
  617. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  618. if dlg.ShowModal() == wx.ID_NO:
  619. dlg.Destroy()
  620. event.Veto()
  621. else:
  622. dlg.Destroy()
  623. event.Skip()
  624. if __name__ == "__main__":
  625. app = wx.App()
  626. gWizard = LocationWizard(None)
  627. # gWizard.Show()
  628. app.MainLoop()