123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914 |
- """
- @package rlisetup.py
- @brief GUI per r.li.setup module
- Classes:
- - RLiSetupFrame (first frame to show existing conf file and choose some
- operation)
- - RLIWizard (the main wizard)
- - FirstPage (first page of wizard, choose name of conf file, raster, vector,
- sampling region)
- - Keyboard (page to insert region areas from keyboard)
- - SamplingAreas (define sampling area)
- - SummaryPage (show choosen options)
- (C) 2011 by the GRASS Development Team
- This program is free software under the GNU General Public License
- (>=v2). Read the file COPYING that comes with GRASS for details.
- @author Luca Delucchi <lucadeluge gmail com>
- """
- import os
- import wx
- from core.globalvar import wxPythonPhoenix
- if wxPythonPhoenix:
- from wx import adv as wiz
- from wx.adv import Wizard
- else:
- from wx import wizard as wiz
- from wx.wizard import Wizard
- import wx.lib.scrolledpanel as scrolled
- from gui_core import gselect
- from core.utils import _
- from location_wizard.wizard import TitledPage as TitledPage
- from rlisetup.functions import checkValue, retRLiPath
- from rlisetup.sampling_frame import RLiSetupMapPanel
- from grass.script import core as grass
- from grass.script import raster as grast
- from grass.script import vector as gvect
- from grass.exceptions import CalledModuleError
- from functions import SamplingType, sampleAreaVector, convertFeature
- from functions import obtainAreaVector, obtainCategories
- from core.gcmd import GError, GMessage, RunCommand
- class RLIWizard(object):
- """
- !Start wizard here and finish wizard here
- """
- def __init__(self, parent):
- self.parent = parent
- self.wizard = Wizard(parent=parent, id=wx.ID_ANY,
- title=_("Create new configuration file for "
- "r.li modules"))
- self.rlipath = retRLiPath()
- self.msAreaList = []
- # pages
- self.startpage = FirstPage(self.wizard, self)
- self.drawsampleframepage = DrawSampleFramePage(self.wizard, self)
- self.keyboardpage = KeyboardPage(self.wizard, self)
- self.samplingareapage = SamplingAreasPage(self.wizard, self)
- self.summarypage = SummaryPage(self.wizard, self)
- self.units = SampleUnitsKeyPage(self.wizard, self)
- self.drawunits = UnitsMousePage(self.wizard, self)
- self.drawsampleunitspage = DrawSampleUnitsPage(self.wizard, self)
- self.vectorareas = VectorAreasPage(self.wizard, self)
- self.moving = MovingKeyPage(self.wizard, self)
- self.regions = DrawRegionsPage(self.wizard, self)
- # order of pages
- self.startpage.SetNext(self.samplingareapage)
- self.keyboardpage.SetPrev(self.startpage)
- self.keyboardpage.SetNext(self.samplingareapage)
- self.drawsampleframepage.SetNext(self.samplingareapage)
- self.drawsampleframepage.SetPrev(self.startpage)
- self.samplingareapage.SetPrev(self.startpage)
- self.samplingareapage.SetNext(self.summarypage)
- self.regions.SetPrev(self.samplingareapage)
- self.regions.SetNext(self.summarypage)
- self.units.SetPrev(self.samplingareapage)
- self.units.SetNext(self.summarypage)
- self.drawunits.SetPrev(self.samplingareapage)
- self.drawunits.SetNext(self.drawsampleunitspage)
- self.drawsampleunitspage.SetPrev(self.drawunits)
- self.drawsampleunitspage.SetNext(self.summarypage)
- self.moving.SetPrev(self.samplingareapage)
- self.moving.SetNext(self.summarypage)
- self.vectorareas.SetPrev(self.samplingareapage)
- self.vectorareas.SetNext(self.summarypage)
- self.summarypage.SetPrev(self.samplingareapage)
- # layout
- self.startpage.DoLayout()
- self.drawsampleframepage.DoLayout()
- self.keyboardpage.DoLayout()
- self.samplingareapage.DoLayout()
- self.summarypage.DoLayout()
- self.units.DoLayout()
- self.drawunits.DoLayout()
- self.drawsampleunitspage.DoLayout()
- self.regions.DoLayout()
- self.moving.DoLayout()
- self.vectorareas.DoLayout()
- self.wizard.FitToPage(self.startpage)
- # run_wizard
- if self.wizard.RunWizard(self.startpage):
- dlg = wx.MessageDialog(
- parent=self.parent,
- message=_(
- "Do you want to create r.li "
- "configuration file <%s>?") %
- self.startpage.conf_name,
- caption=_("Create new r.li configuration file?"),
- style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
- if dlg.ShowModal() == wx.ID_NO:
- self._cleanup()
- else:
- self._write_confile()
- self._cleanup()
- dlg.Destroy()
- else:
- self.wizard.Destroy()
- GMessage(parent=self.parent,
- message=_("r.li.setup wizard canceled. "
- "Configuration file not created."))
- self._cleanup()
- def _write_confile(self):
- """Write the configuration file"""
- f = open(os.path.join(self.rlipath, self.startpage.conf_name), 'wb')
- self.rasterinfo = grast.raster_info(self.startpage.rast)
- self._write_region(f)
- self._write_area(f)
- f.close()
- def _temp_region(self):
- # save current settings:
- grass.use_temp_region()
- # Temporarily aligning region resolution to $RASTER resolution
- # keep boundary settings
- grass.run_command('g.region', raster=self.startpage.rast)
- self.gregion = grass.region()
- self.SF_NSRES = self.gregion['nsres']
- self.SF_EWRES = self.gregion['ewres']
- def _write_region(self, fil):
- """Write the region"""
- if self.startpage.region == 'whole':
- fil.write("SAMPLINGFRAME 0|0|1|1\n")
- self._temp_region()
- self.SF_X = 0.0
- self.SF_Y = 0.0
- self.SF_RL = abs(int(float(self.gregion['s'] - self.gregion['n'])
- / float(self.gregion['nsres'])))
- self.SF_CL = abs(int(float(self.gregion['e'] - self.gregion['w'])
- / float(self.gregion['ewres'])))
- self.SF_N = self.gregion['n']
- self.SF_S = self.gregion['s']
- self.SF_E = self.gregion['e']
- self.SF_W = self.gregion['w']
- self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
- self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
- self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
- self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
- elif self.startpage.region == 'key':
- self._temp_region()
- self.SF_X = float(self.keyboardpage.col_up)
- self.SF_Y = float(self.keyboardpage.row_up)
- self.SF_RL = float(self.keyboardpage.row_len)
- self.SF_CL = float(self.keyboardpage.col_len)
- self.SF_N = self.gregion['n'] - (self.SF_NSRES * self.SF_Y)
- self.SF_S = self.gregion[
- 'n'] - (self.SF_NSRES * self.SF_Y + self.SF_RL)
- self.SF_W = self.gregion['w'] + (self.SF_EWRES * self.SF_X)
- self.SF_E = self.gregion[
- 'w'] + (self.SF_EWRES * self.SF_X + self.SF_CL)
- self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
- self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
- self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
- self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
- fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" % (self.per_x, self.per_y,
- self.per_rl,
- self.per_cl))
- elif self.startpage.region == 'draw':
- self._temp_region()
- tregion = self.drawsampleframepage.tregion
- # should we call this? with align param?
- RunCommand('g.region', align=self.startpage.rast, n=tregion['n'],
- s=tregion['s'], w=tregion['w'], e=tregion['e'])
- newreg = grass.region()
- self.SF_N = newreg['n'] # set env(SF_N) $n
- self.SF_S = newreg['s'] # set env(SF_S) $s
- self.SF_E = newreg['e'] # set env(SF_E) $e
- self.SF_W = newreg['w'] # set env(SF_W) $w
- self.SF_Y = abs(
- round(
- self.gregion['n'] -
- newreg['n']) /
- newreg['nsres'])
- # set env(SF_Y) [expr abs(round(($s_n - $n) / $nres)) ]
- self.SF_X = abs(
- round(
- self.gregion['w'] -
- newreg['w']) /
- newreg['ewres'])
- # set env(SF_X) [expr abs(round(($s_w - $w) / $sres)) ]
- self.SF_RL = abs(
- round(
- newreg['n'] -
- newreg['s']) /
- newreg['nsres'])
- # set env(SF_RL) [expr abs(round(($n - $s) / $nres)) ]
- self.SF_CL = abs(
- round(
- newreg['e'] -
- newreg['w']) /
- newreg['ewres'])
- # set env(SF_CL) [expr abs(round(($e - $w) / $sres)) ]
- self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
- # double($env(SF_X)) / double($cols)
- self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
- # double($env(SF_Y)) / double($rows)
- self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
- # double($env(SF_RL)) / double($rows)
- self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
- # double($env(SF_CL)) / double($cols)
- fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" %
- (self.per_x, self.per_y, self.per_rl, self.per_cl))
- def _value_for_circle(self, radius):
- self.CIR_RL = round((2 * float(radius)) /
- float(self.rasterinfo['ewres']))
- self.CIR_CL = round((2 * float(radius)) /
- float(self.rasterinfo['nsres']))
- if not self.CIR_RL % 2:
- self.CIR_RL += 1
- if not self.CIR_CL % 2:
- self.CIR_CL += 1
- return
- def _circle(self, radius, mask):
- """Create a circle mask"""
- self._value_for_circle(radius)
- eastEdge = float(self.SF_W + (self.CIR_RL * self.SF_EWRES))
- southEdge = float(self.SF_N - (self.CIR_CL * self.SF_NSRES))
- grass.del_temp_region()
- grass.use_temp_region()
- grass.run_command('g.region', n=self.SF_N, s=southEdge, e=eastEdge,
- w=self.SF_W)
- xcenter = grass.region(complete=True)['center_easting']
- ycenter = grass.region(complete=True)['center_northing']
- grass.run_command('r.circle', flags='b', out=mask, max=radius,
- coordinate=[xcenter, ycenter], quiet=True)
- grass.del_temp_region()
- grass.use_temp_region()
- grass.run_command('g.region', raster=self.startpage.rast)
- def getSamplingType(self):
- """Obtain the sampling type"""
- devicetype = self.samplingareapage.regionbox
- samplingtype = self.samplingareapage.samplingtype
- shapetype = self.units.boxtype
- if samplingtype == SamplingType.UNITS:
- if devicetype == 'mouse':
- if shapetype == 'circle':
- samtype = SamplingType.MUNITSC
- else:
- samtype = SamplingType.MUNITSR
- elif devicetype == 'keyboard':
- if shapetype == 'circle':
- samtype = SamplingType.KUNITSC
- else:
- samtype = SamplingType.KUNITSR
- elif samplingtype == SamplingType.MVWIN:
- if devicetype == 'mouse':
- if shapetype == 'circle':
- samtype = SamplingType.MMVWINC
- else:
- samtype = SamplingType.MMVWINR
- elif devicetype == 'keyboard':
- if shapetype == 'circle':
- samtype = SamplingType.KMVWINC
- else:
- samtype = SamplingType.KMVWINR
- elif samplingtype == SamplingType.WHOLE:
- samtype = SamplingType.WHOLE
- elif samplingtype == SamplingType.REGIONS:
- samtype = SamplingType.REGIONS
- elif samplingtype == SamplingType.VECT:
- samtype = SamplingType.VECT
- else:
- samtype = samplingtype
- return samtype
- def _write_area(self, fil):
- """Write the area according the type"""
- samtype = self.getSamplingType()
- # sampling type is whole
- if samtype == SamplingType.WHOLE:
- cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
- rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
- # this two variable are unused, problably to remove
- x = float(self.SF_X) / float(self.rasterinfo['cols'])
- y = float(self.SF_Y) / float(self.rasterinfo['rows'])
- fil.write("SAMPLEAREA %r|%r|%r|%r\n" % (self.per_x, self.per_y,
- rl, cl))
- ##KMWINC = samplingtype=moving, regionbox=keyboard, shape=circle
- elif samtype == SamplingType.KMVWINC:
- self._circle(self.moving.width, self.moving.height)
- cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
- rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
- fil.write("MASKEDSAMPLEAREA -1|-1|%r|%r" % (rl, cl))
- fil.write("|%s" % self.moving.height)
- fil.write("\nMOVINGWINDOW\n")
- # KMWINR = samplingtype moving, regionbox=keyboard, shape=rectangle
- elif samtype == SamplingType.KMVWINR:
- cl = float(self.moving.width) / float(self.rasterinfo['cols'])
- rl = float(self.moving.height) / float(self.rasterinfo['rows'])
- fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
- fil.write("\nMOVINGWINDOW\n")
- # MMVWINR = samplingtype moving, regionbox=mouse, shape=rectangle
- elif samtype == SamplingType.MMVWINR:
- cl = float(self.msAreaList[0]['cols']
- ) / float(self.rasterinfo['cols'])
- rl = float(self.msAreaList[0]['rows']
- ) / float(self.rasterinfo['rows'])
- fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
- fil.write("\nMOVINGWINDOW\n")
- # MMVWINR = samplingtype moving, regionbox=mouse, shape=circle
- elif samtype == SamplingType.MMVWINC:
- self._value_for_circle(self.msAreaList[0].radius)
- cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
- rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
- fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
- fil.write("|%s" % self.msAreaList[0].raster)
- fil.write("\nMOVINGWINDOW\n")
- ##KUNITSC = samplingtype=units, regionbox=keyboard, shape=cirlce
- ##KUNITSR = samplingtype=units, regionbox=keyboard, shape=rectangle
- elif samtype == SamplingType.KUNITSC or samtype == SamplingType.KUNITSR:
- if samtype == SamplingType.KUNITSC:
- self._circle(self.units.width, self.units.height)
- cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
- rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
- else:
- cl = float(self.moving.width) / float(self.rasterinfo['cols'])
- rl = float(self.moving.height) / float(self.rasterinfo['rows'])
- fil.write("SAMPLEAREA -1|-1|%r|%r\n" % (rl, cl))
- if self.units.distrtype == 'non_overlapping':
- fil.write("RANDOMNONOVERLAPPING %s\n" % self.units.distr1)
- elif self.units.distrtype == 'systematic_contiguos':
- fil.write("SYSTEMATICCONTIGUOUS\n")
- elif self.units.distrtype == 'stratified_random':
- fil.write("STRATIFIEDRANDOM %s|%s\n" % (self.units.distr1,
- self.units.distr2))
- elif self.units.distrtype == 'systematic_noncontiguos':
- fil.write("SYSTEMATICNONCONTIGUOUS %s\n" % self.units.distr1)
- elif self.units.distrtype == 'centered_oversites':
- fil.write("")
- # elif self.samplingareapage.samplingtype == SamplingType.UNITS and
- # self.samplingareapage.regionbox=='mouse':
- ##MUNITSC = samplingtype=units, regionbox=mouse, shape=cirlce
- ##MUNITSR = samplingtype=units, regionbox=mouse, shape=rectangle
- elif self.samplingareapage.samplingtype in [SamplingType.MUNITSR,
- SamplingType.MUNITSC]:
- # get the raster region into rastregion
- grass.use_temp_region()
- grass.run_command('g.region', raster=self.startpage.rast)
- rastregion = grass.region()
- s_n = rastregion['n']
- s_w = rastregion['w']
- rows = float(self.rasterinfo['rows'])
- cols = float(self.rasterinfo['cols'])
- for tregion in self.msAreaList:
- if self.samplingareapage.samplingtype == SamplingType.MUNITSC:
- tregion = tregion.region
- abs_y = abs(
- round(
- (float(s_n) - tregion['n']) / tregion
- ['nsres']))
- abs_x = abs(
- round(
- (float(s_w) - tregion['w']) / tregion
- ['ewres']))
- abs_rl = abs(
- round(
- (tregion['n'] - tregion['s']) /
- tregion['nsres']))
- abs_cl = abs(
- round(
- (tregion['e'] - tregion['w']) /
- tregion['ewres']))
- x = float(abs_x) / float(cols)
- y = float(abs_y) / float(rows)
- rl = float(abs_rl) / float(rows)
- cl = float(abs_cl) / float(cols)
- sarea = str(x) + "|" + str(y) + "|" + str(rl) + "|" + str(cl)
- if self.samplingareapage.samplingtype == SamplingType.MUNITSR:
- fil.write("SQUAREAREA %s\n" % sarea)
- elif self.samplingareapage.samplingtype == SamplingType.MUNITSC:
- fil.write("MASKEDSAMPLEAREA %s" % sarea)
- fil.write("|%s\n" % self.msAreaList[0].raster)
- elif self.samplingareapage.samplingtype == SamplingType.REGIONS:
- rows = float(self.rasterinfo['rows'])
- cols = float(self.rasterinfo['cols'])
- for marea in self.msAreaList:
- gregion = marea.region
- abs_y = self.SF_Y + abs(
- round((self.SF_N - gregion['n']) / self.SF_NSRES))
- abs_x = self.SF_X + abs(
- round((self.SF_W - gregion['w']) / self.SF_EWRES))
- abs_rl = abs(
- round(
- gregion['n'] -
- gregion['s']) /
- self.SF_NSRES)
- abs_cl = abs(
- round(
- gregion['e'] -
- gregion['w']) /
- self.SF_EWRES)
- x = float(abs_x) / float(cols)
- y = float(abs_y) / float(rows)
- rl = float(abs_rl) / float(rows)
- cl = float(abs_cl) / float(cols)
- maskArea = str(
- x) + "|" + str(y) + "|" + str(rl) + "|" + str(cl) + "|" + marea.raster
- fil.write("SQUAREAREA %s\n" % maskArea)
- elif self.samplingareapage.samplingtype == SamplingType.VECT:
- for marea in self.msAreaList:
- fil.write(marea)
- fil.write("RASTERMAP {name}\n".format(name=self.startpage.rast))
- fil.write("VECTORMAP {name}\n".format(name=self.startpage.vect))
- def _cleanup(self):
- """Clean all the variables to save into configuration file"""
- self.startpage.conf_name = ''
- self.startpage.rast = ''
- self.startpage.vect = ''
- self.startpage.region = 'whole'
- self.keyboardpage.col_len = ''
- self.keyboardpage.col_up = ''
- self.keyboardpage.row_len = ''
- self.keyboardpage.row_up = ''
- self.samplingareapage.samplingtype = 'whole'
- self.units.width = ''
- self.units.height = ''
- self.units.boxtype = ''
- self.regions.numregions = 0
- self.moving.width = ''
- self.moving.height = ''
- self.moving.boxtype = ''
- class FirstPage(TitledPage):
- """
- !Set name of configuration file, choose raster and optionally vector/sites
- """
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Select maps and define name"))
- self.region = 'whole'
- self.rast = ''
- self.conf_name = ''
- self.vect = ''
- self.VectorEnabled = True
- self.parent = parent
- # name of output configuration file
- self.newconflabel = wx.StaticText(
- parent=self, id=wx.ID_ANY,
- label=_('Name for new configuration file to create'))
- self.newconftxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
- size=(250, -1))
- wx.CallAfter(self.newconftxt.SetFocus)
- self.sizer.Add(self.newconflabel, border=5, pos=(0, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.newconftxt, border=5, pos=(0, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # raster
- self.mapsellabel = wx.StaticText(
- parent=self, id=wx.ID_ANY,
- label=_('Raster map to use to select areas'))
- self.mapselect = gselect.Select(parent=self, id=wx.ID_ANY,
- size=(250, -1), type='cell',
- multiple=False)
- self.sizer.Add(self.mapsellabel, border=5, pos=(1, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.mapselect, border=5, pos=(1, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # vector
- self.vectsellabel = wx.StaticText(
- parent=self, id=wx.ID_ANY,
- label=_('Vector map to use to select areas'))
- self.vectselect = gselect.Select(parent=self, id=wx.ID_ANY,
- size=(250, -1), type='vector',
- multiple=False)
- self.sizer.Add(self.vectsellabel, border=5, pos=(2, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.vectselect, border=5, pos=(2, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # vector layer
- self.vectlaylabel = wx.StaticText(
- parent=self, id=wx.ID_ANY,
- label=_('Vector map layer to use to select areas'))
- self.vectlayer = wx.ComboBox(parent=self, id=wx.ID_ANY,
- size=(250, -1))
- self.sizer.Add(self.vectlaylabel, border=5, pos=(3, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.vectlayer, border=5, pos=(3, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # define sampling region
- self.sampling_reg = wx.RadioBox(
- parent=self,
- id=wx.ID_ANY,
- label=" %s " % _(
- "Define sampling "
- "region (region for analysis)"),
- choices=[
- _('Whole map layer'),
- _('Keyboard setting'),
- _('Draw the sampling frame')],
- majorDimension=1,
- style=wx.RA_SPECIFY_ROWS)
- self.sizer.Add(self.sampling_reg,
- flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
- pos=(5, 0), span=(1, 2))
- self.infoError = wx.StaticText(self, label='')
- self.infoError.SetForegroundColour(wx.RED)
- self.sizer.Add(self.infoError,
- flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
- pos=(6, 0), span=(1, 2))
- # bindings
- self.sampling_reg.Bind(wx.EVT_RADIOBOX, self.OnSampling)
- self.newconftxt.Bind(wx.EVT_KILL_FOCUS, self.OnName)
- self.newconftxt.Bind(wx.EVT_TEXT, self.OnNameChanged)
- self.vectselect.Bind(wx.EVT_TEXT, self.OnVector)
- self.mapselect.Bind(wx.EVT_TEXT, self.OnRast)
- self.vectlayer.Bind(wx.EVT_TEXT, self.OnLayer)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
- wx.CallAfter(wx.FindWindowById(wx.ID_FORWARD).Enable, False)
- def OnSampling(self, event):
- """Change region type"""
- if event.GetInt() == 0:
- self.region = 'whole'
- self.SetNext(self.parent.samplingareapage)
- elif event.GetInt() == 1:
- self.region = 'key'
- self.SetNext(self.parent.keyboardpage)
- elif event.GetInt() == 2: # currently disabled
- self.region = 'draw'
- self.SetNext(self.parent.drawsampleframepage)
- def OnName(self, event):
- """Sets the name of configuration file"""
- if self.conf_name in self.parent.parent.listfiles:
- GMessage(
- parent=self, message=_(
- "The configuration file %s "
- "already exists, please change name") %
- self.conf_name)
- self.newconftxt.SetValue('')
- self.conf_name = ''
- def OnNameChanged(self, event):
- """Name of configuration file has changed"""
- self.conf_name = self.newconftxt.GetValue()
- next = wx.FindWindowById(wx.ID_FORWARD)
- next.Enable(self.CheckInput())
- def OnRast(self, event):
- """Sets raster map"""
- self.rast = self.mapselect.GetValue()
- next = wx.FindWindowById(wx.ID_FORWARD)
- next.Enable(self.CheckInput())
- def OnVector(self, event):
- """Sets vector map"""
- self.vect = self.vectselect.GetValue()
- if self.vect:
- self.VectorEnabled, layers = self.CheckVector(self.vect)
- if self.VectorEnabled:
- self.vectlayer.SetItems(layers)
- self.vectlayer.SetSelection(0)
- self.vectorlayer = self.vectlayer.GetValue()
- self.infoError.SetLabel('')
- else:
- self.vectlayer.Clear()
- self.vectlayer.SetValue('')
- self.vect = ''
- else:
- self.infoError.SetLabel('')
- self.vectlayer.Clear()
- self.vectlayer.SetValue('')
- next = wx.FindWindowById(wx.ID_FORWARD)
- next.Enable(self.CheckInput())
- def OnLayer(self, event):
- try:
- self.vectorlayer = self.vectlayer.GetValue()
- except:
- self.vectorlayer = None
- next = wx.FindWindowById(wx.ID_FORWARD)
- next.Enable(self.CheckInput())
- def OnEnterPage(self, event):
- """Sets the default values, for the entire map
- """
- next = wx.FindWindowById(wx.ID_FORWARD)
- next.Enable(self.CheckInput())
- wx.CallAfter(wx.FindWindowById(wx.ID_FORWARD).Enable,
- self.CheckInput())
- def CheckVector(self, vector):
- """Check if the type of vector is area and return the number of
- vector's layer"""
- try:
- areas = gvect.vector_info_topo(vector)['areas']
- except CalledModuleError:
- self.infoError.SetLabel(_("Vector %s was not found, please "
- "select another vector") % vector)
- return False, []
- if areas == 0:
- self.infoError.SetLabel(_("Vector %s has no areas, please "
- "select another vector") % vector)
- return False, []
- links = gvect.vector_info(vector)['num_dblinks']
- if links == 0:
- self.infoError.SetLabel(_("Vector %s has no table connected, "
- "please select another vector") % vector)
- return False, []
- elif links > 0:
- layers = []
- for i in range(1, links + 1):
- layers.append(str(i))
- return True, layers
- else:
- return False, []
- def CheckInput(self):
- """Check input fields.
- :return: True if configuration file is given and raster xor vector map,
- False otherwise
- """
- return bool(self.conf_name and bool(self.rast and
- bool(self.VectorEnabled)))
- def OnExitPage(self, event=None):
- """Function during exiting"""
- next = wx.FindWindowById(wx.ID_FORWARD)
- next.Enable(self.CheckInput())
- if event.GetDirection():
- if self.region == 'key':
- self.SetNext(self.parent.keyboardpage)
- self.parent.samplingareapage.SetPrev(self.parent.keyboardpage)
- elif self.region == 'whole':
- self.SetNext(self.parent.samplingareapage)
- self.parent.samplingareapage.SetPrev(self)
- elif self.region == 'draw':
- self.SetNext(self.parent.drawsampleframepage)
- self.parent.samplingareapage.SetPrev(
- self.parent.drawsampleframepage)
- return
- class KeyboardPage(TitledPage):
- """
- !Choose the region setting the values of border using the keyboard
- """
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Insert sampling frame parameter"))
- self.parent = parent
- self.col_len = ''
- self.row_len = ''
- self.col_up = '0'
- self.row_up = '0'
- # column up/left
- self.ColUpLeftlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label=_("Column of upper left "
- "corner"))
- self.ColUpLefttxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
- size=(250, -1))
- wx.CallAfter(self.ColUpLeftlabel.SetFocus)
- self.sizer.Add(self.ColUpLeftlabel, border=5, pos=(1, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.ColUpLefttxt, border=5, pos=(1, 2),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.AddGrowableCol(2)
- # row up/left
- self.RowUpLeftlabel = wx.StaticText(
- parent=self, id=wx.ID_ANY, label=_('Row of upper left corner'))
- self.RowUpLefttxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
- size=(250, -1))
- wx.CallAfter(self.RowUpLeftlabel.SetFocus)
- self.sizer.Add(self.RowUpLeftlabel, border=5, pos=(2, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.RowUpLefttxt, border=5, pos=(2, 2),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # row length
- self.RowLenlabel = wx.StaticText(
- parent=self,
- id=wx.ID_ANY,
- label=_('Row length of sampling frame'))
- self.RowLentxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
- wx.CallAfter(self.RowLenlabel.SetFocus)
- self.sizer.Add(self.RowLenlabel, border=5, pos=(3, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.RowLentxt, border=5, pos=(3, 2),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # column length
- self.ColLenlabel = wx.StaticText(
- parent=self,
- id=wx.ID_ANY,
- label=_('Row length of sampling frame'))
- self.ColLentxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
- wx.CallAfter(self.ColLenlabel.SetFocus)
- self.sizer.Add(self.ColLenlabel, border=5, pos=(4, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.ColLentxt, border=5, pos=(4, 2),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.ColUpLefttxt.SetValue(self.col_up)
- self.RowUpLefttxt.SetValue(self.row_up)
- self.ColUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLeft)
- self.RowUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLeft)
- self.ColLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLen)
- self.RowLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLen)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
- def OnColLeft(self, event):
- """Sets the name of configuration file"""
- self.col_up = self.ColUpLefttxt.GetValue()
- checkValue(self.col_up)
- def OnRowLeft(self, event):
- """Sets the name of configuration file"""
- self.row_up = self.RowUpLefttxt.GetValue()
- checkValue(self.row_up)
- def OnColLen(self, event):
- """Sets the name of configuration file"""
- self.col_len = self.ColLentxt.GetValue()
- checkValue(self.col_len)
- def OnRowLen(self, event):
- """Sets the name of configuration file"""
- self.row_len = self.RowLentxt.GetValue()
- checkValue(self.row_len)
- def OnEnterPage(self, event):
- """Sets the default values, for the entire map
- """
- # R# check if raster exists before anything
- if self.col_len == '' and self.row_len == '':
- rastinfo = grast.raster_info(self.parent.startpage.rast)
- self.col_len = rastinfo['cols']
- self.row_len = rastinfo['rows']
- self.ColLentxt.SetValue(self.col_len)
- self.RowLentxt.SetValue(self.row_len)
- def OnExitPage(self, event=None):
- """Function during exiting"""
- if self.row_len == '' or self.col_len == '' or self.row_up == '' or self.col_up == '':
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- class DrawSampleFramePage(TitledPage):
- """Choose the region setting the values drawing a box"""
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Draw sampling frame"))
- self.parent = parent
- self.mapPanel = None
- self.tregion = None
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
- def SampleFrameChanged(self, region):
- """"Enables the next dialog when region is set"""
- if region:
- self.tregion = region
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- def OnEnterPage(self, event):
- """Function during entering"""
- if self.mapPanel is None:
- self.mapPanel = RLiSetupMapPanel(self, samplingType='drawFrame')
- self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
- self.sizer.Add(self.mapPanel, flag=wx.EXPAND, pos=(0, 0))
- self.sizer.AddGrowableCol(0)
- self.sizer.AddGrowableRow(0)
- self._raster = None
- else:
- self.mapPanel._region = {}
- self.SampleFrameChanged(region=None)
- rast = self.parent.startpage.rast
- if self._raster != rast:
- map_ = self.mapPanel.GetMap()
- map_.DeleteAllLayers()
- cmdlist = ['d.rast', 'map=%s' % rast]
- map_.AddLayer(ltype='raster', command=cmdlist, active=True,
- name=rast, hidden=False, opacity=1.0, render=True)
- def OnExitPage(self, event=None):
- """Function during exiting"""
- if event.GetDirection():
- self.SetNext(self.parent.samplingareapage)
- self.parent.samplingareapage.SetPrev(self)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- class SamplingAreasPage(TitledPage):
- """
- Set name of configuration file, choose raster and optionally vector/sites.
- This is coming after choose the region
- """
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Insert sampling areas"))
- self.samplingtype = 'whole'
- self.parent = parent
- self.overwriteTemp = False
- # toggles
- self.radioBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
- label="",
- choices=[_("Whole map layer"),
- _("Regions"),
- _("Sample units"),
- _("Moving window"),
- _("Select areas from the\n"
- "overlayed vector map")],
- majorDimension=1,
- style=wx.RA_SPECIFY_COLS | wx.NO_BORDER)
- # layout
- self.sizer.SetVGap(10)
- self.sizer.Add(self.radioBox, flag=wx.ALIGN_LEFT, pos=(0, 0))
- self.regionBox = wx.RadioBox(
- parent=self,
- id=wx.ID_ANY,
- label=_("Choose a method"),
- choices=[
- _('Use keyboard to enter sampling area'),
- _('Use mouse to draw sampling area')],
- majorDimension=1,
- style=wx.RA_SPECIFY_ROWS)
- #self.regionBox.EnableItem(1, False)
- self.regionBox.SetItemToolTip(1, _("This option is not supported yet"))
- self.sizer.Add(self.regionBox, flag=wx.ALIGN_CENTER, pos=(1, 0))
- # bindings
- self.radioBox.Bind(wx.EVT_RADIOBOX, self.SetVal)
- self.regionBox.Bind(wx.EVT_RADIOBOX, self.OnRegionDraw)
- self.regionbox = 'keyboard'
- self.regionPanelSizer = wx.GridBagSizer(1, 2)
- self.regionNumPanel = wx.Panel(parent=self, id=wx.ID_ANY)
- self.regionNumLabel = wx.StaticText(
- parent=self.regionNumPanel, id=wx.ID_ANY,
- label=_('Number of regions to draw:'))
- self.regionNumTxt = wx.TextCtrl(parent=self.regionNumPanel,
- id=wx.ID_ANY, size=(50, -1))
- self.regionPanelSizer.Add(self.regionNumLabel, flag=wx.ALIGN_CENTER,
- pos=(0, 0))
- self.regionPanelSizer.Add(self.regionNumTxt, flag=wx.ALIGN_CENTER,
- pos=(0, 1))
- self.regionNumPanel.SetSizer(self.regionPanelSizer)
- self.sizer.Add(self.regionNumPanel, flag=wx.ALIGN_CENTER, pos=(2, 0))
- self.areaPanelSizer = wx.GridBagSizer(2, 3)
- self.areaPanel = wx.Panel(parent=self, id=wx.ID_ANY)
- self.overwriteText = wx.StaticText(
- parent=self.areaPanel, id=wx.ID_ANY, label=_(
- 'Do you want to overwrite existing'
- ' temporal maps if they exist?'))
- self.overwriteCheck = wx.CheckBox(parent=self.areaPanel, id=wx.ID_ANY)
- self.areaText = wx.StaticText(
- parent=self.areaPanel, id=wx.ID_ANY,
- label=_('Do you want to check vector areas?'))
- self.areaOK = wx.Button(self.areaPanel, wx.ID_ANY, 'Yes', (50, 80))
- self.areaOK.SetToolTip(wx.ToolTip(_("Select if use area by area")))
- self.areaNO = wx.Button(self.areaPanel, wx.ID_ANY, 'No', (50, 80))
- self.areaNO.SetToolTip(wx.ToolTip(_("All the features will be used")))
- self.areaOK.Bind(wx.EVT_BUTTON, self.OnVectYes)
- self.areaNO.Bind(wx.EVT_BUTTON, self.OnVectNo)
- self.overwriteCheck.Bind(wx.EVT_CHECKBOX, self.OnOverwrite)
- self.areaPanelSizer.Add(self.overwriteText, flag=wx.ALIGN_CENTER,
- pos=(0, 0))
- self.areaPanelSizer.Add(self.overwriteCheck, flag=wx.ALIGN_CENTER,
- pos=(0, 1))
- self.areaPanelSizer.Add(self.areaText, flag=wx.ALIGN_CENTER,
- pos=(1, 0))
- self.areaPanelSizer.Add(self.areaOK, flag=wx.ALIGN_CENTER, pos=(1, 1))
- self.areaPanelSizer.Add(self.areaNO, flag=wx.ALIGN_CENTER, pos=(1, 2))
- self.areaPanel.SetSizer(self.areaPanelSizer)
- self.sizer.Add(self.areaPanel, flag=wx.ALIGN_CENTER, pos=(3, 0))
- self.calculatingAreas = wx.StaticText(
- parent=self, id=wx.ID_ANY,
- label=_('Analysing all vector features...'))
- self.sizer.Add(self.calculatingAreas, flag=wx.ALIGN_CENTER, pos=(4, 0))
- self.numregions = ''
- self.regionNumTxt.Bind(wx.EVT_TEXT, self.OnNumRegions)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- def OnNumRegions(self, event):
- """Obtain the number of regions"""
- if self.regionNumTxt.GetValue():
- self.SetNext(self.parent.regions)
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- self.numregions = self.regionNumTxt.GetValue()
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- def OnEnterPage(self, event):
- """Insert values into text controls for summary of location
- creation options
- """
- self.SetVal(None)
- if self.parent.startpage.vect:
- self.radioBox.ShowItem(4, True)
- self.vect_data = []
- else:
- self.radioBox.ShowItem(4, False)
- self.sizer.Layout()
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- def SetVal(self, event):
- """Choose method"""
- radio = self.radioBox.GetSelection()
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- if radio == 0:
- self.samplingtype = SamplingType.WHOLE
- self.DrawNothing()
- elif radio == 1:
- self.samplingtype = SamplingType.REGIONS
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- elif radio == 2:
- self.samplingtype = SamplingType.UNITS
- regtype = self.regionBox.GetSelection()
- self.RegionDraw(regtype)
- elif radio == 3:
- self.samplingtype = SamplingType.MVWIN
- regtype = self.regionBox.GetSelection()
- self.RegionDraw(regtype)
- elif radio == 4:
- self.samplingtype = SamplingType.VECT
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- self.ShowExtraOptions(self.samplingtype)
- def ShowExtraOptions(self, samtype):
- """Show some extra options for some sampling type"""
- if samtype == SamplingType.REGIONS:
- self.sizer.Hide(self.regionBox)
- self.sizer.Hide(self.areaPanel)
- self.sizer.Hide(self.calculatingAreas)
- self.sizer.Show(self.regionNumPanel)
- elif samtype == SamplingType.UNITS or samtype == SamplingType.MVWIN:
- self.sizer.Hide(self.regionNumPanel)
- self.sizer.Hide(self.areaPanel)
- self.sizer.Hide(self.calculatingAreas)
- self.sizer.Show(self.regionBox)
- elif samtype == SamplingType.VECT:
- self.sizer.Hide(self.regionBox)
- self.sizer.Hide(self.regionNumPanel)
- self.sizer.Hide(self.calculatingAreas)
- self.sizer.Show(self.areaPanel)
- self.sizer.Layout()
- def OnRegionDraw(self, event):
- self.RegionDraw(event.GetInt())
- return
- def OnOverwrite(self, event):
- self.overwriteTemp = self.overwriteCheck.GetValue()
- return
- def OnVectYes(self, event):
- """The user choose to select the vector areas, this function set the
- next page to VectorAreasPage"""
- self.SetNext(self.parent.vectorareas)
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- self.parent.wizard.ShowPage(self.parent.vectorareas)
- def OnVectNo(self, event):
- """The user choose to use all the vector areas, this function analyses
- all the vector areas and fill the msAreaList variable"""
- self.sizer.Show(self.calculatingAreas)
- self.sizer.Hide(self.regionNumPanel)
- self.sizer.Hide(self.regionBox)
- self.sizer.Hide(self.areaPanel)
- self.SetNext(self.parent.summarypage)
- vect_cats = obtainCategories(self.parent.startpage.vect,
- self.parent.startpage.vectorlayer)
- self._progressDlg = wx.ProgressDialog(
- title=_("Analysing vector"),
- message="Analysing vector",
- maximum=len(vect_cats),
- parent=self,
- style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_SMOOTH)
- self._progressDlgMax = len(vect_cats)
- grass.use_temp_region()
- self.parent.msAreaList = sampleAreaVector(
- self.parent.startpage.vect,
- self.parent.startpage.rast,
- vect_cats,
- self.parent.startpage.vectorlayer,
- self.overwriteTemp,
- self._progressDlg)
- grass.del_temp_region()
- if self.parent.msAreaList:
- self.calculatingAreas.SetLabel(_("All feature are been analyzed."))
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- self.parent.wizard.ShowPage(self.parent.summarypage)
- else:
- self.calculatingAreas.SetLabel(_("An error occurred"))
- self._progressDlg.Destroy()
- self._progressDlg = None
- def RegionDraw(self, regtype):
- """Set the next page to units or drawunits"""
- if regtype == 0:
- self.regionbox = 'keyboard'
- if self.samplingtype == SamplingType.UNITS:
- self.SetNext(self.parent.units)
- elif self.samplingtype == SamplingType.MVWIN:
- self.SetNext(self.parent.moving)
- elif regtype == 1:
- self.regionbox = 'mouse'
- self.SetNext(self.parent.drawunits)
- def DrawNothing(self):
- """Remove all the optional choices. Used also when the wizard enter in
- SamplingAreasPage, all the optional choices should be hide here"""
- self.sizer.Hide(self.regionNumPanel)
- self.sizer.Hide(self.regionBox)
- self.sizer.Hide(self.areaPanel)
- self.sizer.Hide(self.calculatingAreas)
- self.sizer.Layout()
- self.SetNext(self.parent.summarypage)
- class DrawRegionsPage(TitledPage):
- def __init__(self, wizard, parent):
- self.parent = parent
- TitledPage.__init__(self, wizard, _("Draw sampling regions"))
- self.regioncount = 0
- self.mapPanel = None
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
- def afterRegionDrawn(self, marea):
- if marea:
- self.parent.msAreaList.append(marea)
- self.regioncount = self.regioncount + 1
- numregions = int(self.parent.samplingareapage.numregions)
- if self.regioncount > numregions:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- self.parent.wizard.ShowPage(self.parent.summarypage)
- else:
- self.title.SetLabel(_('Draw sample region ' +
- str(self.regioncount) + ' of ' +
- str(numregions)))
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- def OnEnterPage(self, event):
- """Function during entering"""
- if self.parent.samplingareapage.samplingtype == SamplingType.WHOLE:
- self.title.SetLabel(_("Draw moving windows region"))
- elif self.parent.samplingareapage.samplingtype == SamplingType.UNITS:
- self.title.SetLabel(_("Draw sampling region"))
- if self.mapPanel is None:
- self.mapPanel = RLiSetupMapPanel(
- self, samplingType=self.parent.samplingareapage.samplingtype, )
- self.mapPanel.afterRegionDrawn.connect(self.afterRegionDrawn)
- self.sizer.Add(self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
- self.sizer.AddGrowableCol(0)
- self.sizer.AddGrowableRow(1)
- self._raster = None
- rast = self.parent.startpage.rast
- self.afterRegionDrawn(marea=None)
- if self._raster != rast:
- map_ = self.mapPanel.GetMap()
- map_.DeleteAllLayers()
- cmdlist = ['d.rast', 'map=%s' % rast]
- map_.AddLayer(ltype='raster', command=cmdlist, active=True,
- name=rast, hidden=False, opacity=1.0, render=True)
- # def OnExitPage(self, event=None):
- #!Function during exiting
- # print event.GetDirection()
- # if event.GetDirection():
- # self.SetNext(self.parent.samplingareapage)
- # self.parent.samplingareapage.SetPrev(self)
- class SampleUnitsKeyPage(TitledPage):
- """Set values from keyboard for sample units
- It is used if you choose keyboard from Sampling Units or Moving windows
- in sampling areas page
- """
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _(
- "Select sample units from keyboard"))
- self.parent = parent
- self.scrollPanel = scrolled.ScrolledPanel(parent=self, id=wx.ID_ANY)
- self.scrollPanel.SetupScrolling(scroll_x=False)
- self.panelSizer = wx.GridBagSizer(5, 5)
- self.width = ''
- self.height = ''
- self.boxtype = 'rectangle'
- self.distrtype = 'non_overlapping'
- # type of shape
- self.typeBox = wx.RadioBox(parent=self.scrollPanel, id=wx.ID_ANY,
- majorDimension=1, style=wx.RA_SPECIFY_COLS,
- label=" %s " % _("Select type of shape"),
- choices=[_('Rectangle'), _('Circle'),
- ('None')])
- self.panelSizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
- span=(1, 2))
- self.widthLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
- self.widthTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
- size=(250, -1))
- self.panelSizer.Add(
- self.widthLabel, pos=(1, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.panelSizer.Add(
- self.widthTxt, pos=(1, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.heightLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
- self.heightTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
- size=(250, -1))
- self.panelSizer.Add(
- self.heightLabel, pos=(2, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.panelSizer.Add(
- self.heightTxt, pos=(2, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.widthLabels = [_('Width size (in cells)?'),
- _('What radius size (in meters)?')]
- self.heightLabels = [_('Height size (in cells)?'),
- _('Name of the circle mask')]
- self.distributionBox = wx.RadioBox(
- parent=self.scrollPanel,
- id=wx.ID_ANY,
- majorDimension=1,
- style=wx.RA_SPECIFY_COLS,
- label=" %s " %
- _("Select method of sampling unit distribution"),
- choices=[
- _('Random non overlapping'),
- _('Systematic contiguos'),
- _('Stratified random'),
- _('Systematic non contiguos'),
- _('Centered over sites')])
- self.panelSizer.Add(self.distributionBox, pos=(3, 0), span=(
- 1, 2), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.distr1Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
- label=_("What number of Sampling "
- "Units to use?"))
- self.distr1Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
- size=(250, -1))
- self.panelSizer.Add(
- self.distr1Label, pos=(4, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.panelSizer.Add(
- self.distr1Txt, pos=(4, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.distr2Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
- label="")
- self.distr2Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
- size=(250, -1))
- self.panelSizer.Add(
- self.distr2Label, pos=(5, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.panelSizer.Add(
- self.distr2Txt, pos=(5, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.panelSizer.Hide(self.distr2Txt)
- self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
- self.distributionBox.Bind(wx.EVT_RADIOBOX, self.OnDistr)
- self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
- self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
- self.distr1Txt.Bind(wx.EVT_TEXT, self.OnDistr1)
- self.distr2Txt.Bind(wx.EVT_TEXT, self.OnDistr2)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- self.sizer.Add(self.scrollPanel, pos=(0, 0), flag=wx.EXPAND)
- self.sizer.AddGrowableCol(0)
- self.sizer.AddGrowableRow(0)
- self.scrollPanel.SetSizer(self.panelSizer)
- #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
- self.OnType(None)
- def OnEnterPage(self, event=None):
- """Function during entering"""
- # This is an hack to force the user to choose Rectangle or Circle
- self.typeBox.SetSelection(2),
- self.typeBox.ShowItem(2, False)
- self.panelSizer.Layout()
- def OnExitPage(self, event=None):
- """Function during exiting"""
- if event.GetDirection():
- self.SetNext(self.parent.summarypage)
- self.SetPrev(self.parent.samplingareapage)
- def OnType(self, event):
- """Set if rectangle or circle will be used"""
- chosen = self.typeBox.GetSelection()
- self.widthLabel.SetLabel(self.widthLabels[chosen])
- self.heightLabel.SetLabel(self.heightLabels[chosen])
- self.panelSizer.Layout()
- if chosen == 0:
- self.boxtype = 'rectangle'
- else:
- self.boxtype = 'circle'
- def OnDistr(self, event):
- chosen = self.distributionBox.GetSelection()
- if chosen == 0:
- self.distrtype = 'non_overlapping'
- self.distr1Label.SetLabel(
- _("What number of Sampling Units to use?"))
- self.panelSizer.Show(self.distr1Txt)
- self.distr2Label.SetLabel("")
- self.panelSizer.Hide(self.distr2Txt)
- self.panelSizer.Layout()
- elif chosen == 1:
- self.distrtype = 'systematic_contiguos'
- self.distr1Label.SetLabel("")
- self.distr2Label.SetLabel("")
- self.panelSizer.Hide(self.distr1Txt)
- self.panelSizer.Hide(self.distr2Txt)
- self.panelSizer.Layout()
- elif chosen == 2:
- self.distrtype = 'stratified_random'
- self.distr1Label.SetLabel(_("Insert number of row strates"))
- self.distr2Label.SetLabel(_("Insert number of column strates"))
- self.panelSizer.Show(self.distr1Txt)
- self.panelSizer.Show(self.distr2Txt)
- self.panelSizer.Layout()
- elif chosen == 3:
- self.distrtype = 'systematic_noncontiguos'
- self.distr1Label.SetLabel(_("Insert distance between units"))
- self.panelSizer.Show(self.distr1Txt)
- self.distr2Label.SetLabel("")
- self.panelSizer.Hide(self.distr2Txt)
- self.panelSizer.Layout()
- elif chosen == 4:
- self.distrtype = 'centered_oversites'
- self.distr1Label.SetLabel("")
- self.distr2Label.SetLabel("")
- self.panelSizer.Hide(self.distr2Txt)
- self.panelSizer.Hide(self.distr1Txt)
- self.panelSizer.Layout()
- def OnWidth(self, event):
- self.width = self.widthTxt.GetValue()
- def OnHeight(self, event):
- self.height = self.heightTxt.GetValue()
- def OnDistr1(self, event):
- self.distr1 = self.distr1Txt.GetValue()
- def OnDistr2(self, event):
- self.distr2 = self.distr2Txt.GetValue()
- class MovingKeyPage(TitledPage):
- """Set values from keyboard for sample units"""
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Set sample units"))
- self.parent = parent
- self.width = ''
- self.height = ''
- self.boxtype = 'rectangle'
- # type of shape
- self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
- label=" %s " % _("Select type of shape"),
- choices=[_('Rectangle'), _('Circle')],
- # ('None')],
- majorDimension=1,
- style=wx.RA_SPECIFY_COLS)
- self.sizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(1, 1))
- self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- self.widthLabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label=_('Width size (in cells)?'))
- self.widthTxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
- self.sizer.Add(self.widthLabel, border=5, pos=(2, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.widthTxt, border=5, pos=(2, 2),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.heightLabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label=_('Height size (in cells)?'))
- self.heightTxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
- self.sizer.Add(self.heightLabel, border=5, pos=(3, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.heightTxt, border=5, pos=(3, 2),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.AddGrowableCol(2)
- self.widthLabels = [_('Width size (in cells)?'),
- _('What radius size (in meters)?')]
- self.heightLabels = [_('Height size (in cells)?'),
- _('Name of the circle mask')]
- self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
- self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- def OnEnterPage(self, event):
- # This is an hack to force the user to choose Rectangle or Circle
- # self.typeBox.SetSelection(2),
- # self.typeBox.ShowItem(2, False)
- if self.parent.samplingareapage.samplingtype == SamplingType.MVWIN:
- self.title.SetLabel(_("Set moving windows"))
- self.OnType(None)
- def OnType(self, event):
- chosen = self.typeBox.GetSelection()
- self.widthLabel.SetLabel(self.widthLabels[chosen])
- self.heightLabel.SetLabel(self.heightLabels[chosen])
- self.sizer.Layout()
- if chosen == 0:
- self.parent.samplingareapage.samplingtype = SamplingType.KMVWINR
- self.boxtype = 'rectangle'
- elif chosen == 1:
- self.parent.samplingareapage.samplingtype = SamplingType.KMVWINC
- self.boxtype = 'circle'
- def CheckInput(self):
- """Check input fields.
- :return: True if configuration file is given and raster xor
- vector map, False otherwise
- """
- return bool(self.width and bool(self.height))
- def OnWidth(self, event):
- self.width = self.widthTxt.GetValue()
- next = wx.FindWindowById(wx.ID_FORWARD)
- next.Enable(self.CheckInput())
- def OnHeight(self, event):
- self.height = self.heightTxt.GetValue()
- next = wx.FindWindowById(wx.ID_FORWARD)
- next.Enable(self.CheckInput())
- class UnitsMousePage(TitledPage):
- """Choose the sampling area setting the values using the mouse drawing the
- areas with rectangle or circle. It is used both from 'Moving windows'
- and 'Sample units'.
- """
- def __init__(self, wizard, parent):
- self.parent = parent
- self.wizard = wizard
- TitledPage.__init__(self, self.wizard, _("Draw sampling units"))
- self.numregions = ''
- self.mapPanel = None
- # type of shape
- self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
- majorDimension=1, style=wx.RA_SPECIFY_COLS,
- label=" %s " % _("Select type of shape"),
- choices=[_('Rectangle'), _('Circle'), ('')])
- # This is an hack to force the user to choose Rectangle or Circle
- self.typeBox.SetSelection(2),
- self.typeBox.ShowItem(2, False)
- self.sizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
- span=(1, 2))
- self.regionPanelSizer = wx.GridBagSizer(1, 2)
- self.regionNumPanel = wx.Panel(parent=self, id=wx.ID_ANY)
- self.regionNumLabel = wx.StaticText(
- parent=self.regionNumPanel, id=wx.ID_ANY,
- label=_('Number of sampling area to draw:'))
- self.regionNumTxt = wx.TextCtrl(parent=self.regionNumPanel,
- id=wx.ID_ANY, size=(50, -1))
- self.regionPanelSizer.Add(self.regionNumLabel, flag=wx.ALIGN_CENTER,
- pos=(0, 0))
- self.regionPanelSizer.Add(self.regionNumTxt, flag=wx.ALIGN_CENTER,
- pos=(0, 1))
- self.regionNumPanel.SetSizer(self.regionPanelSizer)
- self.sizer.Add(self.regionNumPanel, flag=wx.ALIGN_LEFT, pos=(1, 0),
- span=(1, 2))
- self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
- self.regionNumTxt.Bind(wx.EVT_TEXT, self.OnNumRegions)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- self.sizer.AddGrowableCol(0)
- self.OnType(None)
- self.regionNumTxt.SetValue('')
- def OnEnterPage(self, event):
- """Function during entering"""
- if self.numregions:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- if self.parent.samplingareapage.samplingtype in [SamplingType.MVWIN,
- SamplingType.MMVWINR,
- SamplingType.MMVWINC]:
- self.title.SetLabel(_("Draw moving windows region"))
- self.sizer.Hide(self.regionNumPanel)
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- elif self.parent.samplingareapage.samplingtype in [SamplingType.UNITS,
- SamplingType.MUNITSR,
- SamplingType.MUNITSC]:
- self.title.SetLabel(_("Draw sampling region"))
- self.sizer.Show(self.regionNumPanel)
- if self.typeBox.GetSelection() == 2:
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- self.sizer.Layout()
- def OnType(self, event):
- chosen = self.typeBox.GetSelection()
- if chosen == 0:
- if self.parent.samplingareapage.samplingtype in [
- SamplingType.MVWIN, SamplingType.MMVWINR, SamplingType.MMVWINC]:
- self.parent.samplingareapage.samplingtype = SamplingType.MMVWINR
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- else:
- self.parent.samplingareapage.samplingtype = SamplingType.MUNITSR
- self.drawtype = 'rectangle'
- else:
- if self.parent.samplingareapage.samplingtype in [
- SamplingType.MVWIN, SamplingType.MMVWINR, SamplingType.MMVWINC]:
- self.parent.samplingareapage.samplingtype = SamplingType.MMVWINC
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- else:
- self.parent.samplingareapage.samplingtype = SamplingType.MUNITSC
- self.drawtype = 'circle'
- def OnNumRegions(self, event):
- """Set the number of region"""
- if self.regionNumTxt.GetValue():
- self.SetNext(self.parent.drawsampleunitspage)
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- self.numregions = self.regionNumTxt.GetValue()
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- def OnExitPage(self, event=None):
- """Function during exiting"""
- if event.GetDirection():
- self.SetNext(self.drawsampleunitspage)
- self.SetPrev(self.samplingareapage)
- class DrawSampleUnitsPage(TitledPage):
- """Choose the sampling area drawing them"""
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Draw sampling units"))
- self.parent = parent
- self.mapPanel = None
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
- def SampleFrameChanged(self, region):
- #region = self.GetSampleUnitRegion()
- if region:
- self.parent.msAreaList.append(region)
- self.regioncount = self.regioncount + 1
- drawtype = self.parent.drawunits.drawtype
- if self.regioncount > self.numregions:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- self.parent.wizard.ShowPage(self.parent.summarypage)
- else:
- self.title.SetLabel(_('Draw Sampling ' + drawtype + ' '
- + str(self.regioncount) + ' of '
- + str(self.numregions)))
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- def OnEnterPage(self, event):
- """Function during entering"""
- if self.parent.samplingareapage.samplingtype in [SamplingType.MVWIN,
- SamplingType.MMVWINC,
- SamplingType.MMVWINR]:
- self.numregions = 1
- else:
- self.numregions = int(self.parent.drawunits.numregions)
- self.regioncount = 0
- if self.mapPanel:
- self.sizer.Remove(self.mapPanel)
- gtype = self.parent.drawunits.drawtype
- self.mapPanel = RLiSetupMapPanel(
- self, samplingType=self.parent.samplingareapage.samplingtype, )
- if gtype == 'circle':
- self.mapPanel.afterCircleDrawn.connect(self.SampleFrameChanged)
- else:
- self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
- self.sizer.Add(self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
- self.sizer.AddGrowableCol(0)
- self.sizer.AddGrowableRow(1)
- self._raster = None
- self.SampleFrameChanged(region=None)
- rast = self.parent.startpage.rast
- if self._raster != rast:
- map_ = self.mapPanel.GetMap()
- map_.DeleteAllLayers()
- cmdlist = ['d.rast', 'map=%s' % rast]
- map_.AddLayer(ltype='raster', command=cmdlist, active=True,
- name=rast, hidden=False, opacity=1.0, render=True)
- def OnExitPage(self, event=None):
- #!Function during exiting
- print event.GetDirection()
- # if event.GetDirection():
- # self.SetNext(self.parent.samplingareapage)
- # self.parent.samplingareapage.SetPrev(self)
- class VectorAreasPage(TitledPage):
- """Choose the sampling area using the vector features"""
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Select sampling areas"))
- self.parent = parent
- self.areascount = 0
- self.mapPanel = None
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
- self.areaPanelSizer = wx.GridBagSizer(1, 3)
- self.areaPanel = wx.Panel(parent=self, id=wx.ID_ANY)
- self.areaText = wx.StaticText(parent=self.areaPanel, id=wx.ID_ANY,
- label=_('Is this area ok?'))
- self.areaOK = wx.Button(self.areaPanel, wx.ID_ANY, 'Yes', (50, 80))
- self.areaNO = wx.Button(self.areaPanel, wx.ID_ANY, 'No', (50, 80))
- self.areaOK.Bind(wx.EVT_BUTTON, self.OnYes)
- self.areaNO.Bind(wx.EVT_BUTTON, self.OnNo)
- self.areaPanelSizer.Add(self.areaText, flag=wx.ALIGN_CENTER,
- pos=(0, 0))
- self.areaPanelSizer.Add(self.areaOK, flag=wx.ALIGN_CENTER,
- pos=(0, 1))
- self.areaPanelSizer.Add(self.areaNO, flag=wx.ALIGN_CENTER,
- pos=(0, 2))
- self.areaPanel.SetSizer(self.areaPanelSizer)
- self.sizer.Add(self.areaPanel, flag=wx.ALIGN_CENTER, pos=(2, 0))
- def afterRegionDrawn(self):
- """Function to update the title and the number of selected area"""
- self.areascount = self.areascount + 1
- if self.areascount == self.areanum:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
- self.areaOK.Enable(False)
- self.areaNO.Enable(False)
- return True
- else:
- self.title.SetLabel(_('Select sample area ' + str(self.areascount + 1)
- + ' of ' + str(self.areanum)))
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- return False
- def OnYes(self, event):
- """Function to create the string for the conf file if the area
- is selected"""
- self.parent.msAreaList.append(obtainAreaVector(self.outname))
- if not self.afterRegionDrawn():
- self.newCat()
- def OnNo(self, event):
- """Function to pass to the next feature if it is not selected"""
- if not self.afterRegionDrawn():
- self.newCat()
- def newCat(self):
- """Convert to raster and draw the new feature"""
- cat = self.vect_cats[self.areascount]
- self.outpref = "{rast}_{vect}_".format(vect=self.vect.split('@')[0],
- rast=self.rast.split('@')[0])
- self.outname = "{pref}{cat}".format(pref=self.outpref, cat=cat)
- # check if raster already axist
- if len(grass.list_strings('raster', pattern=self.outname, mapset='.')
- ) == 1 and not self.parent.samplingareapage.overwriteTemp:
- GError(parent=self, message=_("The raster map <%s> already exists."
- " Please remove or rename the maps "
- "with the prefix '%s' or select the "
- "option to overwrite existing maps"
- % (self.outname, self.outpref)))
- self.parent.wizard.ShowPage(self.parent.samplingareapage)
- return
- convertFeature(self.vect, self.outname, cat, self.rast,
- self.parent.startpage.vectorlayer,
- self.parent.samplingareapage.overwriteTemp)
- cmdlistcat = ['d.rast', 'map=%s' % self.outname]
- self.map_.AddLayer(ltype='raster', command=cmdlistcat, active=True,
- name=self.outname, hidden=False, opacity=1.0,
- render=True)
- for l in self.map_.GetListOfLayers():
- if l.name == self.outname:
- self.mapPanel.mapWindow.ZoomToMap(layers=[l], render=True,
- ignoreNulls=True)
- elif l.name != self.rast:
- self.map_.DeleteLayer(l)
- self.areaText.SetLabel("Is this area (cat={n}) ok?".format(n=cat))
- def OnEnterPage(self, event):
- """Function during entering: draw the raster map and the first vector
- feature"""
- print self.parent.samplingareapage.overwriteTemp
- if self.mapPanel is None:
- self.mapPanel = RLiSetupMapPanel(
- self, samplingType=self.parent.samplingareapage.samplingtype)
- self.sizer.Add(self.mapPanel, flag=wx.EXPAND, pos=(1, 0))
- self.sizer.AddGrowableCol(0)
- self.sizer.AddGrowableRow(1)
- self._raster = None
- self.rast = self.parent.startpage.rast
- self.vect = self.parent.startpage.vect
- self.vect_cats = obtainCategories(
- self.vect, layer=self.parent.startpage.vectorlayer)
- self.areanum = len(self.vect_cats)
- if self.areanum == 0:
- GError(parent=self, message=_("The polygon seems to have 0 areas"))
- self.parent.wizard.ShowPage(self.parent.samplingareapage)
- return
- self.title.SetLabel(_('Select sample area 1 of ' + str(self.areanum)))
- grass.use_temp_region()
- if self._raster != self.rast:
- self.map_ = self.mapPanel.GetMap()
- self.map_.DeleteAllLayers()
- cmdlist = ['d.rast', 'map=%s' % self.rast]
- self.map_.AddLayer(ltype='raster', command=cmdlist, active=True,
- name=self.rast, hidden=False, opacity=1.0,
- render=True)
- self.newCat()
- def OnExitPage(self, event=None):
- """Function during exiting"""
- grass.del_temp_region()
- # if event.GetDirection():
- # self.SetNext(self.parent.samplingareapage)
- # self.parent.samplingareapage.SetPrev(self)
- class SummaryPage(TitledPage):
- """Shows summary result of choosing data"""
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Summary"))
- global rlisettings
- self.parent = parent
- # configuration file name
- self.conflabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label=_('Configuration file name:'))
- self.conftxt = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.sizer.Add(self.conflabel, border=5, pos=(0, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.conftxt, border=5, pos=(0, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # raster name
- self.rastlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label=_('Raster name:'))
- self.rasttxt = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.sizer.Add(self.rastlabel, border=5, pos=(1, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.rasttxt, border=5, pos=(1, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # vector name
- self.vectlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label=_('Vector name:'))
- self.vecttxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.sizer.Add(self.vectlabel, border=5, pos=(2, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.vecttxt, border=5, pos=(2, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # region type name
- self.regionlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label=_('Region type:'))
- self.regiontxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.sizer.Add(self.regionlabel, border=5, pos=(3, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.regiontxt, border=5, pos=(3, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # region keyboard
- self.regionkeylabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.regionkeytxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.sizer.Add(self.regionkeylabel, border=5, pos=(4, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.regionkeytxt, border=5, pos=(4, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- # sampling area
- self.samplinglabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label=_('Sampling area type:'))
- self.samplingtxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.sizer.Add(self.samplinglabel, border=5, pos=(5, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.samplingtxt, border=5, pos=(5, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # shapetype
- self.shapelabel = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.shapetxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.sizer.Add(self.shapelabel, border=5, pos=(6, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.shapetxt, border=5, pos=(6, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # shapedim
- self.shapewidthlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.shapewidthtxt = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.sizer.Add(self.shapewidthlabel, border=5, pos=(7, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.shapewidthtxt, border=5, pos=(7, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.shapeheightlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.shapeheighttxt = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.sizer.Add(self.shapeheightlabel, border=5, pos=(8, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.shapeheighttxt, border=5, pos=(8, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # units type
- self.unitslabel = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.unitstxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.sizer.Add(self.unitslabel, border=5, pos=(9, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.unitstxt, border=5, pos=(9, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.unitsmorelabel = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.unitsmoretxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.sizer.Add(self.unitsmorelabel, border=5, pos=(10, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.unitsmoretxt, border=5, pos=(10, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.unitsmorelabel2 = wx.StaticText(parent=self, id=wx.ID_ANY,
- label="")
- self.unitsmoretxt2 = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
- self.sizer.Add(self.unitsmorelabel2, border=5, pos=(11, 0),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.unitsmoretxt2, border=5, pos=(11, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- def OnEnterPage(self, event):
- """Insert values into text controls for summary of location
- creation options
- """
- self.conftxt.SetLabel(self.parent.startpage.conf_name)
- self.rasttxt.SetLabel(self.parent.startpage.rast)
- self.samplingtxt.SetLabel(self.parent.samplingareapage.samplingtype)
- self.regiontxt.SetLabel(self.parent.startpage.region)
- self.vecttxt.SetLabel(self.parent.startpage.vect)
- if self.parent.startpage.region == 'key':
- # region keyboard values
- self.regionkeylabel.SetLabel(_('Region keyboard values:'))
- regKeyVals = "Column left up: %s - Row left up: %s\n" \
- "Column length: %s - Row length: %s\n" % (
- self.parent.keyboardpage.col_up,
- self.parent.keyboardpage.row_up,
- self.parent.keyboardpage.col_len,
- self.parent.keyboardpage.row_len)
- self.regionkeytxt.SetLabel(regKeyVals)
- else:
- self.regionkeylabel.SetLabel("")
- self.regionkeytxt.SetLabel("")
- if self.parent.samplingareapage.samplingtype == SamplingType.UNITS \
- and self.parent.samplingareapage.regionbox == 'keyboard':
- self.shapelabel.SetLabel(_('Type of shape:'))
- self.shapetxt.SetLabel(self.parent.units.boxtype)
- if self.parent.units.boxtype == 'circle':
- self.shapewidthlabel.SetLabel(_("Radius size:"))
- self.shapeheightlabel.SetLabel(_("Name circle mask:"))
- else:
- self.shapewidthlabel.SetLabel(_("Width size:"))
- self.shapeheightlabel.SetLabel(_("Height size:"))
- self.shapewidthtxt.SetLabel(self.parent.units.width)
- self.shapeheighttxt.SetLabel(self.parent.units.height)
- self.unitslabel.SetLabel(_("Method of distribution:"))
- self.unitstxt.SetLabel(self.parent.units.distrtype)
- if self.parent.units.distrtype == 'non_overlapping':
- self.unitsmorelabel.SetLabel(_("Number sampling units:"))
- self.unitsmoretxt.SetLabel(self.parent.units.distr1)
- elif self.parent.units.distrtype == 'systematic_noncontiguos':
- self.unitsmorelabel.SetLabel(_("Distance between units:"))
- self.unitsmoretxt.SetLabel(self.parent.units.distr1)
- elif self.parent.units.distrtype == 'stratified_random':
- self.unitsmorelabel.SetLabel(_("Number row strates:"))
- self.unitsmoretxt.SetLabel(self.parent.units.distr1)
- self.unitsmorelabel2.SetLabel(_("Number column strates:"))
- self.unitsmoretxt2.SetLabel(self.parent.units.distr2)
- elif self.parent.samplingareapage.samplingtype == SamplingType.UNITS \
- and self.parent.samplingareapage.regionbox == 'mouse':
- self.shapelabel.SetLabel(_('Type of shape:'))
- self.shapetxt.SetLabel(self.parent.units.boxtype)
- self.unitstxt.SetLabel('by mouse')
- elif self.parent.samplingareapage.samplingtype == 'moving':
- self.shapelabel.SetLabel(_('Type of shape:'))
- self.shapetxt.SetLabel(self.parent.moving.boxtype)
- if self.parent.moving.boxtype == 'circle':
- self.shapewidthlabel.SetLabel(_("Radius size:"))
- self.shapeheightlabel.SetLabel(_("Name circle mask:"))
- else:
- self.shapewidthlabel.SetLabel(_("Width size:"))
- self.shapeheightlabel.SetLabel(_("Height size:"))
- self.shapewidthtxt.SetLabel(self.parent.moving.width)
- self.shapeheighttxt.SetLabel(self.parent.moving.height)
- else:
- self.shapelabel.SetLabel("")
- self.shapetxt.SetLabel("")
- self.shapewidthlabel.SetLabel("")
- self.shapewidthtxt.SetLabel("")
- self.shapeheightlabel.SetLabel("")
- self.shapeheighttxt.SetLabel("")
|