wizard.py 83 KB

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