wizard.py 83 KB

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