wizard.py 83 KB

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