wizard.py 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  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._cleanup()
  117. self.wizard.Destroy()
  118. GMessage(parent=self.parent,
  119. message=_("r.li.setup wizard canceled. "
  120. "Configuration file not created."))
  121. def _write_confile(self):
  122. """Write the configuration file"""
  123. f = open(os.path.join(self.rlipath, self.startpage.conf_name), 'w')
  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.units.width) / float(self.rasterinfo['cols'])
  333. rl = float(self.units.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. for page in (self.drawsampleframepage,
  439. self.regions,
  440. self.drawsampleunitspage,
  441. self.vectorareas):
  442. if page.mapPanel:
  443. page.mapPanel._mgr.UnInit()
  444. class FirstPage(TitledPage):
  445. """
  446. !Set name of configuration file, choose raster and optionally vector/sites
  447. """
  448. def __init__(self, wizard, parent):
  449. TitledPage.__init__(self, wizard, _("Select maps and define name"))
  450. self.region = 'whole'
  451. self.rast = ''
  452. self.conf_name = ''
  453. self.vect = ''
  454. self.VectorEnabled = True
  455. self.parent = parent
  456. # name of output configuration file
  457. self.newconflabel = StaticText(
  458. parent=self, id=wx.ID_ANY,
  459. label=_('Name for new configuration file to create'))
  460. self.newconftxt = TextCtrl(parent=self, id=wx.ID_ANY,
  461. size=(250, -1))
  462. wx.CallAfter(self.newconftxt.SetFocus)
  463. self.sizer.Add(self.newconflabel, border=5, pos=(0, 0),
  464. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  465. self.sizer.Add(self.newconftxt, border=5, pos=(0, 1),
  466. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  467. # raster
  468. self.mapsellabel = StaticText(
  469. parent=self, id=wx.ID_ANY,
  470. label=_('Raster map to use to select areas'))
  471. self.mapselect = gselect.Select(parent=self, id=wx.ID_ANY,
  472. size=(250, -1), type='cell',
  473. multiple=False)
  474. self.sizer.Add(self.mapsellabel, border=5, pos=(1, 0),
  475. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  476. self.sizer.Add(self.mapselect, border=5, pos=(1, 1),
  477. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  478. # vector
  479. self.vectsellabel = StaticText(
  480. parent=self, id=wx.ID_ANY,
  481. label=_('Vector map to use to select areas'))
  482. self.vectselect = gselect.Select(parent=self, id=wx.ID_ANY,
  483. size=(250, -1), type='vector',
  484. multiple=False)
  485. self.sizer.Add(self.vectsellabel, border=5, pos=(2, 0),
  486. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  487. self.sizer.Add(self.vectselect, border=5, pos=(2, 1),
  488. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  489. # vector layer
  490. self.vectlaylabel = StaticText(
  491. parent=self, id=wx.ID_ANY,
  492. label=_('Vector map layer to use to select areas'))
  493. self.vectlayer = wx.ComboBox(parent=self, id=wx.ID_ANY,
  494. size=(250, -1))
  495. self.sizer.Add(self.vectlaylabel, border=5, pos=(3, 0),
  496. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  497. self.sizer.Add(self.vectlayer, border=5, pos=(3, 1),
  498. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  499. # define sampling region
  500. self.sampling_reg = wx.RadioBox(
  501. parent=self,
  502. id=wx.ID_ANY,
  503. label=" %s " % _(
  504. "Define sampling "
  505. "region (region for analysis)"),
  506. choices=[
  507. _('Whole map layer'),
  508. _('Keyboard setting'),
  509. _('Draw the sampling frame')],
  510. majorDimension=1,
  511. style=wx.RA_SPECIFY_ROWS)
  512. self.sizer.Add(self.sampling_reg,
  513. flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
  514. pos=(5, 0), span=(1, 2))
  515. self.infoError = StaticText(self, label='')
  516. self.infoError.SetForegroundColour(wx.RED)
  517. self.sizer.Add(self.infoError,
  518. flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
  519. pos=(6, 0), span=(1, 2))
  520. # bindings
  521. self.sampling_reg.Bind(wx.EVT_RADIOBOX, self.OnSampling)
  522. self.newconftxt.Bind(wx.EVT_KILL_FOCUS, self.OnName)
  523. self.newconftxt.Bind(wx.EVT_TEXT, self.OnNameChanged)
  524. self.vectselect.Bind(wx.EVT_TEXT, self.OnVector)
  525. self.mapselect.Bind(wx.EVT_TEXT, self.OnRast)
  526. self.vectlayer.Bind(wx.EVT_TEXT, self.OnLayer)
  527. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  528. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  529. wx.CallAfter(wx.FindWindowById(wx.ID_FORWARD).Enable, False)
  530. def OnSampling(self, event):
  531. """Change region type"""
  532. if event.GetInt() == 0:
  533. self.region = 'whole'
  534. self.SetNext(self.parent.samplingareapage)
  535. elif event.GetInt() == 1:
  536. self.region = 'key'
  537. self.SetNext(self.parent.keyboardpage)
  538. elif event.GetInt() == 2: # currently disabled
  539. self.region = 'draw'
  540. self.SetNext(self.parent.drawsampleframepage)
  541. def OnName(self, event):
  542. """Sets the name of configuration file"""
  543. if self.conf_name in self.parent.parent.listfiles:
  544. GMessage(
  545. parent=self, message=_(
  546. "The configuration file %s "
  547. "already exists, please change name") %
  548. self.conf_name)
  549. self.newconftxt.SetValue('')
  550. self.conf_name = ''
  551. def OnNameChanged(self, event):
  552. """Name of configuration file has changed"""
  553. self.conf_name = self.newconftxt.GetValue()
  554. next = wx.FindWindowById(wx.ID_FORWARD)
  555. next.Enable(self.CheckInput())
  556. def OnRast(self, event):
  557. """Sets raster map"""
  558. self.rast = self.mapselect.GetValue()
  559. next = wx.FindWindowById(wx.ID_FORWARD)
  560. next.Enable(self.CheckInput())
  561. def OnVector(self, event):
  562. """Sets vector map"""
  563. self.vect = self.vectselect.GetValue()
  564. if self.vect:
  565. self.VectorEnabled, layers = self.CheckVector(self.vect)
  566. if self.VectorEnabled:
  567. self.vectlayer.SetItems(layers)
  568. self.vectlayer.SetSelection(0)
  569. self.vectorlayer = self.vectlayer.GetValue()
  570. self.infoError.SetLabel('')
  571. else:
  572. self.vectlayer.Clear()
  573. self.vectlayer.SetValue('')
  574. self.vect = ''
  575. else:
  576. self.infoError.SetLabel('')
  577. self.vectlayer.Clear()
  578. self.vectlayer.SetValue('')
  579. next = wx.FindWindowById(wx.ID_FORWARD)
  580. next.Enable(self.CheckInput())
  581. def OnLayer(self, event):
  582. try:
  583. self.vectorlayer = self.vectlayer.GetValue()
  584. except:
  585. self.vectorlayer = None
  586. next = wx.FindWindowById(wx.ID_FORWARD)
  587. next.Enable(self.CheckInput())
  588. def OnEnterPage(self, event):
  589. """Sets the default values, for the entire map
  590. """
  591. next = wx.FindWindowById(wx.ID_FORWARD)
  592. next.Enable(self.CheckInput())
  593. wx.CallAfter(wx.FindWindowById(wx.ID_FORWARD).Enable,
  594. self.CheckInput())
  595. def CheckVector(self, vector):
  596. """Check if the type of vector is area and return the number of
  597. vector's layer"""
  598. try:
  599. areas = gvect.vector_info_topo(vector)['areas']
  600. except CalledModuleError:
  601. self.infoError.SetLabel(_("Vector %s was not found, please "
  602. "select another vector") % vector)
  603. return False, []
  604. if areas == 0:
  605. self.infoError.SetLabel(_("Vector %s has no areas, please "
  606. "select another vector") % vector)
  607. return False, []
  608. links = gvect.vector_info(vector)['num_dblinks']
  609. if links == 0:
  610. self.infoError.SetLabel(_("Vector %s has no table connected, "
  611. "please select another vector") % vector)
  612. return False, []
  613. elif links > 0:
  614. layers = []
  615. for i in range(1, links + 1):
  616. layers.append(str(i))
  617. return True, layers
  618. else:
  619. return False, []
  620. def CheckInput(self):
  621. """Check input fields.
  622. :return: True if configuration file is given and raster xor vector map,
  623. False otherwise
  624. """
  625. return bool(self.conf_name and bool(self.rast and
  626. bool(self.VectorEnabled)))
  627. def OnExitPage(self, event=None):
  628. """Function during exiting"""
  629. next = wx.FindWindowById(wx.ID_FORWARD)
  630. next.Enable(self.CheckInput())
  631. if event.GetDirection():
  632. if self.region == 'key':
  633. self.SetNext(self.parent.keyboardpage)
  634. self.parent.samplingareapage.SetPrev(self.parent.keyboardpage)
  635. elif self.region == 'whole':
  636. self.SetNext(self.parent.samplingareapage)
  637. self.parent.samplingareapage.SetPrev(self)
  638. elif self.region == 'draw':
  639. self.SetNext(self.parent.drawsampleframepage)
  640. self.parent.samplingareapage.SetPrev(
  641. self.parent.drawsampleframepage)
  642. return
  643. class KeyboardPage(TitledPage):
  644. """
  645. !Choose the region setting the values of border using the keyboard
  646. """
  647. def __init__(self, wizard, parent):
  648. TitledPage.__init__(self, wizard, _("Insert sampling frame parameter"))
  649. self.parent = parent
  650. self.col_len = ''
  651. self.row_len = ''
  652. self.col_up = '0'
  653. self.row_up = '0'
  654. # column up/left
  655. self.ColUpLeftlabel = StaticText(parent=self, id=wx.ID_ANY,
  656. label=_("Column of upper left "
  657. "corner"))
  658. self.ColUpLefttxt = TextCtrl(parent=self, id=wx.ID_ANY,
  659. size=(250, -1))
  660. wx.CallAfter(self.ColUpLeftlabel.SetFocus)
  661. self.sizer.Add(self.ColUpLeftlabel, border=5, pos=(1, 1),
  662. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  663. self.sizer.Add(self.ColUpLefttxt, border=5, pos=(1, 2),
  664. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  665. self.sizer.AddGrowableCol(2)
  666. # row up/left
  667. self.RowUpLeftlabel = StaticText(
  668. parent=self, id=wx.ID_ANY, label=_('Row of upper left corner'))
  669. self.RowUpLefttxt = TextCtrl(parent=self, id=wx.ID_ANY,
  670. size=(250, -1))
  671. wx.CallAfter(self.RowUpLeftlabel.SetFocus)
  672. self.sizer.Add(self.RowUpLeftlabel, border=5, pos=(2, 1),
  673. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  674. self.sizer.Add(self.RowUpLefttxt, border=5, pos=(2, 2),
  675. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  676. # row length
  677. self.RowLenlabel = StaticText(
  678. parent=self,
  679. id=wx.ID_ANY,
  680. label=_('Row length of sampling frame'))
  681. self.RowLentxt = TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  682. wx.CallAfter(self.RowLenlabel.SetFocus)
  683. self.sizer.Add(self.RowLenlabel, border=5, pos=(3, 1),
  684. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  685. self.sizer.Add(self.RowLentxt, border=5, pos=(3, 2),
  686. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  687. # column length
  688. self.ColLenlabel = StaticText(
  689. parent=self,
  690. id=wx.ID_ANY,
  691. label=_('Row length of sampling frame'))
  692. self.ColLentxt = TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  693. wx.CallAfter(self.ColLenlabel.SetFocus)
  694. self.sizer.Add(self.ColLenlabel, border=5, pos=(4, 1),
  695. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  696. self.sizer.Add(self.ColLentxt, border=5, pos=(4, 2),
  697. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  698. self.ColUpLefttxt.SetValue(self.col_up)
  699. self.RowUpLefttxt.SetValue(self.row_up)
  700. self.ColUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLeft)
  701. self.RowUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLeft)
  702. self.ColLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLen)
  703. self.RowLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLen)
  704. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  705. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  706. def OnColLeft(self, event):
  707. """Sets the name of configuration file"""
  708. self.col_up = self.ColUpLefttxt.GetValue()
  709. checkValue(self.col_up)
  710. def OnRowLeft(self, event):
  711. """Sets the name of configuration file"""
  712. self.row_up = self.RowUpLefttxt.GetValue()
  713. checkValue(self.row_up)
  714. def OnColLen(self, event):
  715. """Sets the name of configuration file"""
  716. self.col_len = self.ColLentxt.GetValue()
  717. checkValue(self.col_len)
  718. def OnRowLen(self, event):
  719. """Sets the name of configuration file"""
  720. self.row_len = self.RowLentxt.GetValue()
  721. checkValue(self.row_len)
  722. def OnEnterPage(self, event):
  723. """Sets the default values, for the entire map
  724. """
  725. # R# check if raster exists before anything
  726. if self.col_len == '' and self.row_len == '':
  727. rastinfo = grast.raster_info(self.parent.startpage.rast)
  728. self.col_len = rastinfo['cols']
  729. self.row_len = rastinfo['rows']
  730. self.ColLentxt.SetValue(self.col_len)
  731. self.RowLentxt.SetValue(self.row_len)
  732. def OnExitPage(self, event=None):
  733. """Function during exiting"""
  734. if self.row_len == '' or self.col_len == '' or self.row_up == '' or self.col_up == '':
  735. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  736. else:
  737. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  738. class DrawSampleFramePage(TitledPage):
  739. """Choose the region setting the values drawing a box"""
  740. def __init__(self, wizard, parent):
  741. TitledPage.__init__(self, wizard, _("Draw sampling frame"))
  742. self.parent = parent
  743. self.mapPanel = None
  744. self.tregion = None
  745. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  746. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  747. def SampleFrameChanged(self, region):
  748. """"Enables the next dialog when region is set"""
  749. if region:
  750. self.tregion = region
  751. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  752. else:
  753. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  754. def OnEnterPage(self, event):
  755. """Function during entering"""
  756. if self.mapPanel is None:
  757. self.mapPanel = RLiSetupMapPanel(self, samplingType='drawFrame')
  758. self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
  759. self.sizer.Add(self.mapPanel, flag=wx.EXPAND, pos=(0, 0))
  760. self.sizer.AddGrowableCol(0)
  761. self.sizer.AddGrowableRow(0)
  762. self._raster = None
  763. else:
  764. self.mapPanel._region = {}
  765. self.SampleFrameChanged(region=None)
  766. rast = self.parent.startpage.rast
  767. if self._raster != rast:
  768. map_ = self.mapPanel.GetMap()
  769. map_.DeleteAllLayers()
  770. cmdlist = ['d.rast', 'map=%s' % rast]
  771. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  772. name=rast, hidden=False, opacity=1.0, render=True)
  773. def OnExitPage(self, event=None):
  774. """Function during exiting"""
  775. if event.GetDirection():
  776. self.SetNext(self.parent.samplingareapage)
  777. self.parent.samplingareapage.SetPrev(self)
  778. else:
  779. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  780. class SamplingAreasPage(TitledPage):
  781. """
  782. Set name of configuration file, choose raster and optionally vector/sites.
  783. This is coming after choose the region
  784. """
  785. def __init__(self, wizard, parent):
  786. TitledPage.__init__(self, wizard, _("Insert sampling areas"))
  787. self.samplingtype = 'whole'
  788. self.parent = parent
  789. self.overwriteTemp = False
  790. # toggles
  791. self.radioBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  792. label="",
  793. choices=[_("Whole map layer"),
  794. _("Regions"),
  795. _("Sample units"),
  796. _("Moving window"),
  797. _("Select areas from the\n"
  798. "overlaid vector map")],
  799. majorDimension=1,
  800. style=wx.RA_SPECIFY_COLS | wx.NO_BORDER)
  801. # layout
  802. self.sizer.SetVGap(10)
  803. self.sizer.Add(self.radioBox, flag=wx.ALIGN_LEFT, pos=(0, 0))
  804. self.regionBox = wx.RadioBox(
  805. parent=self,
  806. id=wx.ID_ANY,
  807. label=_("Choose a method"),
  808. choices=[
  809. _('Use keyboard to enter sampling area'),
  810. _('Use mouse to draw sampling area')],
  811. majorDimension=1,
  812. style=wx.RA_SPECIFY_ROWS)
  813. #self.regionBox.EnableItem(1, False)
  814. self.regionBox.SetItemToolTip(1, _("This option is not supported yet"))
  815. self.sizer.Add(self.regionBox, flag=wx.ALIGN_CENTER, pos=(1, 0))
  816. # bindings
  817. self.radioBox.Bind(wx.EVT_RADIOBOX, self.SetVal)
  818. self.regionBox.Bind(wx.EVT_RADIOBOX, self.OnRegionDraw)
  819. self.regionbox = 'keyboard'
  820. self.regionPanelSizer = wx.GridBagSizer(1, 2)
  821. self.regionNumPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  822. self.regionNumLabel = StaticText(
  823. parent=self.regionNumPanel, id=wx.ID_ANY,
  824. label=_('Number of regions to draw:'))
  825. self.regionNumTxt = TextCtrl(parent=self.regionNumPanel,
  826. id=wx.ID_ANY, size=(50, -1))
  827. self.regionPanelSizer.Add(self.regionNumLabel, flag=wx.ALIGN_CENTER,
  828. pos=(0, 0))
  829. self.regionPanelSizer.Add(self.regionNumTxt, flag=wx.ALIGN_CENTER,
  830. pos=(0, 1))
  831. self.regionNumPanel.SetSizer(self.regionPanelSizer)
  832. self.sizer.Add(self.regionNumPanel, flag=wx.ALIGN_CENTER, pos=(2, 0))
  833. self.areaPanelSizer = wx.GridBagSizer(2, 3)
  834. self.areaPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  835. self.overwriteText = StaticText(
  836. parent=self.areaPanel, id=wx.ID_ANY, label=_(
  837. 'Do you want to overwrite existing'
  838. ' temporal maps if they exist?'))
  839. self.overwriteCheck = wx.CheckBox(parent=self.areaPanel, id=wx.ID_ANY)
  840. self.areaText = StaticText(
  841. parent=self.areaPanel, id=wx.ID_ANY,
  842. label=_('Do you want to check vector areas?'))
  843. self.areaOK = Button(self.areaPanel, wx.ID_ANY, 'Yes', (50, 80))
  844. self.areaOK.SetToolTip(_("Select if use area by area"))
  845. self.areaNO = Button(self.areaPanel, wx.ID_ANY, 'No', (50, 80))
  846. self.areaNO.SetToolTip(_("All the features will be used"))
  847. self.areaOK.Bind(wx.EVT_BUTTON, self.OnVectYes)
  848. self.areaNO.Bind(wx.EVT_BUTTON, self.OnVectNo)
  849. self.overwriteCheck.Bind(wx.EVT_CHECKBOX, self.OnOverwrite)
  850. self.areaPanelSizer.Add(self.overwriteText, flag=wx.ALIGN_CENTER,
  851. pos=(0, 0))
  852. self.areaPanelSizer.Add(self.overwriteCheck, flag=wx.ALIGN_CENTER,
  853. pos=(0, 1))
  854. self.areaPanelSizer.Add(self.areaText, flag=wx.ALIGN_CENTER,
  855. pos=(1, 0))
  856. self.areaPanelSizer.Add(self.areaOK, flag=wx.ALIGN_CENTER, pos=(1, 1))
  857. self.areaPanelSizer.Add(self.areaNO, flag=wx.ALIGN_CENTER, pos=(1, 2))
  858. self.areaPanel.SetSizer(self.areaPanelSizer)
  859. self.sizer.Add(self.areaPanel, flag=wx.ALIGN_CENTER, pos=(3, 0))
  860. self.calculatingAreas = StaticText(
  861. parent=self, id=wx.ID_ANY,
  862. label=_('Analysing all vector features...'))
  863. self.sizer.Add(self.calculatingAreas, flag=wx.ALIGN_CENTER, pos=(4, 0))
  864. self.numregions = ''
  865. self.regionNumTxt.Bind(wx.EVT_TEXT, self.OnNumRegions)
  866. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  867. def OnNumRegions(self, event):
  868. """Obtain the number of regions"""
  869. if self.regionNumTxt.GetValue():
  870. self.SetNext(self.parent.regions)
  871. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  872. self.numregions = self.regionNumTxt.GetValue()
  873. else:
  874. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  875. def OnEnterPage(self, event):
  876. """Insert values into text controls for summary of location
  877. creation options
  878. """
  879. self.SetVal(None)
  880. if self.parent.startpage.vect:
  881. self.radioBox.ShowItem(4, True)
  882. self.vect_data = []
  883. else:
  884. self.radioBox.ShowItem(4, False)
  885. self.sizer.Layout()
  886. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  887. def SetVal(self, event):
  888. """Choose method"""
  889. radio = self.radioBox.GetSelection()
  890. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  891. if radio == 0:
  892. self.samplingtype = SamplingType.WHOLE
  893. self.DrawNothing()
  894. elif radio == 1:
  895. self.samplingtype = SamplingType.REGIONS
  896. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  897. elif radio == 2:
  898. self.samplingtype = SamplingType.UNITS
  899. regtype = self.regionBox.GetSelection()
  900. self.RegionDraw(regtype)
  901. elif radio == 3:
  902. self.samplingtype = SamplingType.MVWIN
  903. regtype = self.regionBox.GetSelection()
  904. self.RegionDraw(regtype)
  905. elif radio == 4:
  906. self.samplingtype = SamplingType.VECT
  907. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  908. self.ShowExtraOptions(self.samplingtype)
  909. def ShowExtraOptions(self, samtype):
  910. """Show some extra options for some sampling type"""
  911. if samtype == SamplingType.REGIONS:
  912. self.sizer.Hide(self.regionBox)
  913. self.sizer.Hide(self.areaPanel)
  914. self.sizer.Hide(self.calculatingAreas)
  915. self.sizer.Show(self.regionNumPanel)
  916. elif samtype == SamplingType.UNITS or samtype == SamplingType.MVWIN:
  917. self.sizer.Hide(self.regionNumPanel)
  918. self.sizer.Hide(self.areaPanel)
  919. self.sizer.Hide(self.calculatingAreas)
  920. self.sizer.Show(self.regionBox)
  921. elif samtype == SamplingType.VECT:
  922. self.sizer.Hide(self.regionBox)
  923. self.sizer.Hide(self.regionNumPanel)
  924. self.sizer.Hide(self.calculatingAreas)
  925. self.sizer.Show(self.areaPanel)
  926. self.sizer.Layout()
  927. def OnRegionDraw(self, event):
  928. self.RegionDraw(event.GetInt())
  929. return
  930. def OnOverwrite(self, event):
  931. self.overwriteTemp = self.overwriteCheck.GetValue()
  932. return
  933. def OnVectYes(self, event):
  934. """The user choose to select the vector areas, this function set the
  935. next page to VectorAreasPage"""
  936. self.SetNext(self.parent.vectorareas)
  937. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  938. self.parent.wizard.ShowPage(self.parent.vectorareas)
  939. def OnVectNo(self, event):
  940. """The user choose to use all the vector areas, this function analyses
  941. all the vector areas and fill the msAreaList variable"""
  942. self.sizer.Show(self.calculatingAreas)
  943. self.sizer.Hide(self.regionNumPanel)
  944. self.sizer.Hide(self.regionBox)
  945. self.sizer.Hide(self.areaPanel)
  946. self.SetNext(self.parent.summarypage)
  947. vect_cats = obtainCategories(self.parent.startpage.vect,
  948. self.parent.startpage.vectorlayer)
  949. self._progressDlg = wx.ProgressDialog(
  950. title=_("Analysing vector"),
  951. message="Analysing vector",
  952. maximum=len(vect_cats),
  953. parent=self,
  954. style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_SMOOTH)
  955. self._progressDlgMax = len(vect_cats)
  956. grass.use_temp_region()
  957. self.parent.msAreaList = sampleAreaVector(
  958. self.parent.startpage.vect,
  959. self.parent.startpage.rast,
  960. vect_cats,
  961. self.parent.startpage.vectorlayer,
  962. self.overwriteTemp,
  963. self._progressDlg)
  964. grass.del_temp_region()
  965. if self.parent.msAreaList:
  966. self.calculatingAreas.SetLabel(_("All feature are been analyzed."))
  967. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  968. self.parent.wizard.ShowPage(self.parent.summarypage)
  969. else:
  970. self.calculatingAreas.SetLabel(_("An error occurred"))
  971. self._progressDlg.Destroy()
  972. self._progressDlg = None
  973. def RegionDraw(self, regtype):
  974. """Set the next page to units or drawunits"""
  975. if regtype == 0:
  976. self.regionbox = 'keyboard'
  977. if self.samplingtype == SamplingType.UNITS:
  978. self.SetNext(self.parent.units)
  979. elif self.samplingtype == SamplingType.MVWIN:
  980. self.SetNext(self.parent.moving)
  981. elif regtype == 1:
  982. self.regionbox = 'mouse'
  983. self.SetNext(self.parent.drawunits)
  984. def DrawNothing(self):
  985. """Remove all the optional choices. Used also when the wizard enter in
  986. SamplingAreasPage, all the optional choices should be hide here"""
  987. self.sizer.Hide(self.regionNumPanel)
  988. self.sizer.Hide(self.regionBox)
  989. self.sizer.Hide(self.areaPanel)
  990. self.sizer.Hide(self.calculatingAreas)
  991. self.sizer.Layout()
  992. self.SetNext(self.parent.summarypage)
  993. class DrawRegionsPage(TitledPage):
  994. def __init__(self, wizard, parent):
  995. self.parent = parent
  996. TitledPage.__init__(self, wizard, _("Draw sampling regions"))
  997. self.regioncount = 0
  998. self.mapPanel = None
  999. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1000. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  1001. def afterRegionDrawn(self, marea):
  1002. if marea:
  1003. self.parent.msAreaList.append(marea)
  1004. self.regioncount = self.regioncount + 1
  1005. numregions = int(self.parent.samplingareapage.numregions)
  1006. if self.regioncount > numregions:
  1007. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1008. self.parent.wizard.ShowPage(self.parent.summarypage)
  1009. else:
  1010. self.title.SetLabel(_('Draw sample region ' +
  1011. str(self.regioncount) + ' of ' +
  1012. str(numregions)))
  1013. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1014. def OnEnterPage(self, event):
  1015. """Function during entering"""
  1016. if self.parent.samplingareapage.samplingtype == SamplingType.WHOLE:
  1017. self.title.SetLabel(_("Draw moving windows region"))
  1018. elif self.parent.samplingareapage.samplingtype == SamplingType.UNITS:
  1019. self.title.SetLabel(_("Draw sampling region"))
  1020. if self.mapPanel is None:
  1021. self.mapPanel = RLiSetupMapPanel(
  1022. self, samplingType=self.parent.samplingareapage.samplingtype, )
  1023. self.mapPanel.afterRegionDrawn.connect(self.afterRegionDrawn)
  1024. self.sizer.Add(self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  1025. self.sizer.AddGrowableCol(0)
  1026. self.sizer.AddGrowableRow(1)
  1027. self._raster = None
  1028. rast = self.parent.startpage.rast
  1029. self.afterRegionDrawn(marea=None)
  1030. if self._raster != rast:
  1031. map_ = self.mapPanel.GetMap()
  1032. map_.DeleteAllLayers()
  1033. cmdlist = ['d.rast', 'map=%s' % rast]
  1034. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  1035. name=rast, hidden=False, opacity=1.0, render=True)
  1036. # def OnExitPage(self, event=None):
  1037. #!Function during exiting
  1038. # print event.GetDirection()
  1039. # if event.GetDirection():
  1040. # self.SetNext(self.parent.samplingareapage)
  1041. # self.parent.samplingareapage.SetPrev(self)
  1042. class SampleUnitsKeyPage(TitledPage):
  1043. """Set values from keyboard for sample units
  1044. It is used if you choose keyboard from Sampling Units or Moving windows
  1045. in sampling areas page
  1046. """
  1047. def __init__(self, wizard, parent):
  1048. TitledPage.__init__(self, wizard, _(
  1049. "Select sample units from keyboard"))
  1050. self.parent = parent
  1051. self.scrollPanel = scrolled.ScrolledPanel(parent=self, id=wx.ID_ANY)
  1052. self.scrollPanel.SetupScrolling(scroll_x=False)
  1053. self.panelSizer = wx.GridBagSizer(5, 5)
  1054. self.width = ''
  1055. self.height = ''
  1056. self.boxtype = 'rectangle'
  1057. self.distrtype = 'non_overlapping'
  1058. # type of shape
  1059. self.typeBox = wx.RadioBox(parent=self.scrollPanel, id=wx.ID_ANY,
  1060. majorDimension=1, style=wx.RA_SPECIFY_COLS,
  1061. label=" %s " % _("Select type of shape"),
  1062. choices=[_('Rectangle'), _('Circle'),
  1063. ('None')])
  1064. self.panelSizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
  1065. span=(1, 2))
  1066. self.widthLabel = StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
  1067. self.widthTxt = TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1068. size=(250, -1))
  1069. self.panelSizer.Add(
  1070. self.widthLabel, pos=(1, 0),
  1071. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1072. self.panelSizer.Add(
  1073. self.widthTxt, pos=(1, 1),
  1074. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1075. self.heightLabel = StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
  1076. self.heightTxt = TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1077. size=(250, -1))
  1078. self.panelSizer.Add(
  1079. self.heightLabel, pos=(2, 0),
  1080. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1081. self.panelSizer.Add(
  1082. self.heightTxt, pos=(2, 1),
  1083. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1084. self.widthLabels = [_('Width size (in cells)?'),
  1085. _('What radius size (in meters)?')]
  1086. self.heightLabels = [_('Height size (in cells)?'),
  1087. _('Name of the circle mask')]
  1088. self.distributionBox = wx.RadioBox(
  1089. parent=self.scrollPanel,
  1090. id=wx.ID_ANY,
  1091. majorDimension=1,
  1092. style=wx.RA_SPECIFY_COLS,
  1093. label=" %s " %
  1094. _("Select method of sampling unit distribution"),
  1095. choices=[
  1096. _('Random non overlapping'),
  1097. _('Systematic contiguos'),
  1098. _('Stratified random'),
  1099. _('Systematic non contiguos'),
  1100. _('Centered over sites')])
  1101. self.panelSizer.Add(self.distributionBox, pos=(3, 0), span=(
  1102. 1, 2), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1103. self.distr1Label = StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
  1104. label=_("What number of Sampling "
  1105. "Units to use?"))
  1106. self.distr1Txt = TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1107. size=(250, -1))
  1108. self.panelSizer.Add(
  1109. self.distr1Label, pos=(4, 0),
  1110. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1111. self.panelSizer.Add(
  1112. self.distr1Txt, pos=(4, 1),
  1113. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1114. self.distr2Label = StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
  1115. label="")
  1116. self.distr2Txt = TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
  1117. size=(250, -1))
  1118. self.panelSizer.Add(
  1119. self.distr2Label, pos=(5, 0),
  1120. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1121. self.panelSizer.Add(
  1122. self.distr2Txt, pos=(5, 1),
  1123. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1124. self.panelSizer.Hide(self.distr2Txt)
  1125. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  1126. self.distributionBox.Bind(wx.EVT_RADIOBOX, self.OnDistr)
  1127. self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
  1128. self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
  1129. self.distr1Txt.Bind(wx.EVT_TEXT, self.OnDistr1)
  1130. self.distr2Txt.Bind(wx.EVT_TEXT, self.OnDistr2)
  1131. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1132. self.sizer.Add(self.scrollPanel, pos=(0, 0), flag=wx.EXPAND)
  1133. self.sizer.AddGrowableCol(0)
  1134. self.sizer.AddGrowableRow(0)
  1135. self.scrollPanel.SetSizer(self.panelSizer)
  1136. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  1137. self.OnType(None)
  1138. def OnEnterPage(self, event=None):
  1139. """Function during entering"""
  1140. # This is an hack to force the user to choose Rectangle or Circle
  1141. self.typeBox.SetSelection(2),
  1142. self.typeBox.ShowItem(2, False)
  1143. self.panelSizer.Layout()
  1144. def OnExitPage(self, event=None):
  1145. """Function during exiting"""
  1146. if event.GetDirection():
  1147. self.SetNext(self.parent.summarypage)
  1148. self.SetPrev(self.parent.samplingareapage)
  1149. def OnType(self, event):
  1150. """Set if rectangle or circle will be used"""
  1151. chosen = self.typeBox.GetSelection()
  1152. self.widthLabel.SetLabel(self.widthLabels[chosen])
  1153. self.heightLabel.SetLabel(self.heightLabels[chosen])
  1154. self.panelSizer.Layout()
  1155. if chosen == 0:
  1156. self.boxtype = 'rectangle'
  1157. else:
  1158. self.boxtype = 'circle'
  1159. def OnDistr(self, event):
  1160. chosen = self.distributionBox.GetSelection()
  1161. if chosen == 0:
  1162. self.distrtype = 'non_overlapping'
  1163. self.distr1Label.SetLabel(
  1164. _("What number of Sampling Units to use?"))
  1165. self.panelSizer.Show(self.distr1Txt)
  1166. self.distr2Label.SetLabel("")
  1167. self.panelSizer.Hide(self.distr2Txt)
  1168. self.panelSizer.Layout()
  1169. elif chosen == 1:
  1170. self.distrtype = 'systematic_contiguos'
  1171. self.distr1Label.SetLabel("")
  1172. self.distr2Label.SetLabel("")
  1173. self.panelSizer.Hide(self.distr1Txt)
  1174. self.panelSizer.Hide(self.distr2Txt)
  1175. self.panelSizer.Layout()
  1176. elif chosen == 2:
  1177. self.distrtype = 'stratified_random'
  1178. self.distr1Label.SetLabel(_("Insert number of row strates"))
  1179. self.distr2Label.SetLabel(_("Insert number of column strates"))
  1180. self.panelSizer.Show(self.distr1Txt)
  1181. self.panelSizer.Show(self.distr2Txt)
  1182. self.panelSizer.Layout()
  1183. elif chosen == 3:
  1184. self.distrtype = 'systematic_noncontiguos'
  1185. self.distr1Label.SetLabel(_("Insert distance between units"))
  1186. self.panelSizer.Show(self.distr1Txt)
  1187. self.distr2Label.SetLabel("")
  1188. self.panelSizer.Hide(self.distr2Txt)
  1189. self.panelSizer.Layout()
  1190. elif chosen == 4:
  1191. self.distrtype = 'centered_oversites'
  1192. self.distr1Label.SetLabel("")
  1193. self.distr2Label.SetLabel("")
  1194. self.panelSizer.Hide(self.distr2Txt)
  1195. self.panelSizer.Hide(self.distr1Txt)
  1196. self.panelSizer.Layout()
  1197. def OnWidth(self, event):
  1198. self.width = self.widthTxt.GetValue()
  1199. def OnHeight(self, event):
  1200. self.height = self.heightTxt.GetValue()
  1201. def OnDistr1(self, event):
  1202. self.distr1 = self.distr1Txt.GetValue()
  1203. def OnDistr2(self, event):
  1204. self.distr2 = self.distr2Txt.GetValue()
  1205. class MovingKeyPage(TitledPage):
  1206. """Set values from keyboard for sample units"""
  1207. def __init__(self, wizard, parent):
  1208. TitledPage.__init__(self, wizard, _("Set sample units"))
  1209. self.parent = parent
  1210. self.width = ''
  1211. self.height = ''
  1212. self.boxtype = 'rectangle'
  1213. # type of shape
  1214. self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  1215. label=" %s " % _("Select type of shape"),
  1216. choices=[_('Rectangle'), _('Circle')],
  1217. # ('None')],
  1218. majorDimension=1,
  1219. style=wx.RA_SPECIFY_COLS)
  1220. self.sizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(1, 1))
  1221. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  1222. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1223. self.widthLabel = StaticText(parent=self, id=wx.ID_ANY,
  1224. label=_('Width size (in cells)?'))
  1225. self.widthTxt = TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  1226. self.sizer.Add(self.widthLabel, border=5, pos=(2, 1),
  1227. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1228. self.sizer.Add(self.widthTxt, border=5, pos=(2, 2),
  1229. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1230. self.heightLabel = StaticText(parent=self, id=wx.ID_ANY,
  1231. label=_('Height size (in cells)?'))
  1232. self.heightTxt = TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
  1233. self.sizer.Add(self.heightLabel, border=5, pos=(3, 1),
  1234. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1235. self.sizer.Add(self.heightTxt, border=5, pos=(3, 2),
  1236. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1237. self.sizer.AddGrowableCol(2)
  1238. self.widthLabels = [_('Width size (in cells)?'),
  1239. _('What radius size (in meters)?')]
  1240. self.heightLabels = [_('Height size (in cells)?'),
  1241. _('Name of the circle mask')]
  1242. self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
  1243. self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
  1244. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1245. def OnEnterPage(self, event):
  1246. # This is an hack to force the user to choose Rectangle or Circle
  1247. # self.typeBox.SetSelection(2),
  1248. # self.typeBox.ShowItem(2, False)
  1249. if self.parent.samplingareapage.samplingtype == SamplingType.MVWIN:
  1250. self.title.SetLabel(_("Set moving windows"))
  1251. self.OnType(None)
  1252. def OnType(self, event):
  1253. chosen = self.typeBox.GetSelection()
  1254. self.widthLabel.SetLabel(self.widthLabels[chosen])
  1255. self.heightLabel.SetLabel(self.heightLabels[chosen])
  1256. self.sizer.Layout()
  1257. if chosen == 0:
  1258. self.parent.samplingareapage.samplingtype = SamplingType.KMVWINR
  1259. self.boxtype = 'rectangle'
  1260. elif chosen == 1:
  1261. self.parent.samplingareapage.samplingtype = SamplingType.KMVWINC
  1262. self.boxtype = 'circle'
  1263. def CheckInput(self):
  1264. """Check input fields.
  1265. :return: True if configuration file is given and raster xor
  1266. vector map, False otherwise
  1267. """
  1268. return bool(self.width and bool(self.height))
  1269. def OnWidth(self, event):
  1270. self.width = self.widthTxt.GetValue()
  1271. next = wx.FindWindowById(wx.ID_FORWARD)
  1272. next.Enable(self.CheckInput())
  1273. def OnHeight(self, event):
  1274. self.height = self.heightTxt.GetValue()
  1275. next = wx.FindWindowById(wx.ID_FORWARD)
  1276. next.Enable(self.CheckInput())
  1277. class UnitsMousePage(TitledPage):
  1278. """Choose the sampling area setting the values using the mouse drawing the
  1279. areas with rectangle or circle. It is used both from 'Moving windows'
  1280. and 'Sample units'.
  1281. """
  1282. def __init__(self, wizard, parent):
  1283. self.parent = parent
  1284. self.wizard = wizard
  1285. TitledPage.__init__(self, self.wizard, _("Draw sampling units"))
  1286. self.numregions = ''
  1287. self.mapPanel = None
  1288. # type of shape
  1289. self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
  1290. majorDimension=1, style=wx.RA_SPECIFY_COLS,
  1291. label=" %s " % _("Select type of shape"),
  1292. choices=[_('Rectangle'), _('Circle'), ('')])
  1293. # This is an hack to force the user to choose Rectangle or Circle
  1294. self.typeBox.SetSelection(2),
  1295. self.typeBox.ShowItem(2, False)
  1296. self.sizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
  1297. span=(1, 2))
  1298. self.regionPanelSizer = wx.GridBagSizer(1, 2)
  1299. self.regionNumPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  1300. self.regionNumLabel = StaticText(
  1301. parent=self.regionNumPanel, id=wx.ID_ANY,
  1302. label=_('Number of sampling area to draw:'))
  1303. self.regionNumTxt = TextCtrl(parent=self.regionNumPanel,
  1304. id=wx.ID_ANY, size=(50, -1))
  1305. self.regionPanelSizer.Add(self.regionNumLabel, flag=wx.ALIGN_CENTER,
  1306. pos=(0, 0))
  1307. self.regionPanelSizer.Add(self.regionNumTxt, flag=wx.ALIGN_CENTER,
  1308. pos=(0, 1))
  1309. self.regionNumPanel.SetSizer(self.regionPanelSizer)
  1310. self.sizer.Add(self.regionNumPanel, flag=wx.ALIGN_LEFT, pos=(1, 0),
  1311. span=(1, 2))
  1312. self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
  1313. self.regionNumTxt.Bind(wx.EVT_TEXT, self.OnNumRegions)
  1314. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1315. self.sizer.AddGrowableCol(0)
  1316. self.OnType(None)
  1317. self.regionNumTxt.SetValue('')
  1318. def OnEnterPage(self, event):
  1319. """Function during entering"""
  1320. if self.numregions:
  1321. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1322. else:
  1323. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1324. if self.parent.samplingareapage.samplingtype in [SamplingType.MVWIN,
  1325. SamplingType.MMVWINR,
  1326. SamplingType.MMVWINC]:
  1327. self.title.SetLabel(_("Draw moving windows region"))
  1328. self.sizer.Hide(self.regionNumPanel)
  1329. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1330. elif self.parent.samplingareapage.samplingtype in [SamplingType.UNITS,
  1331. SamplingType.MUNITSR,
  1332. SamplingType.MUNITSC]:
  1333. self.title.SetLabel(_("Draw sampling region"))
  1334. self.sizer.Show(self.regionNumPanel)
  1335. if self.typeBox.GetSelection() == 2:
  1336. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1337. self.sizer.Layout()
  1338. def OnType(self, event):
  1339. chosen = self.typeBox.GetSelection()
  1340. if chosen == 0:
  1341. if self.parent.samplingareapage.samplingtype in [
  1342. SamplingType.MVWIN, SamplingType.MMVWINR, SamplingType.MMVWINC]:
  1343. self.parent.samplingareapage.samplingtype = SamplingType.MMVWINR
  1344. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1345. else:
  1346. self.parent.samplingareapage.samplingtype = SamplingType.MUNITSR
  1347. self.drawtype = 'rectangle'
  1348. else:
  1349. if self.parent.samplingareapage.samplingtype in [
  1350. SamplingType.MVWIN, SamplingType.MMVWINR, SamplingType.MMVWINC]:
  1351. self.parent.samplingareapage.samplingtype = SamplingType.MMVWINC
  1352. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1353. else:
  1354. self.parent.samplingareapage.samplingtype = SamplingType.MUNITSC
  1355. self.drawtype = 'circle'
  1356. def OnNumRegions(self, event):
  1357. """Set the number of region"""
  1358. if self.regionNumTxt.GetValue():
  1359. self.SetNext(self.parent.drawsampleunitspage)
  1360. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1361. self.numregions = self.regionNumTxt.GetValue()
  1362. else:
  1363. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1364. def OnExitPage(self, event=None):
  1365. """Function during exiting"""
  1366. if event.GetDirection():
  1367. self.SetNext(self.drawsampleunitspage)
  1368. self.SetPrev(self.samplingareapage)
  1369. class DrawSampleUnitsPage(TitledPage):
  1370. """Choose the sampling area drawing them"""
  1371. def __init__(self, wizard, parent):
  1372. TitledPage.__init__(self, wizard, _("Draw sampling units"))
  1373. self.parent = parent
  1374. self.mapPanel = None
  1375. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1376. #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  1377. def SampleFrameChanged(self, region):
  1378. #region = self.GetSampleUnitRegion()
  1379. if region:
  1380. self.parent.msAreaList.append(region)
  1381. self.regioncount = self.regioncount + 1
  1382. drawtype = self.parent.drawunits.drawtype
  1383. if self.regioncount > self.numregions:
  1384. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1385. self.parent.wizard.ShowPage(self.parent.summarypage)
  1386. else:
  1387. self.title.SetLabel(_('Draw Sampling ' + drawtype + ' '
  1388. + str(self.regioncount) + ' of '
  1389. + str(self.numregions)))
  1390. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1391. def OnEnterPage(self, event):
  1392. """Function during entering"""
  1393. if self.parent.samplingareapage.samplingtype in [SamplingType.MVWIN,
  1394. SamplingType.MMVWINC,
  1395. SamplingType.MMVWINR]:
  1396. self.numregions = 1
  1397. else:
  1398. self.numregions = int(self.parent.drawunits.numregions)
  1399. self.regioncount = 0
  1400. if self.mapPanel:
  1401. self.sizer.Remove(self.mapPanel)
  1402. gtype = self.parent.drawunits.drawtype
  1403. self.mapPanel = RLiSetupMapPanel(
  1404. self, samplingType=self.parent.samplingareapage.samplingtype, )
  1405. if gtype == 'circle':
  1406. self.mapPanel.afterCircleDrawn.connect(self.SampleFrameChanged)
  1407. else:
  1408. self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
  1409. self.sizer.Add(self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  1410. self.sizer.AddGrowableCol(0)
  1411. self.sizer.AddGrowableRow(1)
  1412. self._raster = None
  1413. self.SampleFrameChanged(region=None)
  1414. rast = self.parent.startpage.rast
  1415. if self._raster != rast:
  1416. map_ = self.mapPanel.GetMap()
  1417. map_.DeleteAllLayers()
  1418. cmdlist = ['d.rast', 'map=%s' % rast]
  1419. map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  1420. name=rast, hidden=False, opacity=1.0, render=True)
  1421. def OnExitPage(self, event=None):
  1422. #!Function during exiting
  1423. pass
  1424. # if event.GetDirection():
  1425. # self.SetNext(self.parent.samplingareapage)
  1426. # self.parent.samplingareapage.SetPrev(self)
  1427. class VectorAreasPage(TitledPage):
  1428. """Choose the sampling area using the vector features"""
  1429. def __init__(self, wizard, parent):
  1430. TitledPage.__init__(self, wizard, _("Select sampling areas"))
  1431. self.parent = parent
  1432. self.areascount = 0
  1433. self.mapPanel = None
  1434. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1435. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
  1436. self.areaPanelSizer = wx.GridBagSizer(1, 3)
  1437. self.areaPanel = wx.Panel(parent=self, id=wx.ID_ANY)
  1438. self.areaText = StaticText(parent=self.areaPanel, id=wx.ID_ANY,
  1439. label=_('Is this area ok?'))
  1440. self.areaOK = Button(self.areaPanel, wx.ID_ANY, 'Yes', (50, 80))
  1441. self.areaNO = Button(self.areaPanel, wx.ID_ANY, 'No', (50, 80))
  1442. self.areaOK.Bind(wx.EVT_BUTTON, self.OnYes)
  1443. self.areaNO.Bind(wx.EVT_BUTTON, self.OnNo)
  1444. self.areaPanelSizer.Add(self.areaText, flag=wx.ALIGN_CENTER,
  1445. pos=(0, 0))
  1446. self.areaPanelSizer.Add(self.areaOK, flag=wx.ALIGN_CENTER,
  1447. pos=(0, 1))
  1448. self.areaPanelSizer.Add(self.areaNO, flag=wx.ALIGN_CENTER,
  1449. pos=(0, 2))
  1450. self.areaPanel.SetSizer(self.areaPanelSizer)
  1451. self.sizer.Add(self.areaPanel, flag=wx.ALIGN_CENTER, pos=(2, 0))
  1452. def afterRegionDrawn(self):
  1453. """Function to update the title and the number of selected area"""
  1454. self.areascount = self.areascount + 1
  1455. if self.areascount == self.areanum:
  1456. wx.FindWindowById(wx.ID_FORWARD).Enable(True)
  1457. self.areaOK.Enable(False)
  1458. self.areaNO.Enable(False)
  1459. return True
  1460. else:
  1461. self.title.SetLabel(_('Select sample area ' + str(self.areascount + 1)
  1462. + ' of ' + str(self.areanum)))
  1463. wx.FindWindowById(wx.ID_FORWARD).Enable(False)
  1464. return False
  1465. def OnYes(self, event):
  1466. """Function to create the string for the conf file if the area
  1467. is selected"""
  1468. self.parent.msAreaList.append(obtainAreaVector(self.outname))
  1469. if not self.afterRegionDrawn():
  1470. self.newCat()
  1471. def OnNo(self, event):
  1472. """Function to pass to the next feature if it is not selected"""
  1473. if not self.afterRegionDrawn():
  1474. self.newCat()
  1475. def newCat(self):
  1476. """Convert to raster and draw the new feature"""
  1477. cat = self.vect_cats[self.areascount]
  1478. self.outpref = "{rast}_{vect}_".format(vect=self.vect.split('@')[0],
  1479. rast=self.rast.split('@')[0])
  1480. self.outname = "{pref}{cat}".format(pref=self.outpref, cat=cat)
  1481. # check if raster already axist
  1482. if len(grass.list_strings('raster', pattern=self.outname, mapset='.')
  1483. ) == 1 and not self.parent.samplingareapage.overwriteTemp:
  1484. GError(parent=self, message=_("The raster map <%s> already exists."
  1485. " Please remove or rename the maps "
  1486. "with the prefix '%s' or select the "
  1487. "option to overwrite existing maps"
  1488. % (self.outname, self.outpref)))
  1489. self.parent.wizard.ShowPage(self.parent.samplingareapage)
  1490. return
  1491. convertFeature(self.vect, self.outname, cat, self.rast,
  1492. self.parent.startpage.vectorlayer,
  1493. self.parent.samplingareapage.overwriteTemp)
  1494. cmdlistcat = ['d.rast', 'map=%s' % self.outname]
  1495. self.map_.AddLayer(ltype='raster', command=cmdlistcat, active=True,
  1496. name=self.outname, hidden=False, opacity=1.0,
  1497. render=True)
  1498. for l in self.map_.GetListOfLayers():
  1499. if l.name == self.outname:
  1500. self.mapPanel.mapWindow.ZoomToMap(layers=[l], render=True,
  1501. ignoreNulls=True)
  1502. elif l.name != self.rast:
  1503. self.map_.DeleteLayer(l)
  1504. self.areaText.SetLabel("Is this area (cat={n}) ok?".format(n=cat))
  1505. def OnEnterPage(self, event):
  1506. """Function during entering: draw the raster map and the first vector
  1507. feature"""
  1508. if self.mapPanel is None:
  1509. self.mapPanel = RLiSetupMapPanel(
  1510. self, samplingType=self.parent.samplingareapage.samplingtype)
  1511. self.sizer.Add(self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
  1512. self.sizer.AddGrowableCol(0)
  1513. self.sizer.AddGrowableRow(1)
  1514. self._raster = None
  1515. self.rast = self.parent.startpage.rast
  1516. self.vect = self.parent.startpage.vect
  1517. self.vect_cats = obtainCategories(
  1518. self.vect, layer=self.parent.startpage.vectorlayer)
  1519. self.areanum = len(self.vect_cats)
  1520. if self.areanum == 0:
  1521. GError(parent=self, message=_("The polygon seems to have 0 areas"))
  1522. self.parent.wizard.ShowPage(self.parent.samplingareapage)
  1523. return
  1524. self.title.SetLabel(_('Select sample area 1 of ' + str(self.areanum)))
  1525. grass.use_temp_region()
  1526. if self._raster != self.rast:
  1527. self.map_ = self.mapPanel.GetMap()
  1528. self.map_.DeleteAllLayers()
  1529. cmdlist = ['d.rast', 'map=%s' % self.rast]
  1530. self.map_.AddLayer(ltype='raster', command=cmdlist, active=True,
  1531. name=self.rast, hidden=False, opacity=1.0,
  1532. render=True)
  1533. self.newCat()
  1534. def OnExitPage(self, event=None):
  1535. """Function during exiting"""
  1536. grass.del_temp_region()
  1537. # if event.GetDirection():
  1538. # self.SetNext(self.parent.samplingareapage)
  1539. # self.parent.samplingareapage.SetPrev(self)
  1540. class SummaryPage(TitledPage):
  1541. """Shows summary result of choosing data"""
  1542. def __init__(self, wizard, parent):
  1543. TitledPage.__init__(self, wizard, _("Summary"))
  1544. global rlisettings
  1545. self.parent = parent
  1546. # configuration file name
  1547. self.conflabel = StaticText(parent=self, id=wx.ID_ANY,
  1548. label=_('Configuration file name:'))
  1549. self.conftxt = StaticText(parent=self, id=wx.ID_ANY,
  1550. label="")
  1551. self.sizer.Add(self.conflabel, border=5, pos=(0, 0),
  1552. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1553. self.sizer.Add(self.conftxt, border=5, pos=(0, 1),
  1554. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1555. # raster name
  1556. self.rastlabel = StaticText(parent=self, id=wx.ID_ANY,
  1557. label=_('Raster name:'))
  1558. self.rasttxt = StaticText(parent=self, id=wx.ID_ANY,
  1559. label="")
  1560. self.sizer.Add(self.rastlabel, border=5, pos=(1, 0),
  1561. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1562. self.sizer.Add(self.rasttxt, border=5, pos=(1, 1),
  1563. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1564. # vector name
  1565. self.vectlabel = StaticText(parent=self, id=wx.ID_ANY,
  1566. label=_('Vector name:'))
  1567. self.vecttxt = StaticText(parent=self, id=wx.ID_ANY, label="")
  1568. self.sizer.Add(self.vectlabel, border=5, pos=(2, 0),
  1569. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1570. self.sizer.Add(self.vecttxt, border=5, pos=(2, 1),
  1571. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1572. # region type name
  1573. self.regionlabel = StaticText(parent=self, id=wx.ID_ANY,
  1574. label=_('Region type:'))
  1575. self.regiontxt = StaticText(parent=self, id=wx.ID_ANY, label="")
  1576. self.sizer.Add(self.regionlabel, border=5, pos=(3, 0),
  1577. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1578. self.sizer.Add(self.regiontxt, border=5, pos=(3, 1),
  1579. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1580. # region keyboard
  1581. self.regionkeylabel = StaticText(parent=self, id=wx.ID_ANY,
  1582. label="")
  1583. self.regionkeytxt = StaticText(parent=self, id=wx.ID_ANY, label="")
  1584. self.sizer.Add(self.regionkeylabel, border=5, pos=(4, 0),
  1585. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1586. self.sizer.Add(self.regionkeytxt, border=5, pos=(4, 1),
  1587. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1588. self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
  1589. # sampling area
  1590. self.samplinglabel = StaticText(parent=self, id=wx.ID_ANY,
  1591. label=_('Sampling area type:'))
  1592. self.samplingtxt = StaticText(parent=self, id=wx.ID_ANY, label="")
  1593. self.sizer.Add(self.samplinglabel, border=5, pos=(5, 0),
  1594. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1595. self.sizer.Add(self.samplingtxt, border=5, pos=(5, 1),
  1596. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1597. # shapetype
  1598. self.shapelabel = StaticText(parent=self, id=wx.ID_ANY, label="")
  1599. self.shapetxt = StaticText(parent=self, id=wx.ID_ANY, label="")
  1600. self.sizer.Add(self.shapelabel, border=5, pos=(6, 0),
  1601. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1602. self.sizer.Add(self.shapetxt, border=5, pos=(6, 1),
  1603. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1604. # shapedim
  1605. self.shapewidthlabel = StaticText(parent=self, id=wx.ID_ANY,
  1606. label="")
  1607. self.shapewidthtxt = StaticText(parent=self, id=wx.ID_ANY,
  1608. label="")
  1609. self.sizer.Add(self.shapewidthlabel, border=5, pos=(7, 0),
  1610. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1611. self.sizer.Add(self.shapewidthtxt, border=5, pos=(7, 1),
  1612. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1613. self.shapeheightlabel = StaticText(parent=self, id=wx.ID_ANY,
  1614. label="")
  1615. self.shapeheighttxt = StaticText(parent=self, id=wx.ID_ANY,
  1616. label="")
  1617. self.sizer.Add(self.shapeheightlabel, border=5, pos=(8, 0),
  1618. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1619. self.sizer.Add(self.shapeheighttxt, border=5, pos=(8, 1),
  1620. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1621. # units type
  1622. self.unitslabel = StaticText(parent=self, id=wx.ID_ANY, label="")
  1623. self.unitstxt = StaticText(parent=self, id=wx.ID_ANY, label="")
  1624. self.sizer.Add(self.unitslabel, border=5, pos=(9, 0),
  1625. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1626. self.sizer.Add(self.unitstxt, border=5, pos=(9, 1),
  1627. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1628. self.unitsmorelabel = StaticText(parent=self, id=wx.ID_ANY,
  1629. label="")
  1630. self.unitsmoretxt = StaticText(parent=self, id=wx.ID_ANY, label="")
  1631. self.sizer.Add(self.unitsmorelabel, border=5, pos=(10, 0),
  1632. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1633. self.sizer.Add(self.unitsmoretxt, border=5, pos=(10, 1),
  1634. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1635. self.unitsmorelabel2 = StaticText(parent=self, id=wx.ID_ANY,
  1636. label="")
  1637. self.unitsmoretxt2 = StaticText(parent=self, id=wx.ID_ANY, label="")
  1638. self.sizer.Add(self.unitsmorelabel2, border=5, pos=(11, 0),
  1639. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1640. self.sizer.Add(self.unitsmoretxt2, border=5, pos=(11, 1),
  1641. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  1642. def OnEnterPage(self, event):
  1643. """Insert values into text controls for summary of location
  1644. creation options
  1645. """
  1646. self.conftxt.SetLabel(self.parent.startpage.conf_name)
  1647. self.rasttxt.SetLabel(self.parent.startpage.rast)
  1648. self.samplingtxt.SetLabel(self.parent.samplingareapage.samplingtype)
  1649. self.regiontxt.SetLabel(self.parent.startpage.region)
  1650. self.vecttxt.SetLabel(self.parent.startpage.vect)
  1651. if self.parent.startpage.region == 'key':
  1652. # region keyboard values
  1653. self.regionkeylabel.SetLabel(_('Region keyboard values:'))
  1654. regKeyVals = "Column left up: %s - Row left up: %s\n" \
  1655. "Column length: %s - Row length: %s\n" % (
  1656. self.parent.keyboardpage.col_up,
  1657. self.parent.keyboardpage.row_up,
  1658. self.parent.keyboardpage.col_len,
  1659. self.parent.keyboardpage.row_len)
  1660. self.regionkeytxt.SetLabel(regKeyVals)
  1661. else:
  1662. self.regionkeylabel.SetLabel("")
  1663. self.regionkeytxt.SetLabel("")
  1664. if self.parent.samplingareapage.samplingtype == SamplingType.UNITS \
  1665. and self.parent.samplingareapage.regionbox == 'keyboard':
  1666. self.shapelabel.SetLabel(_('Type of shape:'))
  1667. self.shapetxt.SetLabel(self.parent.units.boxtype)
  1668. if self.parent.units.boxtype == 'circle':
  1669. self.shapewidthlabel.SetLabel(_("Radius size:"))
  1670. self.shapeheightlabel.SetLabel(_("Name circle mask:"))
  1671. else:
  1672. self.shapewidthlabel.SetLabel(_("Width size:"))
  1673. self.shapeheightlabel.SetLabel(_("Height size:"))
  1674. self.shapewidthtxt.SetLabel(self.parent.units.width)
  1675. self.shapeheighttxt.SetLabel(self.parent.units.height)
  1676. self.unitslabel.SetLabel(_("Method of distribution:"))
  1677. self.unitstxt.SetLabel(self.parent.units.distrtype)
  1678. if self.parent.units.distrtype == 'non_overlapping':
  1679. self.unitsmorelabel.SetLabel(_("Number sampling units:"))
  1680. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1681. elif self.parent.units.distrtype == 'systematic_noncontiguos':
  1682. self.unitsmorelabel.SetLabel(_("Distance between units:"))
  1683. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1684. elif self.parent.units.distrtype == 'stratified_random':
  1685. self.unitsmorelabel.SetLabel(_("Number row strates:"))
  1686. self.unitsmoretxt.SetLabel(self.parent.units.distr1)
  1687. self.unitsmorelabel2.SetLabel(_("Number column strates:"))
  1688. self.unitsmoretxt2.SetLabel(self.parent.units.distr2)
  1689. elif self.parent.samplingareapage.samplingtype == SamplingType.UNITS \
  1690. and self.parent.samplingareapage.regionbox == 'mouse':
  1691. self.shapelabel.SetLabel(_('Type of shape:'))
  1692. self.shapetxt.SetLabel(self.parent.units.boxtype)
  1693. self.unitstxt.SetLabel('by mouse')
  1694. elif self.parent.samplingareapage.samplingtype == 'moving':
  1695. self.shapelabel.SetLabel(_('Type of shape:'))
  1696. self.shapetxt.SetLabel(self.parent.moving.boxtype)
  1697. if self.parent.moving.boxtype == 'circle':
  1698. self.shapewidthlabel.SetLabel(_("Radius size:"))
  1699. self.shapeheightlabel.SetLabel(_("Name circle mask:"))
  1700. else:
  1701. self.shapewidthlabel.SetLabel(_("Width size:"))
  1702. self.shapeheightlabel.SetLabel(_("Height size:"))
  1703. self.shapewidthtxt.SetLabel(self.parent.moving.width)
  1704. self.shapeheighttxt.SetLabel(self.parent.moving.height)
  1705. else:
  1706. self.shapelabel.SetLabel("")
  1707. self.shapetxt.SetLabel("")
  1708. self.shapewidthlabel.SetLabel("")
  1709. self.shapewidthtxt.SetLabel("")
  1710. self.shapeheightlabel.SetLabel("")
  1711. self.shapeheighttxt.SetLabel("")