r.li.setup.py 26 KB

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