wizard.py 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  1. """
  2. @package rlisetup.py
  3. @brief GUI per r.li.setup module
  4. Classes:
  5. - RLiSetupFrame (first frame to show existing conf file and choose some
  6. operation)
  7. - RLIWizard (the main wizard)
  8. - FirstPage (first page of wizard, choose name of conf file, raster, vector,
  9. sampling region)
  10. - Keyboard (page to insert region areas from keyboard)
  11. - SamplingAreas (define sampling area)
  12. - SummaryPage (show choosen options)
  13. (C) 2011 by the GRASS Development Team
  14. This program is free software under the GNU General Public License
  15. (>=v2). Read the file COPYING that comes with GRASS for details.
  16. @author Luca Delucchi <lucadeluge gmail com>
  17. """
  18. import sys
  19. import os
  20. wxbase = os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython')
  21. if wxbase not in sys.path:
  22. sys.path.append(wxbase)
  23. import wx
  24. import wx.wizard as wiz
  25. import wx.lib.scrolledpanel as scrolled
  26. from gui_core import gselect
  27. from core.utils import _
  28. from location_wizard.wizard import TitledPage as TitledPage
  29. from rlisetup.functions import checkValue, retRLiPath
  30. from rlisetup.sampling_frame import RLiSetupMapPanel
  31. from grass.script import core as grass
  32. from grass.script import raster as grast
  33. from functions import SamplingType, sampleAreaVector, convertFeature, obtainAreaVector
  34. from core.gcmd import GError, GMessage, RunCommand
  35. #@NOTE: r.li.setup writes in the settings file with
  36. ## r.li.windows.tcl:
  37. #exec echo "SAMPLINGFRAME $per_x|$per_y|$per_rl|$per_cl" >> $env(TMP).set
  38. class RLIWizard(object):
  39. """
  40. !Start wizard here and finish wizard here
  41. """
  42. def __init__(self, parent):
  43. self.parent = parent
  44. self.wizard = wiz.Wizard(parent=parent, id=wx.ID_ANY,
  45. title=_("Create new configuration file for " \
  46. "r.li modules"))
  47. self.rlipath = retRLiPath()
  48. self.msAreaList = []
  49. #pages
  50. self.startpage = FirstPage(self.wizard, self)
  51. self.drawsampleframepage = DrawSampleFramePage(self.wizard, self)
  52. self.keyboardpage = KeyboardPage(self.wizard, self)
  53. self.samplingareapage = SamplingAreasPage(self.wizard, self)
  54. self.summarypage = SummaryPage(self.wizard, self)
  55. self.units = SampleUnitsKeyPage(self.wizard, self)
  56. self.drawunits = SampleUnitsMousePage(self.wizard, self)
  57. self.drawsampleunitspage = DrawSampleUnitsPage(self.wizard, self)
  58. self.vectorareas = VectorAreasPage(self.wizard, self)
  59. self.moving = MovingWindows(self.wizard, self)
  60. self.regions = DrawRegionsPage(self.wizard, self)
  61. #order of pages
  62. self.startpage.SetNext(self.samplingareapage)
  63. self.keyboardpage.SetPrev(self.startpage)
  64. self.keyboardpage.SetNext(self.samplingareapage)
  65. self.drawsampleframepage.SetNext(self.samplingareapage)
  66. self.drawsampleframepage.SetPrev(self.startpage)
  67. self.samplingareapage.SetPrev(self.startpage)
  68. self.samplingareapage.SetNext(self.summarypage)
  69. self.regions.SetPrev(self.samplingareapage)
  70. self.regions.SetNext(self.summarypage)
  71. self.units.SetPrev(self.samplingareapage)
  72. self.units.SetNext(self.summarypage)
  73. self.drawunits.SetPrev(self.samplingareapage)
  74. self.drawunits.SetNext(self.drawsampleunitspage)
  75. self.drawsampleunitspage.SetPrev(self.drawunits)
  76. self.drawsampleunitspage.SetNext(self.summarypage)
  77. self.moving.SetPrev(self.samplingareapage)
  78. self.moving.SetNext(self.summarypage)
  79. self.vectorareas.SetPrev(self.samplingareapage)
  80. self.vectorareas.SetNext(self.summarypage)
  81. self.summarypage.SetPrev(self.samplingareapage)
  82. #layout
  83. self.startpage.DoLayout()
  84. self.drawsampleframepage.DoLayout()
  85. self.keyboardpage.DoLayout()
  86. self.samplingareapage.DoLayout()
  87. self.summarypage.DoLayout()
  88. self.units.DoLayout()
  89. self.drawunits.DoLayout()
  90. self.drawsampleunitspage.DoLayout()
  91. self.regions.DoLayout()
  92. self.moving.DoLayout()
  93. self.vectorareas.DoLayout()
  94. self.wizard.FitToPage(self.startpage)
  95. #run_wizard
  96. if self.wizard.RunWizard(self.startpage):
  97. dlg = wx.MessageDialog(parent=self.parent,
  98. message=_("Do you want to create r.li " \
  99. "configuration file <%s>?") % self.startpage.conf_name,
  100. caption=_("Create new r.li configuration file?"),
  101. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  102. if dlg.ShowModal() == wx.ID_NO:
  103. self._cleanup()
  104. else:
  105. self._write_confile()
  106. self._cleanup()
  107. dlg.Destroy()
  108. else:
  109. self.wizard.Destroy()
  110. GMessage(parent=self.parent,
  111. message=_("r.li.setup wizard canceled. "
  112. "Configuration file not created."))
  113. self._cleanup()
  114. def _write_confile(self):
  115. """!Write the configuration file"""
  116. f = open(os.path.join(self.rlipath, self.startpage.conf_name), 'w')
  117. self.rasterinfo = grast.raster_info(self.startpage.rast)
  118. self._write_region(f)
  119. self._write_area(f)
  120. f.close()
  121. def _temp_region(self):
  122. # save current settings:
  123. grass.use_temp_region()
  124. # Temporarily aligning region resolution to $RASTER resolution
  125. # keep boundary settings
  126. grass.run_command('g.region', rast=self.startpage.rast)
  127. self.gregion = grass.region()
  128. self.SF_NSRES = self.gregion['nsres']
  129. self.SF_EWRES = self.gregion['ewres']
  130. def _write_region(self, fil):
  131. """!Write the region"""
  132. if self.startpage.region == 'whole':
  133. fil.write("SAMPLINGFRAME 0|0|1|1\n")
  134. self._temp_region()
  135. self.SF_X = 0.0
  136. self.SF_Y = 0.0
  137. self.SF_RL = abs(int(float(self.gregion['s'] - self.gregion['n'])
  138. / float(self.gregion['nsres'])))
  139. self.SF_CL = abs(int(float(self.gregion['e'] - self.gregion['w'])
  140. / float(self.gregion['ewres'])))
  141. self.SF_N = self.gregion['n']
  142. self.SF_S = self.gregion['s']
  143. self.SF_E = self.gregion['e']
  144. self.SF_W = self.gregion['w']
  145. self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
  146. self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
  147. self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
  148. self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
  149. elif self.startpage.region == 'key':
  150. self._temp_region()
  151. self.SF_X = float(self.keyboardpage.col_up)
  152. self.SF_Y = float(self.keyboardpage.row_up)
  153. self.SF_RL = float(self.keyboardpage.row_len)
  154. self.SF_CL = float(self.keyboardpage.col_len)
  155. self.SF_N = self.gregion['n'] - (self.SF_NSRES * self.SF_Y)
  156. self.SF_S = self.gregion['n'] - (self.SF_NSRES * self.SF_Y + self.SF_RL)
  157. self.SF_W = self.gregion['w'] + (self.SF_EWRES * self.SF_X)
  158. self.SF_E = self.gregion['w'] + (self.SF_EWRES * self.SF_X + self.SF_CL)
  159. self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
  160. self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
  161. self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
  162. self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
  163. fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" % (self.per_x, self.per_y,
  164. self.per_rl, self.per_cl))
  165. elif self.startpage.region == 'draw':
  166. self._temp_region()
  167. tregion = self.drawsampleframepage.tregion
  168. # should we call this? with align param?
  169. RunCommand('g.region', align=self.startpage.rast,
  170. n=tregion['n'], s=tregion['s'],
  171. w=tregion['w'], e=tregion['e'])
  172. newreg = grass.region()
  173. self.SF_N = newreg['n'] # set env(SF_N) $n
  174. self.SF_S = newreg['s'] # set env(SF_S) $s
  175. self.SF_E = newreg['e'] # set env(SF_E) $e
  176. self.SF_W = newreg['w'] # set env(SF_W) $w
  177. self.SF_Y = abs(round(self.gregion['n'] - newreg['n']) / newreg['nsres'])
  178. # set env(SF_Y) [expr abs(round(($s_n - $n) / $nres)) ]
  179. self.SF_X = abs(round(self.gregion['w'] - newreg['w']) / newreg['ewres'])
  180. # set env(SF_X) [expr abs(round(($s_w - $w) / $sres)) ]
  181. self.SF_RL = abs(round(newreg['n'] - newreg['s']) / newreg['nsres'])
  182. # set env(SF_RL) [expr abs(round(($n - $s) / $nres)) ]
  183. self.SF_CL = abs(round(newreg['e'] - newreg['w']) / newreg['ewres'])
  184. # set env(SF_CL) [expr abs(round(($e - $w) / $sres)) ]
  185. self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
  186. # double($env(SF_X)) / double($cols)
  187. self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
  188. # double($env(SF_Y)) / double($rows)
  189. self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
  190. # double($env(SF_RL)) / double($rows)
  191. self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
  192. # double($env(SF_CL)) / double($cols)
  193. fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" % (self.per_x, self.per_y,
  194. self.per_rl, self.per_cl))
  195. def _circle(self, radius, mask):
  196. """!Create a circle mask"""
  197. self.CIR_RL = round((2 * float(radius)) / float(self.rasterinfo['ewres']))
  198. self.CIR_CL = round((2 * float(radius)) / float(self.rasterinfo['nsres']))
  199. if not self.CIR_RL % 2:
  200. self.CIR_RL += 1
  201. if not self.CIR_CL % 2:
  202. self.CIR_CL += 1
  203. eastEdge = float(self.SF_W + (self.CIR_RL * self.SF_EWRES))
  204. southEdge = float(self.SF_N - (self.CIR_CL * self.SF_NSRES))
  205. grass.del_temp_region()
  206. grass.use_temp_region()
  207. grass.run_command('g.region', n=self.SF_N, s=southEdge, e=eastEdge,
  208. w=self.SF_W)
  209. xcenter = grass.region(complete=True)['center_easting']
  210. ycenter = grass.region(complete=True)['center_northing']
  211. grass.run_command('r.circle', flags='b', out=mask, max=radius,
  212. coordinate=[xcenter, ycenter], quiet=True)
  213. grass.del_temp_region()
  214. grass.use_temp_region()
  215. grass.run_command('g.region', rast=self.startpage.rast)
  216. def getSamplingType(self):
  217. """!Obtain the sampling type"""
  218. devicetype = self.samplingareapage.regionbox
  219. samplingtype = self.samplingareapage.samplingtype
  220. shapetype = self.units.boxtype
  221. if samplingtype == SamplingType.UNITS:
  222. if devicetype == 'mouse':
  223. if shapetype == 'circle':
  224. samtype = SamplingType.MUNITSC
  225. else:
  226. samtype = SamplingType.MUNITSR
  227. elif devicetype == 'keyboard':
  228. if shapetype == 'circle':
  229. samtype = SamplingType.KUNITSC
  230. else:
  231. samtype = SamplingType.KUNITSR
  232. elif samplingtype == SamplingType.MVWIN:
  233. if devicetype == 'mouse':
  234. if shapetype == 'circle':
  235. samtype = SamplingType.MMVWINC
  236. else:
  237. samtype = SamplingType.MMVWINR
  238. elif devicetype == 'keyboard':
  239. if shapetype == 'circle':
  240. samtype = SamplingType.KMVWINC
  241. else:
  242. samtype = SamplingType.KMVWINR
  243. elif samplingtype == SamplingType.WHOLE:
  244. samtype = SamplingType.WHOLE
  245. elif samplingtype == SamplingType.REGIONS:
  246. samtype = SamplingType.REGIONS
  247. elif samplingtype == SamplingType.VECT:
  248. samtype = SamplingType.VECT
  249. return samtype
  250. def _write_area(self, fil):
  251. """!Write the area according the type"""
  252. samtype = self.getSamplingType()
  253. #sampling type is whole
  254. if samtype == SamplingType.WHOLE:
  255. cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
  256. rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
  257. #this two variable are unused, problably to remove
  258. x = float(self.SF_X) / float(self.rasterinfo['cols'])
  259. y = float(self.SF_Y) / float(self.rasterinfo['rows'])
  260. fil.write("SAMPLEAREA %r|%r|%r|%r\n" % (self.per_x, self.per_y,
  261. rl, cl))
  262. ##KMWINC = samplingtype=moving, regionbox=keyboard, shape=circle
  263. elif samtype == SamplingType.KMVWINC:
  264. self._circle(self.moving.width, self.moving.height)
  265. cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
  266. rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
  267. fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
  268. fil.write("|%s" % self.moving.height)
  269. fil.write("\nMOVINGWINDOW\n")
  270. ##KMWINR = samplingtype moving, regionbox=keyboard, shape=rectangle
  271. elif samtype == SamplingType.KMVWINR:
  272. cl = float(self.moving.width) / float(self.rasterinfo['cols'])
  273. rl = float(self.moving.height) / float(self.rasterinfo['rows'])
  274. fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
  275. fil.write("\nMOVINGWINDOW\n")
  276. ##KUNITSC = samplingtype=units, regionbox=keyboard, shape=cirlce
  277. ##KUNITSR = samplingtype=units, regionbox=keyboard, shape=rectangle
  278. elif samtype == SamplingType.KUNITSC or samtype == SamplingType.KUNITSR:
  279. if samtype == SamplingType.KUNITSC:
  280. self._circle(self.units.width, self.units.height)
  281. cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
  282. rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
  283. else:
  284. cl = float(self.moving.width) / float(self.rasterinfo['cols'])
  285. rl = float(self.moving.height) / float(self.rasterinfo['rows'])
  286. fil.write("SAMPLEAREA -1|-1|%r|%r\n" % (rl, cl))
  287. if self.units.distrtype == 'non_overlapping':
  288. fil.write("RANDOMNONOVERLAPPING %s\n" % self.units.distr1)
  289. elif self.units.distrtype == 'systematic_contiguos':
  290. fil.write("SYSTEMATICCONTIGUOUS\n")
  291. elif self.units.distrtype == 'stratified_random':
  292. fil.write("STRATIFIEDRANDOM %s|%s\n" % (self.units.distr1,
  293. self.units.distr2))
  294. elif self.units.distrtype == 'systematic_noncontiguos':
  295. fil.write("SYSTEMATICNONCONTIGUOUS %s\n" % self.units.distr1)
  296. elif self.units.distrtype == 'centered_oversites':
  297. fil.write("")
  298. #elif self.samplingareapage.samplingtype == SamplingType.UNITS and self.samplingareapage.regionbox=='mouse':
  299. ##MUNITSC = samplingtype=units, regionbox=mouse, shape=cirlce
  300. elif self.samplingareapage.samplingtype == SamplingType.MUNITSC:
  301. print "not added"
  302. ##MUNITSR = samplingtype=units, regionbox=mouse, shape=rectangle
  303. elif self.samplingareapage.samplingtype == SamplingType.MUNITSR:
  304. for tregion in self.msAreaList:
  305. rows = float(self.rasterinfo['rows'])
  306. cols = float(self.rasterinfo['cols'])
  307. # get the raster region into rastregion
  308. grass.use_temp_region()
  309. grass.run_command('g.region', rast=self.startpage.rast)
  310. rastregion = grass.region()
  311. s_n = rastregion['n']
  312. s_w = rastregion['w']
  313. abs_y = abs(round((float(s_n) - tregion['n']) / tregion['nsres']))
  314. abs_x = abs(round((float(s_w) - tregion['w']) / tregion['ewres']))
  315. abs_rl = abs(round((tregion['n'] - tregion['s']) / tregion['nsres']))
  316. abs_cl = abs(round((tregion['e'] - tregion['w']) / tregion['ewres']))
  317. x = float(abs_x) / float(cols)
  318. y = float(abs_y) / float(rows)
  319. rl = float(abs_rl) / float(rows)
  320. cl = float(abs_cl) / float(cols)
  321. sarea = str(x) + "|" + str(y) + "|" + str(rl) + "|" + str(cl)
  322. fil.write("SQUAREAREA %s\n" % sarea)
  323. elif self.samplingareapage.samplingtype == SamplingType.REGIONS:
  324. for marea in self.msAreaList:
  325. gregion = marea.region
  326. rows = float(self.rasterinfo['rows'])
  327. cols = float(self.rasterinfo['cols'])
  328. abs_y = self.SF_Y + abs(round((self.SF_N - gregion['n']) / self.SF_NSRES))
  329. abs_x = self.SF_X + abs(round((self.SF_W - gregion['w']) / self.SF_EWRES))
  330. abs_rl = abs(round(gregion['n'] - gregion['s']) / self.SF_NSRES)
  331. abs_cl = abs(round(gregion['e'] - gregion['w']) / self.SF_EWRES)
  332. x = float(abs_x) / float(cols)
  333. y = float(abs_y) / float(rows)
  334. rl = float(abs_rl) / float(rows)
  335. cl = float(abs_cl) / float(cols)
  336. maskArea = str(x) + "|" + str(y) + "|" + str(rl) + "|" + str(cl) + "|" + marea.raster
  337. fil.write("SQUAREAREA %s\n" % maskArea)
  338. elif self.samplingareapage.samplingtype == SamplingType.VECT:
  339. for marea in self.msAreaList:
  340. fil.write(marea)
  341. fil.write("RASTERMAP {name}\n".format(name=self.startpage.rast))
  342. fil.write("VECTORMAP {name}\n".format(name=self.startpage.vect))
  343. def _cleanup(self):
  344. """!Clean all the variables to save into configuration file"""
  345. self.startpage.conf_name = ''
  346. self.startpage.rast = ''
  347. self.startpage.vect = ''
  348. self.startpage.region = 'whole'
  349. self.keyboardpage.col_len = ''
  350. self.keyboardpage.col_up = ''
  351. self.keyboardpage.row_len = ''
  352. self.keyboardpage.row_up = ''
  353. self.samplingareapage.samplingtype = 'whole'
  354. self.units.width = ''
  355. self.units.height = ''
  356. self.units.boxtype = ''
  357. self.regions.numregions = 0
  358. self.moving.width = ''
  359. self.moving.height = ''
  360. self.moving.boxtype = ''
  361. class FirstPage(TitledPage):
  362. """
  363. !Set name of configuration file, choose raster and optionally vector/sites
  364. """
  365. def __init__(self, wizard, parent):
  366. TitledPage.__init__(self, wizard, _("Select maps and define name"))
  367. self.region = 'whole'
  368. self.rast = ''
  369. self.conf_name = ''
  370. self.vect = ''
  371. self.parent = parent
  372. #name of output configuration file
  373. self.newconflabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  374. label=_('Name for new configuration file to create'))
  375. self.newconftxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  376. size=(250, -1))
  377. wx.CallAfter(self.newconftxt.SetFocus)
  378. self.sizer.Add(item=self.newconflabel, border=5, pos=(0, 0),
  379. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  380. self.sizer.Add(item=self.newconftxt, border=5, pos=(0, 1),
  381. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  382. #raster
  383. self.mapsellabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  384. label=_('Raster map to use to select areas'))
  385. self.mapselect = gselect.Select(parent=self, id=wx.ID_ANY,
  386. size=(250, -1), type='cell',
  387. multiple=False)
  388. self.sizer.Add(item=self.mapsellabel, border=5, pos=(1, 0),
  389. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  390. self.sizer.Add(item=self.mapselect, border=5, pos=(1, 1),
  391. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  392. #vector
  393. self.vectsellabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  394. label=_('Vector map to use to select areas'))
  395. self.vectselect = gselect.Select(parent=self, id=wx.ID_ANY,
  396. size=(250, -1), type='vector',
  397. multiple=False)
  398. self.sizer.Add(item=self.vectsellabel, border=5, pos=(2, 0),
  399. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  400. self.sizer.Add(item=self.vectselect, border=5, pos=(2, 1),
  401. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  402. #define sampling region
  403. self.sampling_reg = wx.RadioBox(parent=self, id=wx.ID_ANY,
  404. label=" %s " % _("Define sampling " \
  405. " region (region for analysis)"),
  406. choices=[_('Whole map layer'),
  407. _('Keyboard setting'),
  408. _('Draw the sampling frame')],
  409. majorDimension=1,
  410. style=wx.RA_SPECIFY_ROWS)
  411. self.sizer.Add(item=self.sampling_reg,
  412. flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
  413. pos=(4, 0), span=(1, 2))
  414. #bindings
  415. self.sampling_reg.Bind(wx.EVT_RADIOBOX, self.OnSampling)
  416. self.newconftxt.Bind(wx.EVT_KILL_FOCUS, self.OnName)
  417. self.newconftxt.Bind(wx.EVT_TEXT, self.OnNameChanged)
  418. self.vectselect.Bind(wx.EVT_TEXT, self.OnVector)
  419. self.mapselect.Bind(wx.EVT_TEXT, self.OnRast)
  420. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  421. wx.CallAfter(wx.FindWindowById(wx.ID_FORWARD).Enable, False)
  422. def OnSampling(self, event):
  423. """!Change region type"""
  424. if event.GetInt() == 0:
  425. self.region = 'whole'
  426. self.SetNext(self.parent.samplingareapage)
  427. elif event.GetInt() == 1:
  428. self.region = 'key'
  429. self.SetNext(self.parent.keyboardpage)
  430. elif event.GetInt() == 2: # currently disabled
  431. self.region = 'draw'
  432. self.SetNext(self.parent.drawsampleframepage)
  433. def OnName(self, event):
  434. """!Sets the name of configuration file"""
  435. if self.conf_name in self.parent.parent.listfiles:
  436. GMessage(parent=self, message=_("The configuration file %s "
  437. "already exists, please change name") % self.conf_name)
  438. self.newconftxt.SetValue('')
  439. self.conf_name = ''
  440. def OnNameChanged(self, event):
  441. """!Name of configuration file has changed"""
  442. self.conf_name = self.newconftxt.GetValue()
  443. next = wx.FindWindowById(wx.ID_FORWARD)
  444. next.Enable(self.CheckInput())
  445. def OnRast(self, event):
  446. """!Sets raster map"""
  447. self.rast = event.GetString()
  448. next = wx.FindWindowById(wx.ID_FORWARD)
  449. next.Enable(self.CheckInput())
  450. def OnVector(self, event):
  451. """!Sets vector map"""
  452. self.vect = event.GetString()
  453. next = wx.FindWindowById(wx.ID_FORWARD)
  454. next.Enable(self.CheckInput())
  455. def CheckInput(self):
  456. """!Check input fields.
  457. @return True if configuration file is given and raster xor vector map,
  458. False otherwise
  459. """
  460. #R#return bool(self.conf_name and (bool(self.rast) != bool(self.vect)))
  461. return bool(self.conf_name and bool(self.rast))
  462. def OnExitPage(self, event=None):
  463. """!Function during exiting"""
  464. if self.conf_name == '' or self.rast == '':
  465. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  466. else:
  467. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  468. if event.GetDirection():
  469. if self.region == 'key':
  470. self.SetNext(self.parent.keyboardpage)
  471. self.parent.samplingareapage.SetPrev(self.parent.keyboardpage)
  472. elif self.region == 'whole':
  473. self.SetNext(self.parent.samplingareapage)
  474. self.parent.samplingareapage.SetPrev(self)
  475. elif self.region == 'draw':
  476. self.SetNext(self.parent.drawsampleframepage)
  477. self.parent.samplingareapage.SetPrev(self.parent.drawsampleframepage)
  478. return
  479. class KeyboardPage(TitledPage):
  480. """
  481. !Choose the region setting the values of border using the keyboard
  482. """
  483. def __init__(self, wizard, parent):
  484. TitledPage.__init__(self, wizard, _("Insert sampling frame parameter"))
  485. self.parent = parent
  486. self.sizer.AddGrowableCol(2)
  487. self.col_len = ''
  488. self.row_len = ''
  489. self.col_up = '0'
  490. self.row_up = '0'
  491. #column up/left
  492. self.ColUpLeftlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  493. label=_("Column of upper left " \
  494. "corner"))
  495. self.ColUpLefttxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  496. size=(250, -1))
  497. wx.CallAfter(self.ColUpLeftlabel.SetFocus)
  498. self.sizer.Add(item=self.ColUpLeftlabel, border=5, pos=(1, 1),
  499. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  500. self.sizer.Add(item=self.ColUpLefttxt, border=5, pos=(1, 2),
  501. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  502. #row up/left
  503. self.RowUpLeftlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  504. label=_('Row of upper left corner'))
  505. self.RowUpLefttxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  506. size=(250, -1))
  507. wx.CallAfter(self.RowUpLeftlabel.SetFocus)
  508. self.sizer.Add(item=self.RowUpLeftlabel, border=5, pos=(2, 1),
  509. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  510. self.sizer.Add(item=self.RowUpLefttxt, border=5, pos=(2, 2),
  511. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  512. #row lenght
  513. self.RowLenlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  514. label=_('Row lenght of sampling frame'))
  515. self.RowLentxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  516. wx.CallAfter(self.RowLenlabel.SetFocus)
  517. self.sizer.Add(item=self.RowLenlabel, border=5, pos=(3, 1),
  518. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  519. self.sizer.Add(item=self.RowLentxt, border=5, pos=(3, 2),
  520. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  521. #column lenght
  522. self.ColLenlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  523. label=_('Row lenght of sampling frame'))
  524. self.ColLentxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  525. wx.CallAfter(self.ColLenlabel.SetFocus)
  526. self.sizer.Add(item=self.ColLenlabel, border=5, pos=(4, 1),
  527. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  528. self.sizer.Add(item=self.ColLentxt, border=5, pos=(4, 2),
  529. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  530. self.ColUpLefttxt.SetValue(self.col_up)
  531. self.RowUpLefttxt.SetValue(self.row_up)
  532. self.ColUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLeft)
  533. self.RowUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLeft)
  534. self.ColLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLen)
  535. self.RowLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLen)
  536. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  537. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  538. def OnColLeft(self, event):
  539. """!Sets the name of configuration file"""
  540. self.col_up = self.ColUpLefttxt.GetValue()
  541. checkValue(self.col_up)
  542. def OnRowLeft(self, event):
  543. """!Sets the name of configuration file"""
  544. self.row_up = self.RowUpLefttxt.GetValue()
  545. checkValue(self.row_up)
  546. def OnColLen(self, event):
  547. """!Sets the name of configuration file"""
  548. self.col_len = self.ColLentxt.GetValue()
  549. checkValue(self.col_len)
  550. def OnRowLen(self, event):
  551. """!Sets the name of configuration file"""
  552. self.row_len = self.RowLentxt.GetValue()
  553. checkValue(self.row_len)
  554. def OnEnterPage(self, event):
  555. """!Sets the default values, for the entire map
  556. """
  557. #R# check if raster exists before anything
  558. if self.col_len == '' and self.row_len == '':
  559. rastinfo = grast.raster_info(self.parent.startpage.rast)
  560. self.col_len = rastinfo['cols']
  561. self.row_len = rastinfo['rows']
  562. self.ColLentxt.SetValue(self.col_len)
  563. self.RowLentxt.SetValue(self.row_len)
  564. def OnExitPage(self, event=None):
  565. """!Function during exiting"""
  566. if self.row_len == '' or self.col_len == '' or self.row_up == '' or self.col_up == '':
  567. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  568. else:
  569. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  570. class DrawSampleFramePage(TitledPage):
  571. """!Choose the region setting the values drawing a box"""
  572. def __init__(self, wizard, parent):
  573. TitledPage.__init__(self, wizard, _("Draw sampling frame"))
  574. self.parent = parent
  575. self.mapPanel = None
  576. self.tregion = None
  577. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  578. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  579. def SampleFrameChanged(self, region):
  580. """"!Enables the next dialog when region is set"""
  581. if region:
  582. self.tregion = region
  583. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  584. else:
  585. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  586. def OnEnterPage(self, event):
  587. """!Function during entering"""
  588. if self.mapPanel is None:
  589. self.mapPanel = RLiSetupMapPanel(self, samplingType='drawFrame')
  590. self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
  591. self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(0, 0))
  592. self.sizer.AddGrowableCol(0)
  593. self.sizer.AddGrowableRow(0)
  594. self._raster = None
  595. else:
  596. self.mapPanel._region = {}
  597. self.SampleFrameChanged(region=None)
  598. rast = self.parent.startpage.rast
  599. if self._raster != rast:
  600. map_ = self.mapPanel.GetMap()
  601. map_.DeleteAllLayers()
  602. cmdlist = ['d.rast', 'map=%s' % rast]
  603. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  604. name=rast, hidden=False, opacity=1.0,
  605. render=True)
  606. def OnExitPage(self, event=None):
  607. """!Function during exiting"""
  608. if event.GetDirection():
  609. self.SetNext(self.parent.samplingareapage)
  610. self.parent.samplingareapage.SetPrev(self)
  611. else:
  612. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  613. class SampleUnitsMousePage(TitledPage):
  614. """!Choose the sampling area setting the values using the mouse"""
  615. def __init__(self, wizard, parent):
  616. TitledPage.__init__(self, wizard, _("Draw sampling units"))
  617. self.parent = parent
  618. self.numregions = ''
  619. self.mapPanel = None
  620. # type of shape
  621. self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  622. majorDimension=1, style=wx.RA_SPECIFY_COLS,
  623. label=" %s " % _("Select type of shape"),
  624. choices=[_('Rectangle'), _('Circle')])
  625. self.sizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
  626. span=(1, 2))
  627. self.regionPanelSizer = wx.GridBagSizer(1, 2)
  628. self.regionNumPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  629. self.regionNumLabel = wx.StaticText(parent=self.regionNumPanel,
  630. id=wx.ID_ANY,
  631. label=_('Number of sampling area to draw:'))
  632. self.regionNumTxt = wx.TextCtrl(parent=self.regionNumPanel,
  633. id=wx.ID_ANY, size=(50, -1))
  634. self.regionPanelSizer.Add(self.regionNumLabel, flag=wx.ALIGN_CENTER,
  635. pos=(0, 0))
  636. self.regionPanelSizer.Add(self.regionNumTxt, flag=wx.ALIGN_CENTER,
  637. pos=(0, 1))
  638. self.regionNumPanel.SetSizer(self.regionPanelSizer)
  639. self.sizer.Add(self.regionNumPanel, flag=wx.ALIGN_LEFT, pos=(1, 0),
  640. span=(1, 2))
  641. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  642. self.regionNumTxt.Bind(wx.EVT_TEXT, self.OnNumRegions)
  643. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  644. self.sizer.AddGrowableCol(0)
  645. self.OnType(None)
  646. self.regionNumTxt.SetValue('')
  647. def OnEnterPage(self, event):
  648. """!Function during entering"""
  649. if self.numregions:
  650. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  651. else:
  652. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  653. def OnType(self, event):
  654. chosen = self.typeBox.GetSelection()
  655. if chosen == 0:
  656. self.drawtype = 'rectangle'
  657. else:
  658. self.drawtype = 'circle'
  659. def OnNumRegions(self, event):
  660. """!Set the number of region"""
  661. if event.GetString():
  662. self.SetNext(self.parent.drawsampleunitspage)
  663. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  664. self.numregions = event.GetString()
  665. else:
  666. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  667. def OnExitPage(self, event=None):
  668. """!Function during exiting"""
  669. if event.GetDirection():
  670. self.SetNext(self.drawsampleunitspage)
  671. self.SetPrev(self.samplingareapage)
  672. class DrawSampleUnitsPage(TitledPage):
  673. """!Choose the sampling area drawing them"""
  674. def __init__(self, wizard, parent):
  675. TitledPage.__init__(self, wizard, _("Draw sampling units"))
  676. self.parent = parent
  677. self.regioncount = 0
  678. self.mapPanel = None
  679. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  680. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  681. def SampleFrameChanged(self, region):
  682. #region = self.GetSampleUnitRegion()
  683. if region:
  684. self.parent.msAreaList.append(region)
  685. self.regioncount = self.regioncount + 1
  686. numregions = int(self.parent.drawunits.numregions)
  687. drawtype = self.parent.drawunits.drawtype
  688. if self.regioncount > numregions:
  689. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  690. else:
  691. self.title.SetLabel(_('Draw Sampling ' + drawtype + ' ' \
  692. + str(self.regioncount) + ' of ' \
  693. + str(numregions) ))
  694. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  695. def afterCircleDrawn(self):
  696. if region:
  697. self.parent.msAreaList.append(region)
  698. self.regioncount = self.regioncount + 1
  699. numregions = int(self.parent.drawunits.numregions)
  700. drawtype = self.parent.drawunits.drawtype
  701. if self.regioncount > numregions:
  702. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  703. else:
  704. self.title.SetLabel(_('Draw Sampling ' + drawtype + ' ' \
  705. + str(self.regioncount) + ' of ' \
  706. + str(numregions) ))
  707. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  708. def OnEnterPage(self, event):
  709. """!Function during entering"""
  710. if self.mapPanel is None:
  711. gtype = self.parent.drawunits.drawtype
  712. self.mapPanel = RLiSetupMapPanel(self, samplingType=self.parent.samplingareapage.samplingtype,
  713. graphicsType=gtype)
  714. if gtype == 'circle':
  715. self.mapPanel.afterCircleDrawn.connect(self.afterCircleDrawn)
  716. else:
  717. self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
  718. self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  719. self.sizer.AddGrowableCol(0)
  720. self.sizer.AddGrowableRow(1)
  721. self._raster = None
  722. self.SampleFrameChanged(region=None)
  723. rast = self.parent.startpage.rast
  724. if self._raster != rast:
  725. map_ = self.mapPanel.GetMap()
  726. map_.DeleteAllLayers()
  727. cmdlist = ['d.rast', 'map=%s' % rast]
  728. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  729. name=rast, hidden=False, opacity=1.0,
  730. render=True)
  731. def OnExitPage(self, event=None):
  732. #!Function during exiting
  733. print event.GetDirection()
  734. #if event.GetDirection():
  735. # self.SetNext(self.parent.samplingareapage)
  736. # self.parent.samplingareapage.SetPrev(self)
  737. class DrawRegionsPage(TitledPage):
  738. def __init__(self, wizard, parent):
  739. TitledPage.__init__(self, wizard, _("Draw sampling region"))
  740. self.parent = parent
  741. self.regioncount = 0
  742. self.mapPanel = None
  743. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  744. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  745. def afterRegionDrawn(self, marea):
  746. if marea:
  747. self.parent.msAreaList.append(marea)
  748. self.regioncount = self.regioncount + 1
  749. numregions = int(self.parent.samplingareapage.numregions)
  750. if self.regioncount > numregions:
  751. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  752. else:
  753. self.title.SetLabel(_('Draw sample region ' + str(self.regioncount) + ' of ' + str(numregions) ))
  754. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  755. def OnEnterPage(self, event):
  756. """!Function during entering"""
  757. if self.mapPanel is None:
  758. #print self.parent.samplingareapage.samplingtype
  759. self.mapPanel = RLiSetupMapPanel(self, samplingType=self.parent.samplingareapage.samplingtype, graphicsType="line")
  760. self.mapPanel.afterRegionDrawn.connect(self.afterRegionDrawn)
  761. self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  762. self.sizer.AddGrowableCol(0)
  763. self.sizer.AddGrowableRow(1)
  764. self._raster = None
  765. rast = self.parent.startpage.rast
  766. self.afterRegionDrawn(marea=None)
  767. if self._raster != rast:
  768. map_ = self.mapPanel.GetMap()
  769. map_.DeleteAllLayers()
  770. cmdlist = ['d.rast', 'map=%s' % rast]
  771. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  772. name=rast, hidden=False, opacity=1.0,
  773. render=True)
  774. #def OnExitPage(self, event=None):
  775. #!Function during exiting
  776. #print event.GetDirection()
  777. #if event.GetDirection():
  778. # self.SetNext(self.parent.samplingareapage)
  779. # self.parent.samplingareapage.SetPrev(self)
  780. class VectorAreasPage(TitledPage):
  781. """!Choose the sampling area using the vector features"""
  782. def __init__(self, wizard, parent):
  783. TitledPage.__init__(self, wizard, _("Select sampling areas"))
  784. self.parent = parent
  785. self.areascount = 0
  786. self.mapPanel = None
  787. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  788. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  789. self.areaPanelSizer = wx.GridBagSizer(1, 3)
  790. self.areaPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  791. self.areaText = wx.StaticText(parent=self.areaPanel, id=wx.ID_ANY,
  792. label=_('Is this area ok?'))
  793. self.areaOK = wx.Button(self.areaPanel, wx.ID_ANY, 'Yes', (50, 80))
  794. self.areaNO = wx.Button(self.areaPanel, wx.ID_ANY, 'No', (50, 80))
  795. self.areaOK.Bind(wx.EVT_BUTTON, self.OnYes)
  796. self.areaNO.Bind(wx.EVT_BUTTON, self.OnNo)
  797. self.areaPanelSizer.Add(self.areaText, flag=wx.ALIGN_CENTER,
  798. pos=(0, 0))
  799. self.areaPanelSizer.Add(self.areaOK, flag=wx.ALIGN_CENTER,
  800. pos=(0, 1))
  801. self.areaPanelSizer.Add(self.areaNO, flag=wx.ALIGN_CENTER,
  802. pos=(0, 2))
  803. self.areaPanel.SetSizer(self.areaPanelSizer)
  804. self.sizer.Add(self.areaPanel, flag=wx.ALIGN_CENTER, pos=(2, 0))
  805. def afterRegionDrawn(self):
  806. """!Function to update the title and the number of selected area"""
  807. self.areascount = self.areascount + 1
  808. if self.areascount == self.areanum:
  809. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  810. return True
  811. else:
  812. self.title.SetLabel(_('Select sample area ' + str(self.areascount + 1) \
  813. + ' of ' + str(self.areanum)))
  814. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  815. return False
  816. def OnYes(self, event):
  817. """!Function to create the string for the conf file if the area
  818. is selected"""
  819. self.parent.msAreaList.append(obtainAreaVector(self.outname))
  820. if not self.afterRegionDrawn():
  821. self.newCat()
  822. def OnNo(self, event):
  823. """!Function to pass to the next feature if it is not selected"""
  824. if not self.afterRegionDrawn():
  825. self.newCat()
  826. def newCat(self):
  827. """!Convert to raster and draw the new feature"""
  828. cat = self.vect_cats[self.areascount]
  829. self.outname = "{name}_{cat}".format(name=self.vect.split('@')[0],
  830. cat=cat)
  831. convertFeature(self.vect, self.outname, cat, self.rast)
  832. cmdlistcat = ['d.rast', 'map=%s' % self.outname]
  833. self.map_.AddLayer(ltype='raster', command=cmdlistcat, active=True,
  834. name=self.outname, hidden=False, opacity=1.0,
  835. render=True)
  836. for l in self.map_.GetListOfLayers():
  837. if l.name == self.outname:
  838. self.mapPanel.mapWindow.ZoomToMap(layers=[l], render=True,
  839. ignoreNulls=True)
  840. elif l.name != self.rast:
  841. self.map_.DeleteLayer(l)
  842. self.areaText.SetLabel("Is this area (cat={n}) ok?".format(n=cat))
  843. def OnEnterPage(self, event):
  844. """!Function during entering: draw the raster map and the first vector
  845. feature"""
  846. if self.mapPanel is None:
  847. #print self.parent.samplingareapage.samplingtype
  848. self.mapPanel = RLiSetupMapPanel(self, samplingType=self.parent.samplingareapage.samplingtype,
  849. graphicsType="line")
  850. self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  851. self.sizer.AddGrowableCol(0)
  852. self.sizer.AddGrowableRow(1)
  853. self._raster = None
  854. self.rast = self.parent.startpage.rast
  855. self.vect = self.parent.startpage.vect
  856. self.vect_cats = sorted(set(grass.parse_command('v.category',
  857. input=self.vect,
  858. type='centroid',
  859. option='print').keys()))
  860. self.areanum = len(self.vect_cats)
  861. if self.areanum == 0:
  862. GError(parent=self, message=_("The polygon seems to have 0 areas"))
  863. self.parent.wizard.ShowPage(self.parent.samplingareapage)
  864. return
  865. self.title.SetLabel(_('Select sample area 1 of ' + str(self.areanum)))
  866. grass.use_temp_region()
  867. if self._raster != self.rast:
  868. self.map_ = self.mapPanel.GetMap()
  869. self.map_.DeleteAllLayers()
  870. cmdlist = ['d.rast', 'map=%s' % self.rast]
  871. self.map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  872. name=self.rast, hidden=False, opacity=1.0,
  873. render=True)
  874. self.newCat()
  875. def OnExitPage(self, event=None):
  876. """!Function during exiting"""
  877. grass.del_temp_region()
  878. # if event.GetDirection():
  879. # self.SetNext(self.parent.samplingareapage)
  880. # self.parent.samplingareapage.SetPrev(self)
  881. class SamplingAreasPage(TitledPage):
  882. """
  883. Set name of configuration file, choose raster and optionally vector/sites
  884. """
  885. def __init__(self, wizard, parent):
  886. TitledPage.__init__(self, wizard, _("Insert sampling areas"))
  887. self.samplingtype = 'whole'
  888. self.parent = parent
  889. # toggles
  890. self.radioBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  891. label="",
  892. choices=[_("Whole map layer"),
  893. _("Regions"),
  894. _("Sample units"),
  895. _("Moving window"),
  896. _("Select areas from the\n"
  897. "overlayed vector map")],
  898. majorDimension=1,
  899. style=wx.RA_SPECIFY_COLS | wx.NO_BORDER)
  900. # layout
  901. self.sizer.SetVGap(10)
  902. self.sizer.Add(item=self.radioBox, flag=wx.ALIGN_LEFT, pos=(0, 0))
  903. self.regionBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  904. label=_("Choose a method"),
  905. choices=[_('Use keyboard to enter sampling area'),
  906. _('Use mouse to draw sampling area')],
  907. majorDimension=1,
  908. style=wx.RA_SPECIFY_ROWS)
  909. self.regionBox.EnableItem(1, False)
  910. self.regionBox.SetItemToolTip(1, _("This option is not supported yet"))
  911. self.sizer.Add(self.regionBox, flag=wx.ALIGN_CENTER, pos=(1, 0))
  912. # bindings
  913. self.radioBox.Bind(wx.EVT_RADIOBOX, self.SetVal)
  914. self.regionBox.Bind(wx.EVT_RADIOBOX, self.OnRegionDraw)
  915. self.regionbox = 'keyboard'
  916. self.regionPanelSizer = wx.GridBagSizer(1, 2)
  917. self.regionNumPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  918. self.regionNumLabel = wx.StaticText(parent=self.regionNumPanel,
  919. id=wx.ID_ANY,
  920. label=_('Number of regions to draw:'))
  921. self.regionNumTxt = wx.TextCtrl(parent=self.regionNumPanel,
  922. id=wx.ID_ANY, size=(50, -1))
  923. self.regionPanelSizer.Add(self.regionNumLabel, flag=wx.ALIGN_CENTER,
  924. pos=(0, 0))
  925. self.regionPanelSizer.Add(self.regionNumTxt, flag=wx.ALIGN_CENTER,
  926. pos=(0, 1))
  927. self.regionNumPanel.SetSizer(self.regionPanelSizer)
  928. self.sizer.Add(self.regionNumPanel, flag=wx.ALIGN_CENTER, pos=(2, 0))
  929. self.areaPanelSizer = wx.GridBagSizer(1, 3)
  930. self.areaPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  931. self.areaText = wx.StaticText(parent=self.areaPanel, id=wx.ID_ANY,
  932. label=_('Do you want to check vector areas?'))
  933. self.areaOK = wx.Button(self.areaPanel, wx.ID_ANY, 'Yes', (50, 80))
  934. self.areaOK.SetToolTip(wx.ToolTip(_("Select if use area by area")))
  935. self.areaNO = wx.Button(self.areaPanel, wx.ID_ANY, 'No', (50, 80))
  936. self.areaNO.SetToolTip(wx.ToolTip(_("All the features will be used")))
  937. self.areaOK.Bind(wx.EVT_BUTTON, self.OnVectYes)
  938. self.areaNO.Bind(wx.EVT_BUTTON, self.OnVectNo)
  939. self.areaPanelSizer.Add(self.areaText, flag=wx.ALIGN_CENTER,
  940. pos=(0, 0))
  941. self.areaPanelSizer.Add(self.areaOK, flag=wx.ALIGN_CENTER,
  942. pos=(0, 1))
  943. self.areaPanelSizer.Add(self.areaNO, flag=wx.ALIGN_CENTER,
  944. pos=(0, 2))
  945. self.areaPanel.SetSizer(self.areaPanelSizer)
  946. self.sizer.Add(self.areaPanel, flag=wx.ALIGN_CENTER, pos=(3, 0))
  947. self.calculatingAreas = wx.StaticText(parent=self, id=wx.ID_ANY,
  948. label=_('Analysing all vector features...'))
  949. self.sizer.Add(self.calculatingAreas, flag=wx.ALIGN_CENTER, pos=(4, 0))
  950. self.numregions = ''
  951. self.regionNumTxt.Bind(wx.EVT_TEXT, self.OnNumRegions)
  952. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  953. def OnNumRegions(self, event):
  954. """!Obtain the number of regions"""
  955. if event.GetString():
  956. self.SetNext(self.parent.regions)
  957. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  958. self.numregions = event.GetString()
  959. else:
  960. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  961. def OnEnterPage(self, event):
  962. """!Insert values into text controls for summary of location
  963. creation options
  964. """
  965. self.SetVal(None)
  966. if self.parent.startpage.vect:
  967. self.radioBox.ShowItem(4, True)
  968. self.vect_data = []
  969. else:
  970. self.radioBox.ShowItem(4, False)
  971. self.sizer.Layout()
  972. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  973. def SetVal(self, event):
  974. """!Choose method"""
  975. radio = self.radioBox.GetSelection()
  976. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  977. if radio == 0:
  978. self.samplingtype = SamplingType.WHOLE
  979. self.DrawNothing()
  980. elif radio == 1:
  981. self.samplingtype = SamplingType.REGIONS
  982. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  983. elif radio == 2:
  984. self.samplingtype = SamplingType.UNITS
  985. regtype = self.regionBox.GetSelection()
  986. self.RegionDraw(regtype)
  987. elif radio == 3:
  988. self.samplingtype = SamplingType.MVWIN
  989. self.SetNext(self.parent.moving)
  990. elif radio == 4:
  991. self.samplingtype = SamplingType.VECT
  992. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  993. self.ShowExtraOptions(self.samplingtype)
  994. def ShowExtraOptions(self, samtype):
  995. """!Show some extra options for some sampling type"""
  996. if samtype == SamplingType.REGIONS:
  997. self.sizer.Hide(self.regionBox)
  998. self.sizer.Hide(self.areaPanel)
  999. self.sizer.Hide(self.calculatingAreas)
  1000. self.sizer.Show(self.regionNumPanel)
  1001. elif samtype == SamplingType.UNITS or samtype == SamplingType.MVWIN:
  1002. self.sizer.Hide(self.regionNumPanel)
  1003. self.sizer.Hide(self.areaPanel)
  1004. self.sizer.Hide(self.calculatingAreas)
  1005. self.sizer.Show(self.regionBox)
  1006. elif samtype == SamplingType.VECT:
  1007. self.sizer.Hide(self.regionBox)
  1008. self.sizer.Hide(self.regionNumPanel)
  1009. self.sizer.Hide(self.calculatingAreas)
  1010. self.sizer.Show(self.areaPanel)
  1011. self.sizer.Layout()
  1012. def OnRegionDraw(self, event):
  1013. self.RegionDraw(event.GetInt())
  1014. return
  1015. def OnVectYes(self, event):
  1016. """!The user choose to select the vector areas, this function set the
  1017. next page to VectorAreasPage"""
  1018. self.SetNext(self.parent.vectorareas)
  1019. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1020. self.parent.wizard.ShowPage(self.parent.vectorareas)
  1021. def OnVectNo(self, event):
  1022. """!The user choose to use all the vector areas, this function analyses
  1023. all the vector areas and fill the msAreaList variable"""
  1024. self.sizer.Show(self.calculatingAreas)
  1025. self.sizer.Hide(self.regionNumPanel)
  1026. self.sizer.Hide(self.regionBox)
  1027. self.sizer.Hide(self.areaPanel)
  1028. self.SetNext(self.parent.summarypage)
  1029. vect_cats = sorted(set(grass.parse_command('v.category', input=self.parent.startpage.vect,
  1030. option='print',
  1031. type='centroid').keys()))
  1032. self._progressDlg = wx.ProgressDialog(title=_("Analysing vector"),
  1033. message="Analysing vector",
  1034. maximum=len(vect_cats),
  1035. parent=self,
  1036. style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL |
  1037. wx.PD_AUTO_HIDE | wx.PD_SMOOTH)
  1038. self._progressDlgMax = len(vect_cats)
  1039. grass.use_temp_region()
  1040. self.parent.msAreaList = sampleAreaVector(self.parent.startpage.vect,
  1041. self.parent.startpage.rast,
  1042. vect_cats,
  1043. self._progressDlg)
  1044. grass.del_temp_region()
  1045. if self.parent.msAreaList:
  1046. self.calculatingAreas.SetLabel(_("All feature are been analyzed."))
  1047. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1048. self.parent.wizard.ShowPage(self.parent.summarypage)
  1049. else:
  1050. self.calculatingAreas.SetLabel(_("An error occurred"))
  1051. self._progressDlg.Destroy()
  1052. self._progressDlg = None
  1053. def RegionDraw(self, regtype):
  1054. """!Set the next page to units or drawunits"""
  1055. if regtype == 0:
  1056. self.regionbox = 'keyboard'
  1057. self.SetNext(self.parent.units)
  1058. elif regtype == 1:
  1059. self.regionbox = 'mouse'
  1060. self.SetNext(self.parent.drawunits)
  1061. def DrawNothing(self):
  1062. """Remove all the optional choices. Used also when the wizard enter in
  1063. SamplingAreasPage, all the optional choices should be hide here"""
  1064. self.sizer.Hide(self.regionNumPanel)
  1065. self.sizer.Hide(self.regionBox)
  1066. self.sizer.Hide(self.areaPanel)
  1067. self.sizer.Hide(self.calculatingAreas)
  1068. self.sizer.Layout()
  1069. self.SetNext(self.parent.summarypage)
  1070. class SampleUnitsKeyPage(TitledPage):
  1071. """!Set values from keyboard for sample units"""
  1072. def __init__(self, wizard, parent):
  1073. TitledPage.__init__(self, wizard, _("Units"))
  1074. self.parent = parent
  1075. self.scrollPanel = scrolled.ScrolledPanel(parent=self, id=wx.ID_ANY)
  1076. self.scrollPanel.SetupScrolling(scroll_x=False)
  1077. self.panelSizer = wx.GridBagSizer(5, 5)
  1078. self.width = ''
  1079. self.height = ''
  1080. self.boxtype = 'rectangle'
  1081. self.distrtype = 'non_overlapping'
  1082. # type of shape
  1083. self.typeBox = wx.RadioBox(parent=self.scrollPanel, id=wx.ID_ANY,
  1084. majorDimension=1, style=wx.RA_SPECIFY_COLS,
  1085. label=" %s " % _("Select type of shape"),
  1086. choices=[_('Rectangle'), _('Circle')])
  1087. self.panelSizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
  1088. span=(1, 2))
  1089. self.widthLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
  1090. self.widthTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1091. size=(250, -1))
  1092. self.panelSizer.Add(item=self.widthLabel, pos=(1, 0),
  1093. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1094. self.panelSizer.Add(item=self.widthTxt, pos=(1, 1),
  1095. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1096. self.heightLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
  1097. self.heightTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1098. size=(250, -1))
  1099. self.panelSizer.Add(item=self.heightLabel, pos=(2, 0),
  1100. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1101. self.panelSizer.Add(item=self.heightTxt, pos=(2, 1),
  1102. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1103. self.widthLabels = [_('Width size (in cells)? '),
  1104. _('What radius size (in meters)? ')]
  1105. self.heightLabels = [_('Height size (in cells)? '),
  1106. _('Name of the circle mask')]
  1107. self.distributionBox = wx.RadioBox(parent=self.scrollPanel,
  1108. id=wx.ID_ANY,
  1109. majorDimension=1,
  1110. style=wx.RA_SPECIFY_COLS,
  1111. label= " %s " % _("Select method of sampling unit distribution"),
  1112. choices=[_('Random non overlapping'),
  1113. _('Systematic contiguos'),
  1114. _('Stratified random'),
  1115. _('Systematic non contiguos'),
  1116. _('Centered over sites')]
  1117. )
  1118. self.distributionBox.EnableItem(5, False) # disable 'draw' for now
  1119. self.panelSizer.Add(item=self.distributionBox, pos=(3, 0), span=(1, 2),
  1120. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1121. self.distr1Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
  1122. label=_("What number of Sampling " \
  1123. "Units to use?"))
  1124. self.distr1Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1125. size=(250, -1))
  1126. self.panelSizer.Add(item=self.distr1Label, pos=(4, 0),
  1127. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1128. self.panelSizer.Add(item=self.distr1Txt, pos=(4, 1),
  1129. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1130. self.distr2Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
  1131. label="")
  1132. self.distr2Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1133. size=(250, -1))
  1134. self.panelSizer.Add(item=self.distr2Label, pos=(5, 0),
  1135. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1136. self.panelSizer.Add(item=self.distr2Txt, pos=(5, 1),
  1137. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1138. self.panelSizer.Hide(self.distr2Txt)
  1139. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  1140. self.distributionBox.Bind(wx.EVT_RADIOBOX, self.OnDistr)
  1141. self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
  1142. self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
  1143. self.distr1Txt.Bind(wx.EVT_TEXT, self.OnDistr1)
  1144. self.distr2Txt.Bind(wx.EVT_TEXT, self.OnDistr2)
  1145. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1146. self.sizer.Add(item=self.scrollPanel, pos=(0, 0), flag=wx.EXPAND)
  1147. self.sizer.AddGrowableCol(0)
  1148. self.sizer.AddGrowableRow(0)
  1149. self.scrollPanel.SetSizer(self.panelSizer)
  1150. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  1151. self.OnType(None)
  1152. def OnExitPage(self, event=None):
  1153. """!Function during exiting"""
  1154. if event.GetDirection():
  1155. self.SetNext(self.parent.summarypage)
  1156. self.SetPrev(self.parent.samplingareapage)
  1157. def OnType(self, event):
  1158. chosen = self.typeBox.GetSelection()
  1159. self.widthLabel.SetLabel(self.widthLabels[chosen])
  1160. self.heightLabel.SetLabel(self.heightLabels[chosen])
  1161. self.panelSizer.Layout()
  1162. if chosen == 0:
  1163. self.boxtype = 'rectangle'
  1164. else:
  1165. self.boxtype = 'circle'
  1166. def OnDistr(self, event):
  1167. chosen = self.distributionBox.GetSelection()
  1168. if chosen == 0:
  1169. self.distrtype = 'non_overlapping'
  1170. self.distr1Label.SetLabel(_("What number of Sampling Units to use?"))
  1171. self.panelSizer.Show(self.distr1Txt)
  1172. self.distr2Label.SetLabel("")
  1173. self.panelSizer.Hide(self.distr2Txt)
  1174. self.panelSizer.Layout()
  1175. elif chosen == 1:
  1176. self.distrtype = 'systematic_contiguos'
  1177. self.distr1Label.SetLabel("")
  1178. self.distr2Label.SetLabel("")
  1179. self.panelSizer.Hide(self.distr1Txt)
  1180. self.panelSizer.Hide(self.distr2Txt)
  1181. self.panelSizer.Layout()
  1182. elif chosen == 2:
  1183. self.distrtype = 'stratified_random'
  1184. self.distr1Label.SetLabel(_("Insert number of row strates"))
  1185. self.distr2Label.SetLabel(_("Insert number of column strates"))
  1186. self.panelSizer.Show(self.distr1Txt)
  1187. self.panelSizer.Show(self.distr2Txt)
  1188. self.panelSizer.Layout()
  1189. elif chosen == 3:
  1190. self.distrtype = 'systematic_noncontiguos'
  1191. self.distr1Label.SetLabel(_("Insert distance between units"))
  1192. self.panelSizer.Show(self.distr1Txt)
  1193. self.distr2Label.SetLabel("")
  1194. self.panelSizer.Hide(self.distr2Txt)
  1195. self.panelSizer.Layout()
  1196. elif chosen == 4:
  1197. self.distrtype = 'centered_oversites'
  1198. self.distr1Label.SetLabel("")
  1199. self.distr2Label.SetLabel("")
  1200. self.panelSizer.Hide(self.distr2Txt)
  1201. self.panelSizer.Hide(self.distr1Txt)
  1202. self.panelSizer.Layout()
  1203. def OnWidth(self, event):
  1204. self.width = event.GetString()
  1205. def OnHeight(self, event):
  1206. self.height = event.GetString()
  1207. def OnDistr1(self, event):
  1208. self.distr1 = event.GetString()
  1209. def OnDistr2(self, event):
  1210. self.distr2 = event.GetString()
  1211. class MovingWindows(TitledPage):
  1212. """!Set values from keyboard for sample units"""
  1213. def __init__(self, wizard, parent):
  1214. TitledPage.__init__(self, wizard, _("Units"))
  1215. self.parent = parent
  1216. self.sizer.AddGrowableCol(2)
  1217. self.width = ''
  1218. self.height = ''
  1219. self.boxtype = ''
  1220. # type of shape
  1221. self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  1222. label=" %s " % _("Select type of shape"),
  1223. choices=[_('Rectangle'), _('Circle')],
  1224. majorDimension=1,
  1225. style=wx.RA_SPECIFY_COLS)
  1226. self.sizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(1, 1))
  1227. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  1228. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1229. self.widthLabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1230. label=_('Width size (in cells) ?'))
  1231. self.widthTxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  1232. self.sizer.Add(item=self.widthLabel, border=5, pos=(2, 1),
  1233. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1234. self.sizer.Add(item=self.widthTxt, border=5, pos=(2, 2),
  1235. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1236. self.heightLabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1237. label=_('Height size (in cells) ?'))
  1238. self.heightTxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  1239. self.sizer.Add(item=self.heightLabel, border=5, pos=(3, 1),
  1240. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1241. self.sizer.Add(item=self.heightTxt, border=5, pos=(3, 2),
  1242. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1243. self.widthLabels = [_('Width size (in cells)? '),
  1244. _('What radius size (in meters)? ')]
  1245. self.heightLabels = [_('Height size (in cells)? '),
  1246. _('Name of the circle mask')]
  1247. self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
  1248. self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
  1249. def OnEnterPage(self, event):
  1250. self.OnType(None)
  1251. def OnType(self, event):
  1252. chosen = self.typeBox.GetSelection()
  1253. self.widthLabel.SetLabel(self.widthLabels[chosen])
  1254. self.heightLabel.SetLabel(self.heightLabels[chosen])
  1255. self.sizer.Layout()
  1256. if chosen == 0:
  1257. self.boxtype = 'rectangle'
  1258. else:
  1259. self.boxtype = 'circle'
  1260. def OnWidth(self, event):
  1261. self.width = event.GetString()
  1262. def OnHeight(self, event):
  1263. self.height = event.GetString()
  1264. class SummaryPage(TitledPage):
  1265. """!Shows summary result of choosing data"""
  1266. def __init__(self, wizard, parent):
  1267. TitledPage.__init__(self, wizard, _("Summary"))
  1268. global rlisettings
  1269. self.parent = parent
  1270. self.sizer.AddGrowableCol(2)
  1271. #configuration file name
  1272. self.conflabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1273. label=_('Configuration file name:'))
  1274. self.conftxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1275. label="")
  1276. self.sizer.Add(item=self.conflabel, border=5, pos=(0, 0),
  1277. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1278. self.sizer.Add(item=self.conftxt, border=5, pos=(0, 1),
  1279. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1280. #raster name
  1281. self.rastlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1282. label=_('Raster name:'))
  1283. self.rasttxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1284. label="")
  1285. self.sizer.Add(item=self.rastlabel, border=5, pos=(1, 0),
  1286. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1287. self.sizer.Add(item=self.rasttxt, border=5, pos=(1, 1),
  1288. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1289. #vector name
  1290. self.vectlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1291. label=_('Vector name:'))
  1292. self.vecttxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1293. label="")
  1294. self.sizer.Add(item=self.vectlabel, border=5, pos=(2, 0),
  1295. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1296. self.sizer.Add(item=self.vecttxt, border=5, pos=(2, 1),
  1297. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1298. #region type name
  1299. self.regionlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1300. label=_('Region type:'))
  1301. self.regiontxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1302. label="")
  1303. self.sizer.Add(item=self.regionlabel, border=5, pos=(3, 0),
  1304. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1305. self.sizer.Add(item=self.regiontxt, border=5, pos=(3, 1),
  1306. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1307. #region keyboard
  1308. self.regionkeylabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1309. label="")
  1310. self.regionkeytxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1311. label="")
  1312. self.sizer.Add(item=self.regionkeylabel, border=5, pos=(4, 0),
  1313. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1314. self.sizer.Add(item=self.regionkeytxt, border=5, pos=(4, 1),
  1315. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1316. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1317. #sampling area
  1318. self.samplinglabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1319. label=_('Sampling area type:'))
  1320. self.samplingtxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1321. label="")
  1322. self.sizer.Add(item=self.samplinglabel, border=5, pos=(5, 0),
  1323. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1324. self.sizer.Add(item=self.samplingtxt, border=5, pos=(5, 1),
  1325. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1326. #shapetype
  1327. self.shapelabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1328. label="")
  1329. self.shapetxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1330. label="")
  1331. self.sizer.Add(item=self.shapelabel, border=5, pos=(6, 0),
  1332. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1333. self.sizer.Add(item=self.shapetxt, border=5, pos=(6, 1),
  1334. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1335. #shapedim
  1336. self.shapewidthlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1337. label="")
  1338. self.shapewidthtxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1339. label="")
  1340. self.sizer.Add(item=self.shapewidthlabel, border=5, pos=(7, 0),
  1341. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1342. self.sizer.Add(item=self.shapewidthtxt, border=5, pos=(7, 1),
  1343. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1344. self.shapeheightlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1345. label="")
  1346. self.shapeheighttxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1347. label="")
  1348. self.sizer.Add(item=self.shapeheightlabel, border=5, pos=(8, 0),
  1349. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1350. self.sizer.Add(item=self.shapeheighttxt, border=5, pos=(8, 1),
  1351. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1352. #units type
  1353. self.unitslabel = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1354. self.unitstxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1355. self.sizer.Add(item=self.unitslabel, border=5, pos=(9, 0),
  1356. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1357. self.sizer.Add(item=self.unitstxt, border=5, pos=(9, 1),
  1358. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1359. self.unitsmorelabel = wx.StaticText(parent=self, id=wx.ID_ANY,
  1360. label="")
  1361. self.unitsmoretxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1362. self.sizer.Add(item=self.unitsmorelabel, border=5, pos=(10, 0),
  1363. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1364. self.sizer.Add(item=self.unitsmoretxt, border=5, pos=(10, 1),
  1365. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1366. self.unitsmorelabel2 = wx.StaticText(parent=self, id=wx.ID_ANY,
  1367. label="")
  1368. self.unitsmoretxt2 = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
  1369. self.sizer.Add(item=self.unitsmorelabel2, border=5, pos=(11, 0),
  1370. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1371. self.sizer.Add(item=self.unitsmoretxt2, border=5, pos=(11, 1),
  1372. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1373. def OnEnterPage(self, event):
  1374. """!Insert values into text controls for summary of location
  1375. creation options
  1376. """
  1377. self.conftxt.SetLabel(self.parent.startpage.conf_name)
  1378. self.rasttxt.SetLabel(self.parent.startpage.rast)
  1379. self.samplingtxt.SetLabel(self.parent.samplingareapage.samplingtype)
  1380. self.regiontxt.SetLabel(self.parent.startpage.region)
  1381. self.vecttxt.SetLabel(self.parent.startpage.vect)
  1382. if self.parent.startpage.region == 'key':
  1383. #region keyboard values
  1384. self.regionkeylabel.SetLabel(_('Region keyboard values:'))
  1385. regKeyVals = "Column left up: %s - Row left up: %s\n" \
  1386. "Column length: %s - Row length: %s\n" % (
  1387. self.parent.keyboardpage.col_up,
  1388. self.parent.keyboardpage.row_up,
  1389. self.parent.keyboardpage.col_len,
  1390. self.parent.keyboardpage.row_len)
  1391. self.regionkeytxt.SetLabel(regKeyVals)
  1392. else:
  1393. self.regionkeylabel.SetLabel("")
  1394. self.regionkeytxt.SetLabel("")
  1395. if self.parent.samplingareapage.samplingtype == SamplingType.UNITS \
  1396. and self.parent.samplingareapage.regionbox=='keyboard':
  1397. self.shapelabel.SetLabel(_('Type of shape:'))
  1398. self.shapetxt.SetLabel(self.parent.units.boxtype)
  1399. if self.parent.units.boxtype == 'circle':
  1400. self.shapewidthlabel.SetLabel(_("Radius size:"))
  1401. self.shapeheightlabel.SetLabel(_("Name circle mask:"))
  1402. else:
  1403. self.shapewidthlabel.SetLabel(_("Width size:"))
  1404. self.shapeheightlabel.SetLabel(_("Heigth size:"))
  1405. self.shapewidthtxt.SetLabel(self.parent.units.width)
  1406. self.shapeheighttxt.SetLabel(self.parent.units.height)
  1407. self.unitslabel.SetLabel(_("Method of distribution:"))
  1408. self.unitstxt.SetLabel(self.parent.units.distrtype)
  1409. if self.parent.units.distrtype == 'non_overlapping':
  1410. self.unitsmorelabel.SetLabel(_("Number sampling units:"))
  1411. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1412. elif self.parent.units.distrtype == 'systematic_noncontiguos':
  1413. self.unitsmorelabel.SetLabel(_("Distance between units:"))
  1414. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1415. elif self.parent.units.distrtype == 'stratified_random':
  1416. self.unitsmorelabel.SetLabel(_("Number row strates:"))
  1417. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1418. self.unitsmorelabel2.SetLabel(_("Number column strates:"))
  1419. self.unitsmoretxt2.SetLabel(self.parent.units.distr2)
  1420. elif self.parent.samplingareapage.samplingtype == SamplingType.UNITS \
  1421. and self.parent.samplingareapage.regionbox == 'mouse':
  1422. self.shapelabel.SetLabel(_('Type of shape:'))
  1423. self.shapetxt.SetLabel(self.parent.units.boxtype)
  1424. self.unitstxt.SetLabel('by mouse')
  1425. elif self.parent.samplingareapage.samplingtype == 'moving':
  1426. self.shapelabel.SetLabel(_('Type of shape:'))
  1427. self.shapetxt.SetLabel(self.parent.moving.boxtype)
  1428. if self.parent.moving.boxtype == 'circle':
  1429. self.shapewidthlabel.SetLabel(_("Radius size:"))
  1430. self.shapeheightlabel.SetLabel(_("Name circle mask:"))
  1431. else:
  1432. self.shapewidthlabel.SetLabel(_("Width size:"))
  1433. self.shapeheightlabel.SetLabel(_("Heigth size:"))
  1434. self.shapewidthtxt.SetLabel(self.parent.moving.width)
  1435. self.shapeheighttxt.SetLabel(self.parent.moving.height)
  1436. else:
  1437. self.shapelabel.SetLabel("")
  1438. self.shapetxt.SetLabel("")
  1439. self.shapewidthlabel.SetLabel("")
  1440. self.shapewidthtxt.SetLabel("")
  1441. self.shapeheightlabel.SetLabel("")
  1442. self.shapeheighttxt.SetLabel("")