wizard.py 83 KB

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