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"))
312 label=
' %s ' % _(
"Map type to georectify"),
313 choices=[_(
'raster'), _(
'vector')],
314 majorDimension=wx.RA_SPECIFY_COLS)
316 flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
317 pos=(1, 1), span=(1, 2))
320 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select source location:')),
321 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
325 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
329 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select source mapset:')),
330 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
335 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
338 self.sizer.AddGrowableCol(2)
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"))
433 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select group:')),
434 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
436 self.
cb_group = wx.ComboBox(parent=self, id=wx.ID_ANY,
438 style=wx.CB_DROPDOWN | wx.CB_READONLY)
440 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
444 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Create group if none exists')),
445 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
447 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
448 self.
btn_mkgroup = wx.Button(parent=self, id=wx.ID_ANY, label=_(
"Create/edit group..."))
449 self.
btn_vgroup = wx.Button(parent=self, id=wx.ID_ANY, label=_(
"Add vector map to group..."))
451 flag=wx.RIGHT, border=5)
454 flag=wx.LEFT, border=5)
456 self.sizer.Add(item=btnSizer,
457 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
461 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Extension for output maps:')),
462 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
464 self.
ext_txt = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(350,-1))
466 self.sizer.Add(item=self.
ext_txt,
467 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
469 self.sizer.AddGrowableCol(2)
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 = self.srcselection.GetValue()
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 = self.tgtselection.GetValue()
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
1198 if not sourceMapWin:
1199 GError(parent = self,
1200 message =
"%s. %s%s" % (_(
"source mapwin not defined"),
1203 if not targetMapWin:
1204 GError(parent = self,
1205 message=
"%s. %s%s" % (_(
"target mapwin not defined"),
1209 f = open(self.
file[
'points'],
'r')
1212 for line
in f.readlines():
1213 if line[0] ==
'#' or line ==
'':
1215 line = line.replace(
'\n',
'').strip()
1216 coords = map(float, line.split())
1224 self.
SetGCPData(
'source', (coords[0], coords[1]), sourceMapWin)
1225 self.
SetGCPData(
'target', (coords[2], coords[3]), targetMapWin)
1226 index = self.list.GetSelected()
1227 if index != wx.NOT_FOUND:
1228 self.list.CheckItem(index, check)
1231 except IOError, err:
1232 GError(parent = self,
1233 message =
"%s <%s>. %s%s" % (_(
"Reading POINTS file failed"),
1234 self.
file[
'points'], os.linesep, err))
1249 """!Reload data from file"""
1252 shutil.copy(self.
file[
'points_bak'], self.
file[
'points'])
1256 self.mapcoordlist.append([ 0,
1264 self.list.LoadData()
1268 self.list.ClearColumnImage(self._col)
1272 sourceMapWin = self.SrcMapWindow
1273 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1275 targetMapWin = self.TgtMapWindow
1276 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1286 self.RMSError(self.xygroup,self.gr_order)
1288 sourceMapWin = self.SrcMapWindow
1289 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1290 if self.show_target:
1291 targetMapWin = self.TgtMapWindow
1292 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1296 Checks to make sure that the minimum number of GCPs have been defined and
1297 are active for the selected transformation order
1303 GWarning(parent = self,
1304 message=_(
'Insufficient points defined and active (checked) '
1305 'for selected rectification method.\n'
1306 '3+ points needed for 1st order,\n'
1307 '6+ points for 2nd order, and\n'
1308 '10+ points for 3rd order.'))
1315 Georectifies map(s) in group using i.rectify or v.transform
1323 if maptype ==
'cell':
1324 self.grwiz.SwitchEnv(
'source')
1331 busy = wx.BusyInfo(message=_(
"Rectifying images, please wait..."),
1349 print >> sys.stderr, msg
1351 elif maptype ==
'vector':
1366 self.grwiz.SwitchEnv(
'source')
1369 f = open(self.
file[
'vgrp'])
1372 for vect
in f.readlines():
1373 vect = vect.strip(
'\n')
1376 vectlist.append(vect)
1381 for vect
in vectlist:
1383 self.parent.goutput.WriteLog(text = _(
'Transforming <%s>...') % vect,
1391 pointsfile = self.
file[
'points'],
1392 getErrorMsg =
True, read =
True)
1395 self.VectGRList.append(self.
outname)
1398 self.parent.goutput.WriteLog(text = out, switchPage =
True)
1400 self.parent.goutput.WriteError(_(
'Georectification of vector map <%s> failed') %
1402 self.parent.goutput.WriteError(err)
1441 if os.path.isdir(vpath):
1442 self.parent.goutput.WriteWarning(_(
'Vector map <%s> already exists. '
1443 'Change extension name and '
1444 'georectify again.') % self.
outname)
1448 shutil.copytree(xyvpath, vpath)
1452 GMessage(_(
'For all vector maps georectified successfully,') +
'\n' +
1453 _(
'you will need to copy any attribute tables') +
'\n' +
1454 _(
'and reconnect them to the georectified vectors'),
1457 self.grwiz.SwitchEnv(
'target')
1460 """!Print final message"""
1462 if maptype ==
'cell':
1465 returncode = kargs[
'returncode']
1468 self.VectGRList.append(self.
outname)
1469 print '*****vector list = ' + str(self.
VectGRList)
1471 self.parent.goutput.WriteError(_(
'Georectification of vector map <%s> failed') %
1476 """!GCP Manager settings"""
1477 dlg =
GrSettingsDialog(parent=self, id=wx.ID_ANY, title=_(
'GCP Manager settings'))
1479 if dlg.ShowModal() == wx.ID_OK:
1484 def UpdateColours(self, srcrender=False, srcrenderVector=False,
1485 tgtrender=
False, tgtrenderVector=
False):
1486 """!update colours"""
1487 highest_fwd_err = 0.0
1491 for index
in range(self.list.GetItemCount()):
1492 if self.list.IsChecked(index):
1493 key = self.list.GetItemData(index)
1497 self.list.SetItemTextColour(index, wx.BLACK)
1498 if highest_fwd_err < fwd_err:
1499 highest_fwd_err = fwd_err
1504 self.list.SetItemTextColour(index, wx.RED)
1506 self.list.SetItemTextColour(index, wx.BLACK)
1508 self.list.SetItemTextColour(index, wx.BLACK)
1511 self.list.SetItemTextColour(highest_idx, wx.RED)
1513 sourceMapWin = self.SrcMapWindow
1514 sourceMapWin.UpdateMap(render=srcrender, renderVector=srcrenderVector)
1516 targetMapWin = self.TgtMapWindow
1517 targetMapWin.UpdateMap(render=tgtrender, renderVector=tgtrenderVector)
1520 """!Quit georectifier"""
1521 ret = wx.MessageBox(parent=self,
1522 caption=_(
"Quit GCP Manager"),
1523 message=_(
'Save ground control points?'),
1524 style=wx.ICON_QUESTION | wx.YES_NO | wx.CANCEL | wx.CENTRE)
1526 if ret != wx.CANCEL:
1531 if os.path.exists(self.
file[
'points_bak']):
1532 shutil.copy(self.
file[
'points_bak'], self.
file[
'points'])
1534 if os.path.exists(self.
file[
'points_bak']):
1535 os.unlink(self.
file[
'points_bak'])
1540 self.grwiz.Cleanup()
1548 sets transformation order for georectifying
1553 numOfItems = self.list.GetItemCount()
1554 minNumOfItems = numOfItems
1562 diff = 6 - numOfItems
1569 for i
in range(minNumOfItems - numOfItems):
1572 return minNumOfItems
1576 Uses g.transform to calculate forward and backward error for each used GCP
1577 in POINTS file and insert error values into GCP list.
1578 Calculates total forward and backward RMS error for all used points
1588 self.grwiz.SwitchEnv(
'source')
1596 self.grwiz.SwitchEnv(
'target')
1599 errlist = ret.splitlines()
1601 GError(parent = self,
1602 message=_(
'Could not calculate RMS Error.\n'
1603 'Possible error with g.transform.'))
1607 sdfactor = float(UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'sdfactor'))
1612 highest_fwd_err = 0.0
1616 for index
in range(self.list.GetItemCount()):
1617 key = self.list.GetItemData(index)
1618 if self.list.IsChecked(index):
1619 fwd_err, bkw_err = errlist[GCPcount].
split()
1620 self.list.SetStringItem(index, 5, fwd_err)
1621 self.list.SetStringItem(index, 6, bkw_err)
1624 self.list.SetItemTextColour(index, wx.BLACK)
1626 if highest_fwd_err < float(fwd_err):
1627 highest_fwd_err = float(fwd_err)
1631 sumsq_fwd_err += float(fwd_err)**2
1632 sumsq_bkw_err += float(bkw_err)**2
1633 sum_fwd_err += float(fwd_err)
1636 self.list.SetStringItem(index, 5,
'')
1637 self.list.SetStringItem(index, 6,
'')
1640 self.list.SetItemTextColour(index, wx.BLACK)
1644 sum_fwd_err /= GCPcount
1645 self.
rmsmean = sum_fwd_err /GCPcount
1646 self.
rmssd = (((sumsq_fwd_err/GCPcount) - self.
rmsmean**2)**0.5)
1654 self.list.SetItemTextColour(highest_idx, wx.RED)
1656 for index
in range(self.list.GetItemCount()):
1657 if self.list.IsChecked(index):
1658 key = self.list.GetItemData(index)
1660 self.list.SetItemTextColour(index, wx.RED)
1665 self.list.ResizeColumns()
1670 newreg = {
'n' : 0.0,
's' : 0.0,
'e' : 0.0,
'w' : 0.0,}
1673 f = open(coord_file, mode=
'w')
1675 f.write(str(region[
'e']) +
" " + str(region[
'n']) +
"\n")
1677 f.write(str(region[
'e']) +
" " + str(region[
's']) +
"\n")
1679 f.write(str(region[
'w']) +
" " + str(region[
'n']) +
"\n")
1681 f.write(str(region[
'w']) +
" " + str(region[
's']) +
"\n")
1698 self.grwiz.SwitchEnv(
'source')
1707 coords = coord_file)
1709 elif map ==
'target':
1717 coords = coord_file)
1719 os.unlink(coord_file)
1721 self.grwiz.SwitchEnv(
'target')
1724 errlist = ret.splitlines()
1726 GError(parent = self,
1727 message=_(
'Could not calculate new extends.\n'
1728 'Possible error with g.transform.'))
1732 e, n = errlist[0].
split()
1740 for i
in range(1, 4):
1741 e, n = errlist[i].
split()
1744 if fe < newreg[
'w']:
1746 if fe > newreg[
'e']:
1748 if fn < newreg[
's']:
1750 if fn > newreg[
'n']:
1756 """!Show GCP Manager manual page"""
1757 cmdlist = [
'g.manual',
'entry=wxGUI.GCP_Manager']
1758 self.parent.goutput.RunCmd(cmdlist, compReg=
False,
1763 if self.activemap.GetSelection() == 0:
1765 self.
Map = self.SrcMap
1768 self.
Map = self.TgtMap
1773 self.MapWindow.SetFocus()
1778 self.GetMapToolbar().Enable(
'zoomback', enable = (len(self.MapWindow.zoomhistory) > 1))
1780 if self.activemap.GetSelection() != (win == self.TgtMapWindow):
1781 self.activemap.SetSelection(win == self.TgtMapWindow)
1782 self.StatusbarUpdate()
1785 """!Adjust map window to new extents
1789 self.Map.region[
'n'] = newreg[
'n']
1790 self.Map.region[
's'] = newreg[
's']
1791 self.Map.region[
'e'] = newreg[
'e']
1792 self.Map.region[
'w'] = newreg[
'w']
1794 self.MapWindow.ZoomHistory(self.Map.region[
'n'], self.Map.region[
's'],
1795 self.Map.region[
'e'], self.Map.region[
'w'])
1798 if self.Map.projinfo[
'proj'] ==
'll':
1799 if newreg[
'n'] > 90.0:
1801 if newreg[
's'] < -90.0:
1804 ce = newreg[
'w'] + (newreg[
'e'] - newreg[
'w']) / 2
1805 cn = newreg[
's'] + (newreg[
'n'] - newreg[
's']) / 2
1808 self.Map.region[
'center_easting'] = ce
1809 self.Map.region[
'center_northing'] = cn
1810 self.Map.region[
"ewres"] = (newreg[
'e'] - newreg[
'w']) / self.Map.width
1811 self.Map.region[
"nsres"] = (newreg[
'n'] - newreg[
's']) / self.Map.height
1812 self.Map.AlignExtentFromDisplay()
1814 self.MapWindow.ZoomHistory(self.Map.region[
'n'], self.Map.region[
's'],
1815 self.Map.region[
'e'], self.Map.region[
'w'])
1817 if self.MapWindow.redrawAll
is False:
1818 self.MapWindow.redrawAll =
True
1820 self.MapWindow.UpdateMap()
1821 self.StatusbarUpdate()
1824 """!Set target map window to match extents of source map window
1827 if not self.
MapWindow == self.TgtMapWindow:
1829 self.
Map = self.TgtMap
1833 newreg = self.
GetNewExtent(self.SrcMap.region,
'source')
1838 """!Set source map window to match extents of target map window
1841 if not self.
MapWindow == self.SrcMapWindow:
1843 self.
Map = self.SrcMap
1847 newreg = self.
GetNewExtent(self.TgtMap.region,
'target')
1854 point = wx.GetMousePosition()
1855 zoommenu = wx.Menu()
1858 zoomsource = wx.MenuItem(zoommenu, wx.ID_ANY, _(
'Adjust source display to target display'))
1859 zoommenu.AppendItem(zoomsource)
1862 zoomtarget = wx.MenuItem(zoommenu, wx.ID_ANY, _(
'Adjust target display to source display'))
1863 zoommenu.AppendItem(zoomtarget)
1868 self.PopupMenu(zoommenu)
1872 """!GCP Map Display resized, adjust Map Windows
1874 if self.GetMapToolbar():
1875 srcwidth, srcheight = self.SrcMapWindow.GetSize()
1876 tgtwidth, tgtheight = self.TgtMapWindow.GetSize()
1877 srcwidth = (srcwidth + tgtwidth) / 2
1878 self._mgr.GetPane(
"target").Hide()
1880 self._mgr.GetPane(
"source").BestSize((srcwidth, srcheight))
1881 self._mgr.GetPane(
"target").BestSize((srcwidth, tgtheight))
1883 self._mgr.GetPane(
"target").Show()
1889 ListCtrlAutoWidthMixin):
1891 def __init__(self, parent, gcp, id=wx.ID_ANY,
1892 pos=wx.DefaultPosition, size=wx.DefaultSize,
1893 style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_HRULES |
1896 wx.ListCtrl.__init__(self, parent, id, pos, size, style)
1902 CheckListCtrlMixin.__init__(self)
1903 ListCtrlAutoWidthMixin.__init__(self)
1913 self.Bind(wx.EVT_LIST_COL_CLICK, self.
OnColClick)
1923 for col
in (_(
'use'),
1929 _(
'Backward error')):
1930 self.InsertColumn(idx_col, col)
1934 info = wx.ListItem()
1935 info.SetMask(wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT)
1937 info.m_format = wx.LIST_FORMAT_LEFT
1940 for lbl
in (_(
'use'),
1946 _(
'Backward error')):
1948 self.InsertColumnInfo(idx_col, info)
1952 """!Load data into list"""
1953 self.DeleteAllItems()
1956 if os.path.isfile(self.gcp.file[
'points']):
1961 self.gcp.AddGCP(
None)
1967 wx.LIST_STATE_SELECTED,
1968 wx.LIST_STATE_SELECTED)
1976 """!Item is checked/unchecked"""
1980 sourceMapWin = self.gcp.SrcMapWindow
1981 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1982 if self.gcp.show_target:
1983 targetMapWin = self.gcp.TgtMapWindow
1984 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1990 Appends an item to GCP list
2002 self.
selected = self.GetItemCount() - 1
2006 wx.LIST_STATE_SELECTED,
2007 wx.LIST_STATE_SELECTED)
2017 Deletes selected item in GCP list
2022 key = self.GetItemData(self.
selected)
2028 """!Resize columns"""
2029 minWidth = [90, 120]
2030 for i
in range(self.GetColumnCount()):
2031 self.SetColumnWidth(i, wx.LIST_AUTOSIZE)
2033 if i > 0
and self.GetColumnWidth(i) < minWidth[i > 4]:
2034 self.SetColumnWidth(i, minWidth[i > 4])
2036 self.SendSizeEvent()
2039 """!Get index of selected item"""
2050 sourceMapWin = self.gcp.SrcMapWindow
2051 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
2052 if self.gcp.show_target:
2053 targetMapWin = self.gcp.TgtMapWindow
2054 targetMapWin.UpdateMap(render=
False, renderVector=
False)
2060 When item double clicked, open editor to update coordinate values
2063 index = event.GetIndex()
2064 key = self.GetItemData(index)
2067 for i
in range(1, 5):
2068 coords.append(self.GetItem(index, i).GetText())
2070 dlg =
EditGCP(parent=self, id=wx.ID_ANY, data=coords, gcpno=key)
2072 if dlg.ShowModal() == wx.ID_OK:
2073 values = dlg.GetValues()
2075 if len(values) == 0:
2076 GError(parent = self,
2077 message=_(
"Invalid coordinate value. Operation canceled."))
2079 for i
in range(len(values)):
2080 if values[i] != coords[i]:
2081 self.SetStringItem(index, i + 1, values[i])
2086 self.SetStringItem(index, 5,
'')
2087 self.SetStringItem(index, 6,
'')
2088 key = self.GetItemData(index)
2089 self.gcp.mapcoordlist[key] = [key,
2096 self.gcp.UpdateColours()
2099 """!ListCtrl forgets selected item..."""
2102 wx.LIST_STATE_SELECTED,
2103 wx.LIST_STATE_SELECTED)
2108 Dialog to create a vector group (VREF file) for georectifying
2110 @todo Replace by g.group
2112 def __init__(self, parent, id, grassdb, location, mapset, group,
2113 style=wx.DEFAULT_DIALOG_STYLE):
2115 wx.Dialog.__init__(self, parent, id, style=style,
2116 title = _(
"Create vector map group"))
2130 for dir
in vectlist:
2137 vectlist.remove(dir)
2156 self.btnOK.SetDefault()
2162 self.
listMap = wx.CheckListBox(parent = self, id = wx.ID_ANY,
2169 for line
in f.readlines():
2170 line = line.replace(
'\n',
'')
2173 checked.append(line)
2174 self.listMap.SetCheckedStrings(checked)
2178 line = wx.StaticLine(parent = self,
2179 id = wx.ID_ANY, size = (20, -1),
2180 style = wx.LI_HORIZONTAL)
2185 sizer = wx.BoxSizer(wx.VERTICAL)
2187 box = wx.BoxSizer(wx.HORIZONTAL)
2188 box.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
2189 label = _(
'Select vector map(s) to add to group:')),
2190 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
2194 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
2198 sizer.Add(box, flag = wx.ALIGN_RIGHT | wx.ALL,
2201 sizer.Add(item = line, proportion = 0,
2202 flag = wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT,
2206 btnSizer = wx.StdDialogButtonSizer()
2208 btnSizer.AddButton(self.
btnOK)
2211 sizer.Add(item = btnSizer, proportion = 0,
2212 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER,
2215 self.SetSizer(sizer)
2220 """!Create VREF file"""
2222 for item
in range(self.listMap.GetCount()):
2223 if not self.listMap.IsChecked(item):
2225 vgrouplist.append(self.listMap.GetString(item))
2229 for vect
in vgrouplist:
2230 f.write(vect +
'\n')
2235 def __init__(self, parent, data, gcpno, id=wx.ID_ANY,
2236 title=_(
"Edit GCP"),
2237 style=wx.DEFAULT_DIALOG_STYLE):
2238 """!Dialog for editing GPC and map coordinates in list control"""
2240 wx.Dialog.__init__(self, parent, id, title=title, style=style)
2242 panel = wx.Panel(parent=self)
2244 sizer = wx.BoxSizer(wx.VERTICAL)
2246 box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
2247 label=
" %s %s " % (_(
"Ground Control Point No."), str(gcpno)))
2248 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2251 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
2253 self.
xcoord = wx.TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))
2254 self.
ycoord = wx.TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))
2255 self.
ecoord = wx.TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))
2256 self.
ncoord = wx.TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))
2266 for label, win
in ((_(
"source E:"), self.
xcoord),
2267 (_(
"target E:"), self.
ecoord),
2268 (_(
"source N:"), self.
ycoord),
2269 (_(
"target N:"), self.
ncoord)):
2270 label = wx.StaticText(parent=panel, id=wx.ID_ANY,
2272 gridSizer.Add(item=label,
2273 flag=wx.ALIGN_CENTER_VERTICAL,
2277 win.SetValue(str(data[idx]))
2279 gridSizer.Add(item=win,
2289 boxSizer.Add(item=gridSizer, proportion=1,
2290 flag=wx.EXPAND | wx.ALL, border=5)
2292 sizer.Add(item=boxSizer, proportion=1,
2293 flag=wx.EXPAND | wx.ALL, border=5)
2300 self.btnOk.SetDefault()
2302 btnSizer = wx.StdDialogButtonSizer()
2304 btnSizer.AddButton(self.
btnOk)
2307 sizer.Add(item=btnSizer, proportion=0,
2308 flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
2310 panel.SetSizer(sizer)
2314 """!Return list of values (as strings).
2318 float(self.xcoord.GetValue())
2319 float(self.ycoord.GetValue())
2320 float(self.ecoord.GetValue())
2321 float(self.ncoord.GetValue())
2325 valuelist.append(self.xcoord.GetValue())
2326 valuelist.append(self.ycoord.GetValue())
2327 valuelist.append(self.ecoord.GetValue())
2328 valuelist.append(self.ncoord.GetValue())
2333 def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
2334 style=wx.DEFAULT_DIALOG_STYLE):
2335 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
2337 Dialog to set profile text options: font, title
2338 and font size, axis labels and font size
2357 notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
2362 btnSave = wx.Button(self, wx.ID_SAVE)
2363 btnApply = wx.Button(self, wx.ID_APPLY)
2364 btnClose = wx.Button(self, wx.ID_CLOSE)
2365 btnApply.SetDefault()
2368 btnApply.Bind(wx.EVT_BUTTON, self.
OnApply)
2369 btnApply.SetToolTipString(_(
"Apply changes for the current session"))
2370 btnSave.Bind(wx.EVT_BUTTON, self.
OnSave)
2371 btnSave.SetToolTipString(_(
"Apply and save changes to user settings file (default for next sessions)"))
2372 btnClose.Bind(wx.EVT_BUTTON, self.
OnClose)
2373 btnClose.SetToolTipString(_(
"Close dialog"))
2376 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
2377 btnSizer.Add(btnApply, flag=wx.LEFT | wx.RIGHT, border=5)
2378 btnSizer.Add(btnSave, flag=wx.LEFT | wx.RIGHT, border=5)
2379 btnSizer.Add(btnClose, flag=wx.LEFT | wx.RIGHT, border=5)
2382 mainSizer = wx.BoxSizer(wx.VERTICAL)
2383 mainSizer.Add(item=notebook, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
2384 mainSizer.Add(item=btnSizer, proportion=0,
2385 flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
2388 self.SetSizer(mainSizer)
2391 def __CreateSymbologyPage(self, notebook):
2392 """!Create notebook page with symbology settings"""
2394 panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
2395 notebook.AddPage(page=panel, text=_(
"Symbology"))
2397 sizer = wx.BoxSizer(wx.VERTICAL)
2399 rmsgridSizer = wx.GridBagSizer(vgap=5, hgap=5)
2403 label=_(
"Highlight highest RMS error only"))
2404 hh = UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'highestonly')
2405 self.highlighthighest.SetValue(hh)
2406 rmsgridSizer.Add(item=self.
highlighthighest, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
2409 rmslabel = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Highlight RMS error > M + SD * factor:"))
2410 rmslabel.SetToolTip(wx.ToolTip(_(
"Highlight GCPs with an RMS error larger than \n"
2411 "mean + standard deviation * given factor. \n"
2412 "Recommended values for this factor are between 1 and 2.")))
2413 rmsgridSizer.Add(item=rmslabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
2414 sdfactor = UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'sdfactor')
2415 self.
rmsWin = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
2416 size=(70,-1), style=wx.TE_NOHIDESEL)
2417 self.rmsWin.SetValue(
"%s" % str(sdfactor))
2418 if (self.parent.highest_only ==
True):
2419 self.rmsWin.Disable()
2421 self.
symbol[
'sdfactor'] = self.rmsWin.GetId()
2422 rmsgridSizer.Add(item=self.
rmsWin, flag=wx.ALIGN_RIGHT, pos=(1, 1))
2423 rmsgridSizer.AddGrowableCol(1)
2424 sizer.Add(item=rmsgridSizer, flag=wx.EXPAND | wx.ALL, border=5)
2426 box = wx.StaticBox(parent=panel, id=wx.ID_ANY,
2427 label=
" %s " % _(
"Symbol settings"))
2428 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2429 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
2435 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color:"))
2436 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2437 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'color')
2438 colWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2439 colour=wx.Colour(col[0],
2443 self.
symbol[
'color'] = colWin.GetId()
2444 gridSizer.Add(item=colWin,
2445 flag=wx.ALIGN_RIGHT,
2452 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for high RMS error:"))
2453 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2454 hcol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'hcolor')
2455 hcolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2456 colour=wx.Colour(hcol[0],
2460 self.
symbol[
'hcolor'] = hcolWin.GetId()
2461 gridSizer.Add(item=hcolWin,
2462 flag=wx.ALIGN_RIGHT,
2469 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for selected GCP:"))
2470 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2471 scol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'scolor')
2472 scolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2473 colour=wx.Colour(scol[0],
2477 self.
symbol[
'scolor'] = scolWin.GetId()
2478 gridSizer.Add(item=scolWin,
2479 flag=wx.ALIGN_RIGHT,
2486 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for unused GCPs:"))
2487 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2488 ucol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'ucolor')
2489 ucolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2490 colour=wx.Colour(ucol[0],
2494 self.
symbol[
'ucolor'] = ucolWin.GetId()
2495 gridSizer.Add(item=ucolWin,
2496 flag=wx.ALIGN_RIGHT,
2502 label=_(
"Show unused GCPs"))
2503 shuu = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'unused')
2504 self.showunused.SetValue(shuu)
2505 gridSizer.Add(item=self.
showunused, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2511 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Symbol size:"))
2512 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2513 symsize = int(UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'size'))
2514 sizeWin = wx.SpinCtrl(parent=panel, id=wx.ID_ANY,
2516 sizeWin.SetValue(symsize)
2517 self.
symbol[
'size'] = sizeWin.GetId()
2518 gridSizer.Add(item=sizeWin,
2519 flag=wx.ALIGN_RIGHT,
2526 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Line width:"))
2527 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2528 width = int(UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'width'))
2529 widWin = wx.SpinCtrl(parent=panel, id=wx.ID_ANY,
2531 widWin.SetValue(width)
2532 self.
symbol[
'width'] = widWin.GetId()
2533 gridSizer.Add(item=widWin,
2534 flag=wx.ALIGN_RIGHT,
2536 gridSizer.AddGrowableCol(1)
2538 boxSizer.Add(item=gridSizer, flag=wx.EXPAND)
2539 sizer.Add(item=boxSizer, flag=wx.EXPAND | wx.ALL, border=5)
2546 size=globalvar.DIALOG_GSELECT_SIZE, type=
'cell', updateOnPopup =
False)
2547 self.parent.grwiz.SwitchEnv(
'source')
2548 self.srcselection.SetElementList(maptype)
2550 self.srcselection.tcp.GetElementList(elements = self.parent.src_maps)
2554 size=globalvar.DIALOG_GSELECT_SIZE, type=
'cell', updateOnPopup =
False)
2555 self.parent.grwiz.SwitchEnv(
'target')
2556 self.tgtselection.SetElementList(maptype)
2557 self.tgtselection.GetElementList()
2559 sizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Select source map to display:')),
2560 proportion=0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2562 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2563 self.srcselection.SetValue(src_map)
2564 sizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Select target map to display:')),
2565 proportion=0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2567 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2568 self.tgtselection.SetValue(tgt_map)
2571 self.highlighthighest.Bind(wx.EVT_CHECKBOX, self.
OnHighlight)
2572 self.rmsWin.Bind(wx.EVT_TEXT, self.
OnSDFactor)
2576 panel.SetSizer(sizer)
2580 def __CreateRectificationPage(self, notebook):
2581 """!Create notebook page with symbology settings"""
2583 panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
2584 notebook.AddPage(page=panel, text=_(
"Rectification"))
2586 sizer = wx.BoxSizer(wx.VERTICAL)
2590 label=
" %s " % _(
"Select rectification order"),
2591 choices=[_(
'1st order'), _(
'2nd order'), _(
'3rd order')],
2592 majorDimension=wx.RA_SPECIFY_COLS)
2593 sizer.Add(item=self.
rb_grorder, proportion=0,
2594 flag=wx.EXPAND | wx.ALL, border=5)
2595 self.rb_grorder.SetSelection(self.parent.gr_order - 1)
2598 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
2599 gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Select interpolation method:')),
2600 pos=(0,0), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2603 gridSizer.Add(item=self.
grmethod, pos=(0,1),
2604 flag=wx.ALIGN_RIGHT, border=5)
2605 self.grmethod.SetStringSelection(self.parent.gr_method)
2606 gridSizer.AddGrowableCol(1)
2607 sizer.Add(item=gridSizer, flag=wx.EXPAND | wx.ALL, border=5)
2610 self.
check = wx.CheckBox(parent=panel, id=wx.ID_ANY,
2611 label=_(
"clip to computational region in target location"))
2612 sizer.Add(item=self.
check, proportion=0,
2613 flag=wx.EXPAND | wx.ALL, border=5)
2614 self.check.SetValue(self.parent.clip_to_region)
2617 sizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Extension for output maps:')),
2618 proportion=0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2619 self.
ext_txt = wx.TextCtrl(parent=panel, id=wx.ID_ANY, value=
"", size=(350,-1))
2620 self.ext_txt.SetValue(self.parent.extension)
2622 proportion=0, flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2626 self.Bind(wx.EVT_RADIOBOX, self.parent.OnGROrder, self.
rb_grorder)
2630 panel.SetSizer(sizer)
2635 """!Checkbox 'highlighthighest' checked/unchecked"""
2636 if self.highlighthighest.IsChecked():
2637 self.parent.highest_only =
True
2638 self.rmsWin.Disable()
2640 self.parent.highest_only =
False
2641 self.rmsWin.Enable()
2644 """!New factor for RMS threshold = M + SD * factor"""
2646 self.
sdfactor = float(self.rmsWin.GetValue())
2651 GError(parent = self,
2652 message=_(
'RMS threshold factor must be > 0'))
2654 GError(parent = self,
2655 message=_(
'RMS threshold factor is < 1\n'
2656 'Too many points might be highlighted'))
2659 """!Source map to display selected"""
2662 tmp_map = self.srcselection.GetValue()
2664 if not tmp_map ==
'' and not tmp_map == src_map:
2668 """!Target map to display selected"""
2671 tmp_map = self.tgtselection.GetValue()
2673 if not tmp_map == tgt_map:
2677 self.parent.gr_method = self.
methods[event.GetSelection()]
2680 self.parent.clip_to_region = event.IsChecked()
2683 self.parent.extension = self.ext_txt.GetValue()
2691 UserSettings.Set(group=
'gcpman', key=
'rms', subkey=
'highestonly',
2692 value=self.highlighthighest.GetValue())
2694 UserSettings.Set(group=
'gcpman', key=
'rms', subkey=
'sdfactor',
2697 self.parent.sdfactor = self.
sdfactor
2698 if self.parent.rmsthresh > 0:
2699 self.parent.rmsthresh = self.parent.mean + self.parent.sdfactor * self.parent.rmssd
2701 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'color',
2702 value=tuple(wx.FindWindowById(self.
symbol[
'color']).GetColour()))
2703 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'hcolor',
2704 value=tuple(wx.FindWindowById(self.
symbol[
'hcolor']).GetColour()))
2705 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'scolor',
2706 value=tuple(wx.FindWindowById(self.
symbol[
'scolor']).GetColour()))
2707 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'ucolor',
2708 value=tuple(wx.FindWindowById(self.
symbol[
'ucolor']).GetColour()))
2709 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'unused',
2710 value=self.showunused.GetValue())
2711 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'size',
2713 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'width',
2717 srcrenderVector =
False
2719 tgtrenderVector =
False
2722 layers = self.parent.grwiz.SrcMap.GetListOfLayers()
2723 self.parent.grwiz.SrcMap.DeleteLayer(layers[0])
2726 cmdlist = [
'd.rast',
'map=%s' % src_map]
2727 self.parent.grwiz.SwitchEnv(
'source')
2729 self.parent.grwiz.SrcMap.AddLayer(type=
'raster', command=cmdlist, l_active=
True,
2730 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
2732 self.parent.grwiz.SwitchEnv(
'target')
2737 layers = self.parent.grwiz.TgtMap.GetListOfLayers()
2739 self.parent.grwiz.TgtMap.DeleteLayer(layers[0])
2743 cmdlist = [
'd.rast',
'map=%s' % tgt_map]
2745 self.parent.grwiz.TgtMap.AddLayer(type=
'raster', command=cmdlist, l_active=
True,
2746 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
2749 if self.parent.show_target ==
False:
2750 self.parent.show_target =
True
2751 self.parent._mgr.GetPane(
"target").Show()
2752 self.parent._mgr.Update()
2753 self.parent.GetMapToolbar().Enable(
'zoommenu', enable =
True)
2754 self.parent.activemap.Enable()
2755 self.parent.TgtMapWindow.ZoomToMap(layers = self.parent.TgtMap.GetListOfLayers())
2757 if self.parent.show_target ==
True:
2758 self.parent.show_target =
False
2759 self.parent._mgr.GetPane(
"target").Hide()
2760 self.parent._mgr.Update()
2761 self.parent.activemap.SetSelection(0)
2762 self.parent.activemap.Enable(
False)
2763 self.parent.GetMapToolbar().Enable(
'zoommenu', enable =
False)
2765 self.parent.UpdateColours(srcrender, srcrenderVector, tgtrender, tgtrenderVector)
2768 """!Button 'Save' pressed"""
2771 UserSettings.ReadSettingsFile(settings=fileSettings)
2772 fileSettings[
'gcpman'] = UserSettings.Get(group=
'gcpman')
2773 file = UserSettings.SaveToFile(fileSettings)
2774 self.parent.parent.goutput.WriteLog(_(
'GCP Manager settings saved to file \'%s\'.') % file)
2778 """!Button 'Apply' pressed"""
2783 """!Button 'Cancel' pressed"""
def OnMaptype
Change map type.
def OnVGroup
Add vector maps to group.
def OnSrcSelection
Source map to display selected.
def MakeVGroup
Create VREF file.
def OnZoomToTarget
Set source map window to match extents of target map window.
def AdjustMap
Adjust map window to new extents.
Manages ground control points for georectifying.
def GetSelected
Get index of selected item.
Location wizard - creates a new GRASS Location.
def OnZoomMenuGCP
Popup Zoom menu.
def OnGeorectDone
Print final message.
def GetValues
Return list of values (as strings).
def OnSrcSelection
Source map to display selected.
def OnApply
Button 'Apply' pressed.
def OnHighlight
Checkbox 'highlighthighest' checked/unchecked.
def OnTgtSelection
Target map to display selected.
Various dialogs used in wxGUI.
def OnQuit
Quit georectifier.
Custom control that selects elements.
Rendering map layers and overlays into map composition image.
def split
Platform spefic shlex.split.
def ReloadGCPs
Reload data from file.
def OnCheckItem
Item is checked/unchecked.
def OnColClick
ListCtrl forgets selected item...
def OnGLMFocus
Layer Manager focus.
def GetLayerNameFromCmd
Get map name from GRASS command.
def __CreateSymbologyPage
Create notebook page with symbology settings.
def ListSortLower
Sort list items (not case-sensitive)
def __del__
Disable GCP manager mode.
def OnMapset
Sets source mapset for map(s) to georectify.
def OnSettings
GCP Manager settings.
def GetTempfile
Creates GRASS temporary file using defined prefix.
def ResizeColumns
Resize columns.
Display to manage ground control points with two toolbars, one for various display management functio...
def OnMkGroup
Create new group in source location/mapset.
def OnDispResize
GCP Map Display resized, adjust Map Windows.
def OnTgtSelection
Source map to display selected.
def __CreateRectificationPage
Create notebook page with symbology settings.
def OnZoomToSource
Set target map window to match extents of source map window.
def UpdateColours
update colours
def SetSrcEnv
Create environment to use for location and mapset that are the source of the file(s) to georectify...
def __init__
Dialog for editing GPC and map coordinates in list control.
def Cleanup
Return to current location and mapset.
def OnSDFactor
New factor for RMS threshold = M + SD * factor.
def LoadData
Load data into list.
def OnLocation
Sets source location for map(s) to georectify.
def CreateGCPList
Create GCP List Control.
def OnClose
Button 'Cancel' pressed.
def OnSave
Button 'Save' pressed.
def RunCommand
Run GRASS command.
def OnHelp
Show GCP Manager manual page.