4 @brief Georectification module for GRASS GIS. Includes ground control
5 point management and interactive point and click GCP creation
9 - manager::LocationPage
11 - manager::DispMapPage
16 - manager::GrSettingsDialog
18 (C) 2006-2011 by the GRASS Development Team
20 This program is free software under the GNU General Public License
21 (>=v2). Read the file COPYING that comes with GRASS for details.
23 @author Michael Barton
24 @author Updated by Martin Landa <landa.martin gmail.com>
25 @author Markus Metz redesign georectfier -> GCP Manager
33 from wx.lib.mixins.listctrl
import CheckListCtrlMixin, ColumnSorterMixin, ListCtrlAutoWidthMixin
34 import wx.lib.colourselect
as csel
35 import wx.wizard
as wiz
39 from core
import globalvar
40 from core
import utils
44 from core.gcmd import RunCommand, GMessage, GError, GWarning
62 stream = open(os.path.join(globalvar.ETCIMGDIR,
'small_up_arrow.png'),
'rb')
64 img = wx.ImageFromStream(stream)
70 stream = open(os.path.join(globalvar.ETCIMGDIR,
'small_down_arrow.png'),
'rb')
72 img = wx.ImageFromStream(stream)
80 Start wizard here and finish wizard here
98 for line
in f.readlines():
99 line = line.replace(
'\n',
'').strip()
102 key, value = line.split(
':', 1)
129 self.
wizard = wiz.Wizard(parent=parent, id=wx.ID_ANY, title=_(
"Setup for georectification"))
139 self.grouppage.SetNext(self.
mappage)
145 self.startpage.DoLayout()
146 self.grouppage.DoLayout()
147 self.mappage.DoLayout()
158 if self.wizard.RunWizard(self.
startpage):
161 GMessage(parent = self.
parent,
162 message = _(
"Georectifying setup canceled."))
165 GMessage(parent = self.
parent,
166 message = _(
"Georectifying setup canceled."))
183 if maptype ==
'cell':
184 rendertype =
'raster'
185 cmdlist = [
'd.rast',
'map=%s' % src_map]
187 rendertype =
'vector'
188 cmdlist = [
'd.vect',
'map=%s' % src_map]
192 self.SrcMap.AddLayer(type=rendertype, command=cmdlist, l_active=
True,
193 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
199 if maptype ==
'cell':
200 rendertype =
'raster'
201 cmdlist = [
'd.rast',
'map=%s' % tgt_map]
203 rendertype =
'vector'
204 cmdlist = [
'd.vect',
'map=%s' % tgt_map]
208 self.TgtMap.AddLayer(type=rendertype, command=cmdlist, l_active=
True,
209 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
215 toolbars=[
"gcpdisp"],
219 self.gcpmgr.InitMapDisplay()
220 self.gcpmgr.CenterOnScreen()
223 self.gcpmgr._mgr.Update()
228 """!Create environment to use for location and mapset
229 that are the source of the file(s) to georectify
231 @param location source location
232 @param mapset source mapset
234 @return False on error
235 @return True on success
252 for line
in self.gisrc_dict.items():
253 f.write(line[0] +
": " + line[1] +
"\n")
261 Switches between original working location/mapset and
262 location/mapset that is source of file(s) to georectify
270 elif grc ==
'source':
281 """!Layer Manager focus"""
287 """!Return to current location and mapset"""
289 self.parent.gcpmanagement =
None
291 self.wizard.Destroy()
295 Set map type (raster or vector) to georectify and
296 select location/mapset of map(s) to georectify.
299 TitledPage.__init__(self, wizard, _(
"Select map type and location/mapset"))
310 self.sizer.AddGrowableCol(2)
313 label=
' %s ' % _(
"Map type to georectify"),
314 choices=[_(
'raster'), _(
'vector')],
315 majorDimension=wx.RA_SPECIFY_COLS)
317 flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
318 pos=(1, 1), span=(1, 2))
321 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select source location:')),
322 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
326 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
330 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select source mapset:')),
331 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
336 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
346 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
350 """!Change map type"""
353 if event.GetInt() == 0:
359 """!Sets source location for map(s) to georectify"""
368 if item !=
'PERMANENT':
369 self.mapsetList.append(item)
373 self.mapsetList.insert(0,
'PERMANENT')
375 self.cb_mapset.SetStringSelection(self.
xymapset)
377 if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
378 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
381 """!Sets source mapset for map(s) to georectify"""
383 GMessage(_(
'You must select a valid location '
384 'before selecting a mapset'),
390 if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
391 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
394 if event.GetDirection()
and \
396 GMessage(_(
'You must select a valid location '
397 'and mapset in order to continue'),
406 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
408 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
412 Set group to georectify. Create group if desired.
415 TitledPage.__init__(self, wizard, _(
"Select image/map group to georectify"))
432 self.sizer.AddGrowableCol(2)
434 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select group:')),
435 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
437 self.
cb_group = wx.ComboBox(parent=self, id=wx.ID_ANY,
439 style=wx.CB_DROPDOWN | wx.CB_READONLY)
441 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
445 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Create group if none exists')),
446 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
448 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
449 self.
btn_mkgroup = wx.Button(parent=self, id=wx.ID_ANY, label=_(
"Create/edit group..."))
450 self.
btn_vgroup = wx.Button(parent=self, id=wx.ID_ANY, label=_(
"Add vector map to group..."))
452 flag=wx.RIGHT, border=5)
455 flag=wx.LEFT, border=5)
457 self.sizer.Add(item=btnSizer,
458 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
462 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Extension for output maps:')),
463 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
465 self.
ext_txt = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(350,-1))
467 self.sizer.Add(item=self.
ext_txt,
468 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
477 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
478 self.Bind(wx.EVT_CLOSE, self.parent.Cleanup)
481 self.btn_vgroup.Hide()
484 self.
xygroup = event.GetString()
487 """!Create new group in source location/mapset"""
488 dlg = GroupDialog(parent = self, defaultGroup = self.
xygroup)
491 gr = dlg.GetSelectedGroup()
492 if gr
in dlg.GetExistGroups():
502 """!Add vector maps to group"""
510 if dlg.ShowModal() != wx.ID_OK:
520 if event.GetDirection()
and self.
xygroup ==
'':
521 GMessage(_(
'You must select a valid image/map '
522 'group in order to continue'),
527 if event.GetDirection()
and self.
extension ==
'':
528 GMessage(_(
'You must enter an map name '
529 'extension in order to continue'),
539 self.
xylocation = self.parent.gisrc_dict[
'LOCATION_NAME']
540 self.
xymapset = self.parent.gisrc_dict[
'MAPSET']
557 self.groupList.append(item)
559 if maptype ==
'cell':
560 self.btn_vgroup.Hide()
563 elif maptype ==
'vector':
564 self.btn_vgroup.Show()
573 self.cb_group.SetStringSelection(self.
xygroup)
575 self.cb_group.SetSelection(0)
580 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
582 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
585 self.parent.SwitchEnv(
'source')
589 Select ungeoreferenced map to display for interactively
590 setting ground control points (GCPs).
593 TitledPage.__init__(self, wizard,
594 _(
"Select maps to display for ground control point (GCP) creation"))
602 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select source map to display:')),
603 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
607 size=globalvar.DIALOG_GSELECT_SIZE, type=maptype, updateOnPopup =
False)
610 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
613 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select target map to display:')),
614 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
618 size = globalvar.DIALOG_GSELECT_SIZE, type=maptype, updateOnPopup =
False)
621 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
630 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
631 self.Bind(wx.EVT_CLOSE, self.parent.Cleanup)
634 """!Source map to display selected"""
638 src_map = event.GetString()
641 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
643 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
647 if maptype ==
'cell':
649 elif maptype ==
'vector':
652 if p.returncode == 0:
653 print 'returncode = ', str(p.returncode)
654 self.parent.Map.region = self.parent.Map.GetRegion()
659 """!Source map to display selected"""
662 tgt_map = event.GetString()
668 if event.GetDirection()
and (src_map ==
''):
669 GMessage(_(
'You must select a source map '
670 'in order to continue'),
675 self.parent.SwitchEnv(
'target')
682 self.srcselection.SetElementList(maptype)
686 group = self.parent.grouppage.xygroup,
690 self.parent.src_maps = ret.splitlines()
692 GError(parent = self,
693 message = _(
'No maps in selected group <%s>.\n'
694 'Please edit group or select another group.') %
695 self.parent.grouppage.xygroup)
699 self.srcselection.tcp.GetElementList(elements = self.parent.src_maps)
700 src_map = self.parent.src_maps[0]
701 self.srcselection.SetValue(src_map)
703 self.parent.SwitchEnv(
'target')
704 self.tgtselection.SetElementList(maptype)
705 self.tgtselection.GetElementList()
706 self.parent.SwitchEnv(
'source')
709 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
711 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
713 class GCP(MapFrame, ColumnSorterMixin):
715 Manages ground control points for georectifying. Calculates RMS statics.
716 Calls i.rectify or v.transform to georectify map.
718 def __init__(self, parent, grwiz = None, id = wx.ID_ANY,
719 title = _(
"Manage Ground Control Points"),
720 size = (700, 300), toolbars = [
"gcpdisp"], Map =
None, lmgr =
None):
730 MapFrame.__init__(self, parent = parent, title = title, size = size,
731 Map = Map, toolbars = toolbars, lmgr = lmgr, name =
'GCPMapWindow')
737 self.parent.gcpmanagement = self
789 if os.path.exists(self.
file[
'points']):
790 shutil.copy(self.
file[
'points'], self.
file[
'points_bak'])
806 self.mapcoordlist.append([ 0,
828 self.
il = self.list.GetImageList(wx.IMAGE_LIST_SMALL)
832 self.
sm_dn = self.il.Add(SmallDnArrow)
833 self.
sm_up = self.il.Add(SmallUpArrow)
837 self.mapwin.mouse[
'box'] =
'point'
838 self.mapwin.mouse[
"use"] ==
"pointer"
839 self.mapwin.zoomtype = 0
840 self.mapwin.pen = wx.Pen(colour=
'black', width=2, style=wx.SOLID)
841 self.mapwin.SetCursor(self.cursors[
"cross"])
843 self.
mapwin = self.TgtMapWindow
846 self.mapwin.mouse[
'box'] =
'point'
847 self.mapwin.mouse[
"use"] ==
"pointer"
848 self.mapwin.zoomtype = 0
849 self.mapwin.pen = wx.Pen(colour=
'black', width=2, style=wx.SOLID)
850 self.mapwin.SetCursor(self.cursors[
"cross"])
858 self.OnZoomToMap(
None)
861 self.
Map = self.SrcMap
862 self.OnZoomToMap(
None)
867 self.Bind(wx.EVT_ACTIVATE, self.
OnFocus)
868 self.Bind(wx.EVT_CLOSE, self.
OnQuit)
871 """!Disable GCP manager mode"""
872 self.parent.gcpmanagement =
None
875 """!Create GCP List Control"""
877 return GCPList(parent=self, gcp=self)
901 ncols = self.list.GetColumnCount()
902 ColumnSorterMixin.__init__(self, ncols)
908 Sets rectification target to current location and mapset
917 self.grwiz.SwitchEnv(
'source')
921 location = tlocation,
923 self.grwiz.SwitchEnv(
'target')
927 Appends an item to GCP list
929 keyval = self.list.AddGCPItem() + 1
931 self.mapcoordlist.append([ keyval,
939 if self.statusbarManager.GetMode() == 8:
940 self.StatusbarUpdate()
944 Deletes selected item in GCP list
948 if self.list.GetItemCount() <= minNumOfItems:
949 GMessage(parent = self,
950 message=_(
"At least %d GCPs required. Operation canceled.") % minNumOfItems)
953 key = self.list.DeleteGCPItem()
958 index = self.list.FindItemData(-1, newkey + 1)
960 self.list.SetStringItem(index, 0, str(newkey))
961 self.list.SetItemData(index, newkey)
964 if self.list.GetItemCount() > 0:
965 if self.list.selected < self.list.GetItemCount():
966 self.list.selectedkey = self.list.GetItemData(self.list.selected)
968 self.list.selected = self.list.GetItemCount() - 1
969 self.list.selectedkey = self.list.GetItemData(self.list.selected)
971 self.list.SetItemState(self.list.selected,
972 wx.LIST_STATE_SELECTED,
973 wx.LIST_STATE_SELECTED)
975 self.list.selected = wx.NOT_FOUND
976 self.list.selectedkey = -1
980 if self.statusbarManager.GetMode() == 8:
981 self.StatusbarUpdate()
982 if self.list.selectedkey > 0:
983 self.statusbarManager.SetProperty(
'gotoGCP', self.list.selectedkey)
987 Clears all values in selected item of GCP list and unchecks it
989 index = self.list.GetSelected()
990 key = self.list.GetItemData(index)
992 for i
in range(1, 5):
993 self.list.SetStringItem(index, i,
'0.0')
994 self.list.SetStringItem(index, 5,
'')
995 self.list.SetStringItem(index, 6,
'')
996 self.list.CheckItem(index,
False)
999 self.
mapcoordlist[key] = [key, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
1003 Updates GCP and map coord maps and redraws
1004 active (checked) GCP markers
1006 self.
highest_only = UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'highestonly')
1008 self.
show_unused = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'unused')
1009 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'color')
1010 wxLowCol = wx.Colour(col[0], col[1], col[2], 255)
1011 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'hcolor')
1012 wxHiCol = wx.Colour(col[0], col[1], col[2], 255)
1013 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'scolor')
1014 wxSelCol = wx.Colour(col[0], col[1], col[2], 255)
1015 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'ucolor')
1016 wxUnCol = wx.Colour(col[0], col[1], col[2], 255)
1017 spx = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'size')
1018 wpx = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'width')
1019 font = self.GetFont()
1020 font.SetPointSize(int(spx) + 2)
1022 penOrig = polypenOrig =
None
1026 if coordtype ==
'source':
1027 mapWin = self.SrcMapWindow
1030 elif coordtype ==
'target':
1031 mapWin = self.TgtMapWindow
1036 GError(parent = self,
1037 message=
"%s%s." % (_(
"mapwin not defined for "),
1042 for idx
in range(self.list.GetItemCount()):
1044 key = self.list.GetItemData(idx)
1047 if not self.list.IsChecked(idx):
1064 if idx == self.list.selected:
1068 penOrig = mapWin.pen
1069 polypenOrig = mapWin.polypen
1070 mapWin.pen = wx.Pen(colour=wxCol, width=wpx, style=wx.SOLID)
1071 mapWin.polypen = wx.Pen(colour=wxCol, width=wpx, style=wx.SOLID)
1073 mapWin.pen.SetColour(wxCol)
1074 mapWin.polypen.SetColour(wxCol)
1076 coord = mapWin.Cell2Pixel((gcp[e_idx], gcp[n_idx]))
1077 mapWin.DrawCross(pdc=mapWin.pdcTmp, coords=coord,
1078 size=spx, text={
'text' :
'%s' % str(gcp[0]),
1082 'coords': [coord[0] + 5,
1088 mapWin.pen = penOrig
1089 mapWin.polypen = polypenOrig
1091 def SetGCPData(self, coordtype, coord, mapdisp=None, confirm=False):
1093 Inserts coordinates from file, mouse click on map, or after editing
1094 into selected item of GCP list and checks it for use
1097 index = self.list.GetSelected()
1098 if index == wx.NOT_FOUND:
1104 key = self.list.GetItemData(index)
1107 currloc = _(
"source")
1109 currloc = _(
"target")
1110 ret = wx.MessageBox(parent=self,
1111 caption=_(
"Set GCP coordinates"),
1112 message=_(
'Set %(coor)s coordinates for GCP No. %(key)s? \n\n'
1113 'East: %(coor0)s \n'
1114 'North: %(coor1)s') % \
1117 'coor0' : str(coord0),
1118 'coor1' : str(coord1) },
1119 style=wx.ICON_QUESTION | wx.YES_NO | wx.CENTRE)
1123 self.MapWindow.SetFocus()
1127 if coordtype ==
'source':
1128 self.list.SetStringItem(index, 1, str(coord0))
1129 self.list.SetStringItem(index, 2, str(coord1))
1132 elif coordtype ==
'target':
1133 self.list.SetStringItem(index, 3, str(coord0))
1134 self.list.SetStringItem(index, 4, str(coord1))
1138 self.list.SetStringItem(index, 5,
'0')
1139 self.list.SetStringItem(index, 6,
'0')
1147 Make a POINTS file or save GCP coordinates to existing POINTS file
1152 f = open(self.
file[
'points'], mode=
'w')
1154 f.write(
'# Ground Control Points File\n')
1158 f.write(
"#\tsource\t\ttarget\t\tstatus\n")
1159 f.write(
"#\teast\tnorth\teast\tnorth\t(1=ok, 0=ignore)\n")
1160 f.write(
"#----------------------- ----------------------- ---------------\n")
1162 for index
in range(self.list.GetItemCount()):
1163 if self.list.IsChecked(index) ==
True:
1168 coord0 = self.list.GetItem(index, 1).GetText()
1169 coord1 = self.list.GetItem(index, 2).GetText()
1170 coord2 = self.list.GetItem(index, 3).GetText()
1171 coord3 = self.list.GetItem(index, 4).GetText()
1172 f.write(coord0 +
' ' + coord1 +
' ' + coord2 +
' ' + coord3 +
' ' + check +
'\n')
1174 except IOError, err:
1175 GError(parent = self,
1176 message=
"%s <%s>. %s%s" % (_(
"Writing POINTS file failed"),
1177 self.
file[
'points'], os.linesep, err))
1184 shutil.copy(self.
file[
'points'], self.
file[
'points_bak'])
1185 self.parent.goutput.WriteLog(_(
'POINTS file saved for group <%s>') % self.
xygroup)
1190 Reads GCPs and georectified coordinates from POINTS file
1195 sourceMapWin = self.SrcMapWindow
1196 targetMapWin = self.TgtMapWindow
1199 if not sourceMapWin:
1200 GError(parent = self,
1201 message =
"%s. %s%s" % (_(
"source mapwin not defined"),
1204 if not targetMapWin:
1205 GError(parent = self,
1206 message=
"%s. %s%s" % (_(
"target mapwin not defined"),
1210 f = open(self.
file[
'points'],
'r')
1213 for line
in f.readlines():
1214 if line[0] ==
'#' or line ==
'':
1216 line = line.replace(
'\n',
'').strip()
1217 coords = map(float, line.split())
1225 self.
SetGCPData(
'source', (coords[0], coords[1]), sourceMapWin)
1226 self.
SetGCPData(
'target', (coords[2], coords[3]), targetMapWin)
1227 index = self.list.GetSelected()
1228 if index != wx.NOT_FOUND:
1229 self.list.CheckItem(index, check)
1232 except IOError, err:
1233 GError(parent = self,
1234 message =
"%s <%s>. %s%s" % (_(
"Reading POINTS file failed"),
1235 self.
file[
'points'], os.linesep, err))
1250 """!Reload data from file"""
1253 shutil.copy(self.
file[
'points_bak'], self.
file[
'points'])
1257 self.mapcoordlist.append([ 0,
1265 self.list.LoadData()
1269 self.list.ClearColumnImage(self._col)
1273 sourceMapWin = self.SrcMapWindow
1274 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1276 targetMapWin = self.TgtMapWindow
1277 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1287 self.RMSError(self.xygroup,self.gr_order)
1289 sourceMapWin = self.SrcMapWindow
1290 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1291 if self.show_target:
1292 targetMapWin = self.TgtMapWindow
1293 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1297 Checks to make sure that the minimum number of GCPs have been defined and
1298 are active for the selected transformation order
1304 GWarning(parent = self,
1305 message=_(
'Insufficient points defined and active (checked) '
1306 'for selected rectification method.\n'
1307 '3+ points needed for 1st order,\n'
1308 '6+ points for 2nd order, and\n'
1309 '10+ points for 3rd order.'))
1316 Georectifies map(s) in group using i.rectify or v.transform
1324 if maptype ==
'cell':
1325 self.grwiz.SwitchEnv(
'source')
1332 busy = wx.BusyInfo(message=_(
"Rectifying images, please wait..."),
1350 print >> sys.stderr, msg
1352 elif maptype ==
'vector':
1367 self.grwiz.SwitchEnv(
'source')
1370 f = open(self.
file[
'vgrp'])
1373 for vect
in f.readlines():
1374 vect = vect.strip(
'\n')
1377 vectlist.append(vect)
1382 for vect
in vectlist:
1384 self.parent.goutput.WriteLog(text = _(
'Transforming <%s>...') % vect,
1392 pointsfile = self.
file[
'points'],
1393 getErrorMsg =
True, read =
True)
1396 self.VectGRList.append(self.
outname)
1399 self.parent.goutput.WriteLog(text = out, switchPage =
True)
1401 self.parent.goutput.WriteError(_(
'Georectification of vector map <%s> failed') %
1403 self.parent.goutput.WriteError(err)
1442 if os.path.isdir(vpath):
1443 self.parent.goutput.WriteWarning(_(
'Vector map <%s> already exists. '
1444 'Change extension name and '
1445 'georectify again.') % self.
outname)
1449 shutil.copytree(xyvpath, vpath)
1453 GMessage(_(
'For all vector maps georectified successfully,') +
'\n' +
1454 _(
'you will need to copy any attribute tables') +
'\n' +
1455 _(
'and reconnect them to the georectified vectors'),
1458 self.grwiz.SwitchEnv(
'target')
1461 """!Print final message"""
1463 if maptype ==
'cell':
1466 returncode = kargs[
'returncode']
1469 self.VectGRList.append(self.
outname)
1470 print '*****vector list = ' + str(self.
VectGRList)
1472 self.parent.goutput.WriteError(_(
'Georectification of vector map <%s> failed') %
1477 """!GCP Manager settings"""
1478 dlg =
GrSettingsDialog(parent=self, id=wx.ID_ANY, title=_(
'GCP Manager settings'))
1480 if dlg.ShowModal() == wx.ID_OK:
1485 def UpdateColours(self, srcrender=False, srcrenderVector=False,
1486 tgtrender=
False, tgtrenderVector=
False):
1487 """!update colours"""
1488 highest_fwd_err = 0.0
1492 for index
in range(self.list.GetItemCount()):
1493 if self.list.IsChecked(index):
1494 key = self.list.GetItemData(index)
1498 self.list.SetItemTextColour(index, wx.BLACK)
1499 if highest_fwd_err < fwd_err:
1500 highest_fwd_err = fwd_err
1505 self.list.SetItemTextColour(index, wx.RED)
1507 self.list.SetItemTextColour(index, wx.BLACK)
1509 self.list.SetItemTextColour(index, wx.BLACK)
1512 self.list.SetItemTextColour(highest_idx, wx.RED)
1514 sourceMapWin = self.SrcMapWindow
1515 sourceMapWin.UpdateMap(render=srcrender, renderVector=srcrenderVector)
1517 targetMapWin = self.TgtMapWindow
1518 targetMapWin.UpdateMap(render=tgtrender, renderVector=tgtrenderVector)
1521 """!Quit georectifier"""
1522 ret = wx.MessageBox(parent=self,
1523 caption=_(
"Quit GCP Manager"),
1524 message=_(
'Save ground control points?'),
1525 style=wx.ICON_QUESTION | wx.YES_NO | wx.CANCEL | wx.CENTRE)
1527 if ret != wx.CANCEL:
1532 if os.path.exists(self.
file[
'points_bak']):
1533 shutil.copy(self.
file[
'points_bak'], self.
file[
'points'])
1535 if os.path.exists(self.
file[
'points_bak']):
1536 os.unlink(self.
file[
'points_bak'])
1541 self.grwiz.Cleanup()
1549 sets transformation order for georectifying
1554 numOfItems = self.list.GetItemCount()
1555 minNumOfItems = numOfItems
1563 diff = 6 - numOfItems
1570 for i
in range(minNumOfItems - numOfItems):
1573 return minNumOfItems
1577 Uses g.transform to calculate forward and backward error for each used GCP
1578 in POINTS file and insert error values into GCP list.
1579 Calculates total forward and backward RMS error for all used points
1589 self.grwiz.SwitchEnv(
'source')
1597 self.grwiz.SwitchEnv(
'target')
1600 errlist = ret.splitlines()
1602 GError(parent = self,
1603 message=_(
'Could not calculate RMS Error.\n'
1604 'Possible error with g.transform.'))
1608 sdfactor = float(UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'sdfactor'))
1613 highest_fwd_err = 0.0
1617 for index
in range(self.list.GetItemCount()):
1618 key = self.list.GetItemData(index)
1619 if self.list.IsChecked(index):
1620 fwd_err, bkw_err = errlist[GCPcount].
split()
1621 self.list.SetStringItem(index, 5, fwd_err)
1622 self.list.SetStringItem(index, 6, bkw_err)
1625 self.list.SetItemTextColour(index, wx.BLACK)
1627 if highest_fwd_err < float(fwd_err):
1628 highest_fwd_err = float(fwd_err)
1632 sumsq_fwd_err += float(fwd_err)**2
1633 sumsq_bkw_err += float(bkw_err)**2
1634 sum_fwd_err += float(fwd_err)
1637 self.list.SetStringItem(index, 5,
'')
1638 self.list.SetStringItem(index, 6,
'')
1641 self.list.SetItemTextColour(index, wx.BLACK)
1645 sum_fwd_err /= GCPcount
1646 self.
rmsmean = sum_fwd_err /GCPcount
1647 self.
rmssd = (((sumsq_fwd_err/GCPcount) - self.
rmsmean**2)**0.5)
1655 self.list.SetItemTextColour(highest_idx, wx.RED)
1657 for index
in range(self.list.GetItemCount()):
1658 if self.list.IsChecked(index):
1659 key = self.list.GetItemData(index)
1661 self.list.SetItemTextColour(index, wx.RED)
1666 self.list.ResizeColumns()
1671 newreg = {
'n' : 0.0,
's' : 0.0,
'e' : 0.0,
'w' : 0.0,}
1674 f = open(coord_file, mode=
'w')
1676 f.write(str(region[
'e']) +
" " + str(region[
'n']) +
"\n")
1678 f.write(str(region[
'e']) +
" " + str(region[
's']) +
"\n")
1680 f.write(str(region[
'w']) +
" " + str(region[
'n']) +
"\n")
1682 f.write(str(region[
'w']) +
" " + str(region[
's']) +
"\n")
1699 self.grwiz.SwitchEnv(
'source')
1708 coords = coord_file)
1710 elif map ==
'target':
1718 coords = coord_file)
1720 os.unlink(coord_file)
1722 self.grwiz.SwitchEnv(
'target')
1725 errlist = ret.splitlines()
1727 GError(parent = self,
1728 message=_(
'Could not calculate new extends.\n'
1729 'Possible error with g.transform.'))
1733 e, n = errlist[0].
split()
1741 for i
in range(1, 4):
1742 e, n = errlist[i].
split()
1745 if fe < newreg[
'w']:
1747 if fe > newreg[
'e']:
1749 if fn < newreg[
's']:
1751 if fn > newreg[
'n']:
1757 """!Show GCP Manager manual page"""
1758 cmdlist = [
'g.manual',
'entry=wxGUI.GCP_Manager']
1759 self.parent.goutput.RunCmd(cmdlist, compReg=
False,
1764 if self.activemap.GetSelection() == 0:
1766 self.
Map = self.SrcMap
1769 self.
Map = self.TgtMap
1774 self.MapWindow.SetFocus()
1779 self.GetMapToolbar().Enable(
'zoomback', enable = (len(self.MapWindow.zoomhistory) > 1))
1781 if self.activemap.GetSelection() != (win == self.TgtMapWindow):
1782 self.activemap.SetSelection(win == self.TgtMapWindow)
1783 self.StatusbarUpdate()
1786 """!Adjust map window to new extents
1790 self.Map.region[
'n'] = newreg[
'n']
1791 self.Map.region[
's'] = newreg[
's']
1792 self.Map.region[
'e'] = newreg[
'e']
1793 self.Map.region[
'w'] = newreg[
'w']
1795 self.MapWindow.ZoomHistory(self.Map.region[
'n'], self.Map.region[
's'],
1796 self.Map.region[
'e'], self.Map.region[
'w'])
1799 if self.Map.projinfo[
'proj'] ==
'll':
1800 if newreg[
'n'] > 90.0:
1802 if newreg[
's'] < -90.0:
1805 ce = newreg[
'w'] + (newreg[
'e'] - newreg[
'w']) / 2
1806 cn = newreg[
's'] + (newreg[
'n'] - newreg[
's']) / 2
1809 self.Map.region[
'center_easting'] = ce
1810 self.Map.region[
'center_northing'] = cn
1811 self.Map.region[
"ewres"] = (newreg[
'e'] - newreg[
'w']) / self.Map.width
1812 self.Map.region[
"nsres"] = (newreg[
'n'] - newreg[
's']) / self.Map.height
1813 self.Map.AlignExtentFromDisplay()
1815 self.MapWindow.ZoomHistory(self.Map.region[
'n'], self.Map.region[
's'],
1816 self.Map.region[
'e'], self.Map.region[
'w'])
1818 if self.MapWindow.redrawAll
is False:
1819 self.MapWindow.redrawAll =
True
1821 self.MapWindow.UpdateMap()
1822 self.StatusbarUpdate()
1825 """!Set target map window to match extents of source map window
1828 if not self.
MapWindow == self.TgtMapWindow:
1830 self.
Map = self.TgtMap
1834 newreg = self.
GetNewExtent(self.SrcMap.region,
'source')
1839 """!Set source map window to match extents of target map window
1842 if not self.
MapWindow == self.SrcMapWindow:
1844 self.
Map = self.SrcMap
1848 newreg = self.
GetNewExtent(self.TgtMap.region,
'target')
1855 point = wx.GetMousePosition()
1856 zoommenu = wx.Menu()
1859 zoomsource = wx.MenuItem(zoommenu, wx.ID_ANY, _(
'Adjust source display to target display'))
1860 zoommenu.AppendItem(zoomsource)
1863 zoomtarget = wx.MenuItem(zoommenu, wx.ID_ANY, _(
'Adjust target display to source display'))
1864 zoommenu.AppendItem(zoomtarget)
1869 self.PopupMenu(zoommenu)
1873 """!GCP Map Display resized, adjust Map Windows
1875 if self.GetMapToolbar():
1876 srcwidth, srcheight = self.SrcMapWindow.GetSize()
1877 tgtwidth, tgtheight = self.TgtMapWindow.GetSize()
1878 srcwidth = (srcwidth + tgtwidth) / 2
1879 self._mgr.GetPane(
"target").Hide()
1881 self._mgr.GetPane(
"source").BestSize((srcwidth, srcheight))
1882 self._mgr.GetPane(
"target").BestSize((srcwidth, tgtheight))
1884 self._mgr.GetPane(
"target").Show()
1890 ListCtrlAutoWidthMixin):
1892 def __init__(self, parent, gcp, id=wx.ID_ANY,
1893 pos=wx.DefaultPosition, size=wx.DefaultSize,
1894 style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_HRULES |
1897 wx.ListCtrl.__init__(self, parent, id, pos, size, style)
1903 CheckListCtrlMixin.__init__(self)
1904 ListCtrlAutoWidthMixin.__init__(self)
1914 self.Bind(wx.EVT_LIST_COL_CLICK, self.
OnColClick)
1924 for col
in (_(
'use'),
1930 _(
'Backward error')):
1931 self.InsertColumn(idx_col, col)
1935 info = wx.ListItem()
1936 info.SetMask(wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT)
1938 info.m_format = wx.LIST_FORMAT_LEFT
1941 for lbl
in (_(
'use'),
1947 _(
'Backward error')):
1949 self.InsertColumnInfo(idx_col, info)
1953 """!Load data into list"""
1954 self.DeleteAllItems()
1957 if os.path.isfile(self.gcp.file[
'points']):
1962 self.gcp.AddGCP(
None)
1968 wx.LIST_STATE_SELECTED,
1969 wx.LIST_STATE_SELECTED)
1977 """!Item is checked/unchecked"""
1981 sourceMapWin = self.gcp.SrcMapWindow
1982 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1983 if self.gcp.show_target:
1984 targetMapWin = self.gcp.TgtMapWindow
1985 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1991 Appends an item to GCP list
2003 self.
selected = self.GetItemCount() - 1
2007 wx.LIST_STATE_SELECTED,
2008 wx.LIST_STATE_SELECTED)
2018 Deletes selected item in GCP list
2023 key = self.GetItemData(self.
selected)
2029 """!Resize columns"""
2030 minWidth = [90, 120]
2031 for i
in range(self.GetColumnCount()):
2032 self.SetColumnWidth(i, wx.LIST_AUTOSIZE)
2034 if i > 0
and self.GetColumnWidth(i) < minWidth[i > 4]:
2035 self.SetColumnWidth(i, minWidth[i > 4])
2037 self.SendSizeEvent()
2040 """!Get index of selected item"""
2051 sourceMapWin = self.gcp.SrcMapWindow
2052 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
2053 if self.gcp.show_target:
2054 targetMapWin = self.gcp.TgtMapWindow
2055 targetMapWin.UpdateMap(render=
False, renderVector=
False)
2061 When item double clicked, open editor to update coordinate values
2064 index = event.GetIndex()
2065 key = self.GetItemData(index)
2068 for i
in range(1, 5):
2069 coords.append(self.GetItem(index, i).GetText())
2071 dlg =
EditGCP(parent=self, id=wx.ID_ANY, data=coords, gcpno=key)
2073 if dlg.ShowModal() == wx.ID_OK:
2074 values = dlg.GetValues()
2076 if len(values) == 0:
2077 GError(parent = self,
2078 message=_(
"Invalid coordinate value. Operation canceled."))
2080 for i
in range(len(values)):
2081 if values[i] != coords[i]:
2082 self.SetStringItem(index, i + 1, values[i])
2087 self.SetStringItem(index, 5,
'')
2088 self.SetStringItem(index, 6,
'')
2089 key = self.GetItemData(index)
2090 self.gcp.mapcoordlist[key] = [key,
2097 self.gcp.UpdateColours()
2100 """!ListCtrl forgets selected item..."""
2103 wx.LIST_STATE_SELECTED,
2104 wx.LIST_STATE_SELECTED)
2109 Dialog to create a vector group (VREF file) for georectifying
2111 @todo Replace by g.group
2113 def __init__(self, parent, id, grassdb, location, mapset, group,
2114 style=wx.DEFAULT_DIALOG_STYLE):
2116 wx.Dialog.__init__(self, parent, id, style=style,
2117 title = _(
"Create vector map group"))
2131 for dir
in vectlist:
2138 vectlist.remove(dir)
2157 self.btnOK.SetDefault()
2163 self.
listMap = wx.CheckListBox(parent = self, id = wx.ID_ANY,
2170 for line
in f.readlines():
2171 line = line.replace(
'\n',
'')
2174 checked.append(line)
2175 self.listMap.SetCheckedStrings(checked)
2179 line = wx.StaticLine(parent = self,
2180 id = wx.ID_ANY, size = (20, -1),
2181 style = wx.LI_HORIZONTAL)
2186 sizer = wx.BoxSizer(wx.VERTICAL)
2188 box = wx.BoxSizer(wx.HORIZONTAL)
2189 box.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
2190 label = _(
'Select vector map(s) to add to group:')),
2191 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
2195 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
2199 sizer.Add(box, flag = wx.ALIGN_RIGHT | wx.ALL,
2202 sizer.Add(item = line, proportion = 0,
2203 flag = wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT,
2207 btnSizer = wx.StdDialogButtonSizer()
2209 btnSizer.AddButton(self.
btnOK)
2212 sizer.Add(item = btnSizer, proportion = 0,
2213 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER,
2216 self.SetSizer(sizer)
2221 """!Create VREF file"""
2223 for item
in range(self.listMap.GetCount()):
2224 if not self.listMap.IsChecked(item):
2226 vgrouplist.append(self.listMap.GetString(item))
2230 for vect
in vgrouplist:
2231 f.write(vect +
'\n')
2236 def __init__(self, parent, data, gcpno, id=wx.ID_ANY,
2237 title=_(
"Edit GCP"),
2238 style=wx.DEFAULT_DIALOG_STYLE):
2239 """!Dialog for editing GPC and map coordinates in list control"""
2241 wx.Dialog.__init__(self, parent, id, title=title, style=style)
2243 panel = wx.Panel(parent=self)
2245 sizer = wx.BoxSizer(wx.VERTICAL)
2247 box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
2248 label=
" %s %s " % (_(
"Ground Control Point No."), str(gcpno)))
2249 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2252 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
2254 self.
xcoord = wx.TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))
2255 self.
ycoord = wx.TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))
2256 self.
ecoord = wx.TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))
2257 self.
ncoord = wx.TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))
2267 for label, win
in ((_(
"source E:"), self.
xcoord),
2268 (_(
"target E:"), self.
ecoord),
2269 (_(
"source N:"), self.
ycoord),
2270 (_(
"target N:"), self.
ncoord)):
2271 label = wx.StaticText(parent=panel, id=wx.ID_ANY,
2273 gridSizer.Add(item=label,
2274 flag=wx.ALIGN_CENTER_VERTICAL,
2278 win.SetValue(str(data[idx]))
2280 gridSizer.Add(item=win,
2290 boxSizer.Add(item=gridSizer, proportion=1,
2291 flag=wx.EXPAND | wx.ALL, border=5)
2293 sizer.Add(item=boxSizer, proportion=1,
2294 flag=wx.EXPAND | wx.ALL, border=5)
2301 self.btnOk.SetDefault()
2303 btnSizer = wx.StdDialogButtonSizer()
2305 btnSizer.AddButton(self.
btnOk)
2308 sizer.Add(item=btnSizer, proportion=0,
2309 flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
2311 panel.SetSizer(sizer)
2315 """!Return list of values (as strings).
2319 float(self.xcoord.GetValue())
2320 float(self.ycoord.GetValue())
2321 float(self.ecoord.GetValue())
2322 float(self.ncoord.GetValue())
2326 valuelist.append(self.xcoord.GetValue())
2327 valuelist.append(self.ycoord.GetValue())
2328 valuelist.append(self.ecoord.GetValue())
2329 valuelist.append(self.ncoord.GetValue())
2334 def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
2335 style=wx.DEFAULT_DIALOG_STYLE):
2336 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
2338 Dialog to set profile text options: font, title
2339 and font size, axis labels and font size
2358 notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
2363 btnSave = wx.Button(self, wx.ID_SAVE)
2364 btnApply = wx.Button(self, wx.ID_APPLY)
2365 btnClose = wx.Button(self, wx.ID_CLOSE)
2366 btnApply.SetDefault()
2369 btnApply.Bind(wx.EVT_BUTTON, self.
OnApply)
2370 btnApply.SetToolTipString(_(
"Apply changes for the current session"))
2371 btnSave.Bind(wx.EVT_BUTTON, self.
OnSave)
2372 btnSave.SetToolTipString(_(
"Apply and save changes to user settings file (default for next sessions)"))
2373 btnClose.Bind(wx.EVT_BUTTON, self.
OnClose)
2374 btnClose.SetToolTipString(_(
"Close dialog"))
2377 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
2378 btnSizer.Add(btnApply, flag=wx.LEFT | wx.RIGHT, border=5)
2379 btnSizer.Add(btnSave, flag=wx.LEFT | wx.RIGHT, border=5)
2380 btnSizer.Add(btnClose, flag=wx.LEFT | wx.RIGHT, border=5)
2383 mainSizer = wx.BoxSizer(wx.VERTICAL)
2384 mainSizer.Add(item=notebook, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
2385 mainSizer.Add(item=btnSizer, proportion=0,
2386 flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
2389 self.SetSizer(mainSizer)
2392 def __CreateSymbologyPage(self, notebook):
2393 """!Create notebook page with symbology settings"""
2395 panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
2396 notebook.AddPage(page=panel, text=_(
"Symbology"))
2398 sizer = wx.BoxSizer(wx.VERTICAL)
2400 rmsgridSizer = wx.GridBagSizer(vgap=5, hgap=5)
2401 rmsgridSizer.AddGrowableCol(1)
2405 label=_(
"Highlight highest RMS error only"))
2406 hh = UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'highestonly')
2407 self.highlighthighest.SetValue(hh)
2408 rmsgridSizer.Add(item=self.
highlighthighest, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
2411 rmslabel = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Highlight RMS error > M + SD * factor:"))
2412 rmslabel.SetToolTip(wx.ToolTip(_(
"Highlight GCPs with an RMS error larger than \n"
2413 "mean + standard deviation * given factor. \n"
2414 "Recommended values for this factor are between 1 and 2.")))
2415 rmsgridSizer.Add(item=rmslabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
2416 sdfactor = UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'sdfactor')
2417 self.
rmsWin = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
2418 size=(70,-1), style=wx.TE_NOHIDESEL)
2419 self.rmsWin.SetValue(
"%s" % str(sdfactor))
2420 if (self.parent.highest_only ==
True):
2421 self.rmsWin.Disable()
2423 self.
symbol[
'sdfactor'] = self.rmsWin.GetId()
2424 rmsgridSizer.Add(item=self.
rmsWin, flag=wx.ALIGN_RIGHT, pos=(1, 1))
2425 sizer.Add(item=rmsgridSizer, flag=wx.EXPAND | wx.ALL, border=5)
2427 box = wx.StaticBox(parent=panel, id=wx.ID_ANY,
2428 label=
" %s " % _(
"Symbol settings"))
2429 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2430 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
2431 gridSizer.AddGrowableCol(1)
2437 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color:"))
2438 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2439 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'color')
2440 colWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2441 colour=wx.Colour(col[0],
2445 self.
symbol[
'color'] = colWin.GetId()
2446 gridSizer.Add(item=colWin,
2447 flag=wx.ALIGN_RIGHT,
2454 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for high RMS error:"))
2455 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2456 hcol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'hcolor')
2457 hcolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2458 colour=wx.Colour(hcol[0],
2462 self.
symbol[
'hcolor'] = hcolWin.GetId()
2463 gridSizer.Add(item=hcolWin,
2464 flag=wx.ALIGN_RIGHT,
2471 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for selected GCP:"))
2472 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2473 scol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'scolor')
2474 scolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2475 colour=wx.Colour(scol[0],
2479 self.
symbol[
'scolor'] = scolWin.GetId()
2480 gridSizer.Add(item=scolWin,
2481 flag=wx.ALIGN_RIGHT,
2488 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for unused GCPs:"))
2489 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2490 ucol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'ucolor')
2491 ucolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2492 colour=wx.Colour(ucol[0],
2496 self.
symbol[
'ucolor'] = ucolWin.GetId()
2497 gridSizer.Add(item=ucolWin,
2498 flag=wx.ALIGN_RIGHT,
2504 label=_(
"Show unused GCPs"))
2505 shuu = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'unused')
2506 self.showunused.SetValue(shuu)
2507 gridSizer.Add(item=self.
showunused, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2513 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Symbol size:"))
2514 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2515 symsize = int(UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'size'))
2516 sizeWin = wx.SpinCtrl(parent=panel, id=wx.ID_ANY,
2518 sizeWin.SetValue(symsize)
2519 self.
symbol[
'size'] = sizeWin.GetId()
2520 gridSizer.Add(item=sizeWin,
2521 flag=wx.ALIGN_RIGHT,
2528 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Line width:"))
2529 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2530 width = int(UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'width'))
2531 widWin = wx.SpinCtrl(parent=panel, id=wx.ID_ANY,
2533 widWin.SetValue(width)
2534 self.
symbol[
'width'] = widWin.GetId()
2535 gridSizer.Add(item=widWin,
2536 flag=wx.ALIGN_RIGHT,
2539 boxSizer.Add(item=gridSizer, flag=wx.EXPAND)
2540 sizer.Add(item=boxSizer, flag=wx.EXPAND | wx.ALL, border=5)
2547 size=globalvar.DIALOG_GSELECT_SIZE, type=
'cell', updateOnPopup =
False)
2548 self.parent.grwiz.SwitchEnv(
'source')
2549 self.srcselection.SetElementList(maptype)
2551 self.srcselection.tcp.GetElementList(elements = self.parent.src_maps)
2555 size=globalvar.DIALOG_GSELECT_SIZE, type=
'cell', updateOnPopup =
False)
2556 self.parent.grwiz.SwitchEnv(
'target')
2557 self.tgtselection.SetElementList(maptype)
2558 self.tgtselection.GetElementList()
2560 sizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Select source map to display:')),
2561 proportion=0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2563 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2564 self.srcselection.SetValue(src_map)
2565 sizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Select target map to display:')),
2566 proportion=0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2568 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2569 self.tgtselection.SetValue(tgt_map)
2572 self.highlighthighest.Bind(wx.EVT_CHECKBOX, self.
OnHighlight)
2573 self.rmsWin.Bind(wx.EVT_TEXT, self.
OnSDFactor)
2577 panel.SetSizer(sizer)
2581 def __CreateRectificationPage(self, notebook):
2582 """!Create notebook page with symbology settings"""
2584 panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
2585 notebook.AddPage(page=panel, text=_(
"Rectification"))
2587 sizer = wx.BoxSizer(wx.VERTICAL)
2591 label=
" %s " % _(
"Select rectification order"),
2592 choices=[_(
'1st order'), _(
'2nd order'), _(
'3rd order')],
2593 majorDimension=wx.RA_SPECIFY_COLS)
2594 sizer.Add(item=self.
rb_grorder, proportion=0,
2595 flag=wx.EXPAND | wx.ALL, border=5)
2596 self.rb_grorder.SetSelection(self.parent.gr_order - 1)
2599 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
2600 gridSizer.AddGrowableCol(1)
2601 gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Select interpolation method:')),
2602 pos=(0,0), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2605 gridSizer.Add(item=self.
grmethod, pos=(0,1),
2606 flag=wx.ALIGN_RIGHT, border=5)
2607 self.grmethod.SetStringSelection(self.parent.gr_method)
2608 sizer.Add(item=gridSizer, flag=wx.EXPAND | wx.ALL, border=5)
2611 self.
check = wx.CheckBox(parent=panel, id=wx.ID_ANY,
2612 label=_(
"clip to computational region in target location"))
2613 sizer.Add(item=self.
check, proportion=0,
2614 flag=wx.EXPAND | wx.ALL, border=5)
2615 self.check.SetValue(self.parent.clip_to_region)
2618 sizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Extension for output maps:')),
2619 proportion=0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2620 self.
ext_txt = wx.TextCtrl(parent=panel, id=wx.ID_ANY, value=
"", size=(350,-1))
2621 self.ext_txt.SetValue(self.parent.extension)
2623 proportion=0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2627 self.Bind(wx.EVT_RADIOBOX, self.parent.OnGROrder, self.
rb_grorder)
2631 panel.SetSizer(sizer)
2636 """!Checkbox 'highlighthighest' checked/unchecked"""
2637 if self.highlighthighest.IsChecked():
2638 self.parent.highest_only =
True
2639 self.rmsWin.Disable()
2641 self.parent.highest_only =
False
2642 self.rmsWin.Enable()
2645 """!New factor for RMS threshold = M + SD * factor"""
2647 self.
sdfactor = float(event.GetString())
2650 GError(parent = self,
2651 message=_(
'RMS threshold factor must be > 0'))
2653 GError(parent = self,
2654 message=_(
'RMS threshold factor is < 1\n'
2655 'Too many points might be highlighted'))
2658 """!Source map to display selected"""
2661 tmp_map = event.GetString()
2663 if not tmp_map ==
'' and not tmp_map == src_map:
2667 """!Target map to display selected"""
2670 tmp_map = event.GetString()
2672 if not tmp_map == tgt_map:
2676 self.parent.gr_method = self.
methods[event.GetSelection()]
2679 self.parent.clip_to_region = event.IsChecked()
2682 self.parent.extension = event.GetString()
2690 UserSettings.Set(group=
'gcpman', key=
'rms', subkey=
'highestonly',
2691 value=self.highlighthighest.GetValue())
2693 UserSettings.Set(group=
'gcpman', key=
'rms', subkey=
'sdfactor',
2696 self.parent.sdfactor = self.
sdfactor
2697 if self.parent.rmsthresh > 0:
2698 self.parent.rmsthresh = self.parent.mean + self.parent.sdfactor * self.parent.rmssd
2700 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'color',
2701 value=tuple(wx.FindWindowById(self.
symbol[
'color']).GetColour()))
2702 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'hcolor',
2703 value=tuple(wx.FindWindowById(self.
symbol[
'hcolor']).GetColour()))
2704 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'scolor',
2705 value=tuple(wx.FindWindowById(self.
symbol[
'scolor']).GetColour()))
2706 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'ucolor',
2707 value=tuple(wx.FindWindowById(self.
symbol[
'ucolor']).GetColour()))
2708 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'unused',
2709 value=self.showunused.GetValue())
2710 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'size',
2712 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'width',
2716 srcrenderVector =
False
2718 tgtrenderVector =
False
2721 layers = self.parent.grwiz.SrcMap.GetListOfLayers()
2722 self.parent.grwiz.SrcMap.DeleteLayer(layers[0])
2725 cmdlist = [
'd.rast',
'map=%s' % src_map]
2726 self.parent.grwiz.SwitchEnv(
'source')
2728 self.parent.grwiz.SrcMap.AddLayer(type=
'raster', command=cmdlist, l_active=
True,
2729 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
2731 self.parent.grwiz.SwitchEnv(
'target')
2736 layers = self.parent.grwiz.TgtMap.GetListOfLayers()
2738 self.parent.grwiz.TgtMap.DeleteLayer(layers[0])
2742 cmdlist = [
'd.rast',
'map=%s' % tgt_map]
2744 self.parent.grwiz.TgtMap.AddLayer(type=
'raster', command=cmdlist, l_active=
True,
2745 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
2748 if self.parent.show_target ==
False:
2749 self.parent.show_target =
True
2750 self.parent._mgr.GetPane(
"target").Show()
2751 self.parent._mgr.Update()
2752 self.parent.GetMapToolbar().Enable(
'zoommenu', enable =
True)
2753 self.parent.activemap.Enable()
2754 self.parent.TgtMapWindow.ZoomToMap(layers = self.parent.TgtMap.GetListOfLayers())
2756 if self.parent.show_target ==
True:
2757 self.parent.show_target =
False
2758 self.parent._mgr.GetPane(
"target").Hide()
2759 self.parent._mgr.Update()
2760 self.parent.activemap.SetSelection(0)
2761 self.parent.activemap.Enable(
False)
2762 self.parent.GetMapToolbar().Enable(
'zoommenu', enable =
False)
2764 self.parent.UpdateColours(srcrender, srcrenderVector, tgtrender, tgtrenderVector)
2767 """!Button 'Save' pressed"""
2770 UserSettings.ReadSettingsFile(settings=fileSettings)
2771 fileSettings[
'gcpman'] = UserSettings.Get(group=
'gcpman')
2772 file = UserSettings.SaveToFile(fileSettings)
2773 self.parent.parent.goutput.WriteLog(_(
'GCP Manager settings saved to file \'%s\'.') % file)
2777 """!Button 'Apply' pressed"""
2782 """!Button 'Cancel' pressed"""