4 @brief Georectification module for GRASS GIS. Includes ground control
5 point management and interactive point and click GCP creation
18 (C) 2006-2011 by the GRASS Development Team
19 This program is free software under the GNU General Public License
20 (>=v2). Read the file COPYING that comes with GRASS for details.
22 @author Michael Barton
23 @author Updated by Martin Landa <landa.martin gmail.com>
24 @author Markus Metz redesign georectfier -> GCP Manager
35 from wx.lib.mixins.listctrl
import CheckListCtrlMixin, ColumnSorterMixin, ListCtrlAutoWidthMixin
36 import wx.lib.colourselect
as csel
37 import wx.wizard
as wiz
48 from debug
import Debug
as Debug
49 from icon
import Icons
as Icons
50 from location_wizard
import TitledPage
as TitledPage
51 from preferences
import globalSettings
as UserSettings
52 from gcpmapdisp
import MapFrame
53 from mapdisp_window
import BufferedWindow
58 CompatPath = globalvar.ETCWXDIR
59 sys.path.append(CompatPath)
60 from compat
import subprocess
62 sys.path.append(os.path.join(globalvar.ETCWXDIR,
"icons"))
76 stream = open(os.path.join(globalvar.ETCIMGDIR,
'small_up_arrow.png'),
'rb')
78 img = wx.ImageFromStream(stream)
84 stream = open(os.path.join(globalvar.ETCIMGDIR,
'small_down_arrow.png'),
'rb')
86 img = wx.ImageFromStream(stream)
94 Start wizard here and finish wizard here
112 for line
in f.readlines():
113 line = line.replace(
'\n',
'').strip()
116 key, value = line.split(
':', 1)
143 self.
wizard = wiz.Wizard(parent=parent, id=wx.ID_ANY, title=_(
"Setup for georectification"))
153 self.grouppage.SetNext(self.
mappage)
159 self.startpage.DoLayout()
160 self.grouppage.DoLayout()
161 self.mappage.DoLayout()
172 if self.wizard.RunWizard(self.
startpage):
176 message = _(
"Georectifying setup canceled."))
180 message = _(
"Georectifying setup canceled."))
197 if maptype ==
'cell':
198 rendertype =
'raster'
199 cmdlist = [
'd.rast',
'map=%s' % src_map]
201 rendertype =
'vector'
202 cmdlist = [
'd.vect',
'map=%s' % src_map]
205 name, found = utils.GetLayerNameFromCmd(cmdlist)
206 self.SrcMap.AddLayer(type=rendertype, command=cmdlist, l_active=
True,
207 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
213 if maptype ==
'cell':
214 rendertype =
'raster'
215 cmdlist = [
'd.rast',
'map=%s' % tgt_map]
217 rendertype =
'vector'
218 cmdlist = [
'd.vect',
'map=%s' % tgt_map]
221 name, found = utils.GetLayerNameFromCmd(cmdlist)
222 self.TgtMap.AddLayer(type=rendertype, command=cmdlist, l_active=
True,
223 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
229 toolbars=[
"gcpdisp"],
233 self.gcpmgr.InitMapDisplay()
234 self.gcpmgr.CenterOnScreen()
237 self.gcpmgr._mgr.Update()
242 """!Create environment to use for location and mapset
243 that are the source of the file(s) to georectify
245 @param location source location
246 @param mapset source mapset
248 @return False on error
249 @return True on success
266 for line
in self.gisrc_dict.items():
267 f.write(line[0] +
": " + line[1] +
"\n")
275 Switches between original working location/mapset and
276 location/mapset that is source of file(s) to georectify
284 elif grc ==
'source':
295 """!Layer Manager focus"""
301 """!Return to current location and mapset"""
303 self.parent.gcpmanagement =
None
305 self.wizard.Destroy()
309 Set map type (raster or vector) to georectify and
310 select location/mapset of map(s) to georectify.
313 TitledPage.__init__(self, wizard, _(
"Select map type and location/mapset"))
324 self.sizer.AddGrowableCol(2)
327 label=
' %s ' % _(
"Map type to georectify"),
328 choices=[_(
'raster'), _(
'vector')],
329 majorDimension=wx.RA_SPECIFY_COLS)
331 flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
332 pos=(1, 1), span=(1, 2))
335 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select source location:')),
336 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
340 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
344 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select source mapset:')),
345 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
350 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
360 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
364 """!Change map type"""
367 if event.GetInt() == 0:
373 """!Sets source location for map(s) to georectify"""
382 if item !=
'PERMANENT':
383 self.mapsetList.append(item)
387 self.mapsetList.insert(0,
'PERMANENT')
389 self.cb_mapset.SetStringSelection(self.
xymapset)
391 if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
392 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
395 """!Sets source mapset for map(s) to georectify"""
398 'before selecting a mapset'),
404 if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
405 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
408 if event.GetDirection()
and \
411 'and mapset in order to continue'),
420 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
422 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
426 Set group to georectify. Create group if desired.
429 TitledPage.__init__(self, wizard, _(
"Select image/map group to georectify"))
446 self.sizer.AddGrowableCol(2)
448 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select group:')),
449 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
451 self.
cb_group = wx.ComboBox(parent=self, id=wx.ID_ANY,
453 style=wx.CB_DROPDOWN | wx.CB_READONLY)
455 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
459 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Create group if none exists')),
460 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
462 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
463 self.
btn_mkgroup = wx.Button(parent=self, id=wx.ID_ANY, label=_(
"Create/edit group..."))
464 self.
btn_vgroup = wx.Button(parent=self, id=wx.ID_ANY, label=_(
"Add vector map to group..."))
466 flag=wx.RIGHT, border=5)
469 flag=wx.LEFT, border=5)
471 self.sizer.Add(item=btnSizer,
472 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
476 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Extension for output maps:')),
477 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
479 self.
ext_txt = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(350,-1))
481 self.sizer.Add(item=self.
ext_txt,
482 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
491 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
492 self.Bind(wx.EVT_CLOSE, self.parent.Cleanup)
495 self.btn_vgroup.Hide()
498 self.
xygroup = event.GetString()
501 """!Create new group in source location/mapset"""
502 menuform.GUI(parent = self.parent.parent, modal =
True).ParseCommand([
'i.group'],
506 """!Add vector maps to group"""
514 if dlg.ShowModal() != wx.ID_OK:
521 """!Process i.group"""
533 if event.GetDirection()
and self.
xygroup ==
'':
535 'group in order to continue'),
540 if event.GetDirection()
and self.
extension ==
'':
542 'extension in order to continue'),
552 self.
xylocation = self.parent.gisrc_dict[
'LOCATION_NAME']
553 self.
xymapset = self.parent.gisrc_dict[
'MAPSET']
570 self.groupList.append(item)
572 if maptype ==
'cell':
573 self.btn_vgroup.Hide()
576 elif maptype ==
'vector':
577 self.btn_vgroup.Show()
586 self.cb_group.SetSelection(0)
591 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
593 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
596 self.parent.SwitchEnv(
'source')
600 Select ungeoreferenced map to display for interactively
601 setting ground control points (GCPs).
604 TitledPage.__init__(self, wizard,
605 _(
"Select maps to display for ground control point (GCP) creation"))
613 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select source 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,
624 self.sizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
'Select target map to display:')),
625 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
629 size=globalvar.DIALOG_GSELECT_SIZE, type=maptype, updateOnPopup =
False)
632 flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5,
641 self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.
OnEnterPage)
642 self.Bind(wx.EVT_CLOSE, self.parent.Cleanup)
645 """!Source map to display selected"""
649 src_map = event.GetString()
652 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
654 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
658 if maptype ==
'cell':
660 elif maptype ==
'vector':
663 if p.returncode == 0:
664 print 'returncode = ', str(p.returncode)
665 self.parent.Map.region = self.parent.Map.GetRegion()
670 """!Source map to display selected"""
673 tgt_map = event.GetString()
679 if event.GetDirection()
and (src_map ==
''):
681 'in order to continue'),
686 self.parent.SwitchEnv(
'target')
693 self.srcselection.SetElementList(maptype)
694 ret = gcmd.RunCommand(
'i.group',
697 group = self.parent.grouppage.xygroup,
701 self.parent.src_maps = ret.splitlines()
704 message = _(
'No maps in selected group <%s>.\n'
705 'Please edit group or select another group.') %
706 self.parent.grouppage.xygroup)
710 self.srcselection.tcp.GetElementList(elements = self.parent.src_maps)
711 src_map = self.parent.src_maps[0]
712 self.srcselection.SetValue(src_map)
714 self.parent.SwitchEnv(
'target')
715 self.tgtselection.SetElementList(maptype)
716 self.tgtselection.GetElementList()
717 self.parent.SwitchEnv(
'source')
720 wx.FindWindowById(wx.ID_FORWARD).Enable(
False)
722 wx.FindWindowById(wx.ID_FORWARD).Enable(
True)
724 class GCP(MapFrame, wx.Frame, ColumnSorterMixin):
726 Manages ground control points for georectifying. Calculates RMS statics.
727 Calls i.rectify or v.transform to georectify map.
729 def __init__(self, parent, grwiz = None, id = wx.ID_ANY,
730 title = _(
"Manage Ground Control Points"),
731 size = (700, 300), toolbars=[
"gcpdisp"], Map=
None, lmgr=
None):
741 MapFrame.__init__(self, parent, id, title, size = size,
742 Map=Map, toolbars=[
"gcpdisp"], lmgr=lmgr, name=
'GCPMapWindow')
748 self.parent.gcpmanagement = self
800 if os.path.exists(self.
file[
'points']):
801 shutil.copy(self.
file[
'points'], self.
file[
'points_bak'])
817 self.mapcoordlist.append([ 0,
839 self.
il = self.list.GetImageList(wx.IMAGE_LIST_SMALL)
843 self.
sm_dn = self.il.Add(SmallDnArrow)
844 self.
sm_up = self.il.Add(SmallUpArrow)
848 self.mapwin.mouse[
'box'] =
'point'
849 self.mapwin.mouse[
"use"] ==
"pointer"
850 self.mapwin.zoomtype = 0
851 self.mapwin.pen = wx.Pen(colour=
'black', width=2, style=wx.SOLID)
852 self.mapwin.SetCursor(self.cursors[
"cross"])
854 self.
mapwin = self.TgtMapWindow
857 self.mapwin.mouse[
'box'] =
'point'
858 self.mapwin.mouse[
"use"] ==
"pointer"
859 self.mapwin.zoomtype = 0
860 self.mapwin.pen = wx.Pen(colour=
'black', width=2, style=wx.SOLID)
861 self.mapwin.SetCursor(self.cursors[
"cross"])
869 self.OnZoomToMap(
None)
872 self.
Map = self.SrcMap
873 self.OnZoomToMap(
None)
878 self.Bind(wx.EVT_ACTIVATE, self.
OnFocus)
879 self.Bind(wx.EVT_CLOSE, self.
OnQuit)
882 """!Disable GCP manager mode"""
883 self.parent.gcpmanagement =
None
886 """!Create GCP List Control"""
888 return GCPList(parent=self, gcp=self)
903 ncols = self.list.GetColumnCount()
904 ColumnSorterMixin.__init__(self, ncols)
910 Sets rectification target to current location and mapset
914 gcmd.RunCommand(
'i.target',
919 self.grwiz.SwitchEnv(
'source')
920 gcmd.RunCommand(
'i.target',
923 location = tlocation,
925 self.grwiz.SwitchEnv(
'target')
929 Appends an item to GCP list
931 keyval = self.list.AddGCPItem() + 1
933 self.mapcoordlist.append([ keyval,
941 if self.statusbarWin[
'toggle'].GetSelection() == 7:
942 self.StatusbarUpdate()
946 Deletes selected item in GCP list
950 if self.list.GetItemCount() <= minNumOfItems:
952 message=_(
"At least %d GCPs required. Operation cancelled.") % minNumOfItems)
955 key = self.list.DeleteGCPItem()
960 index = self.list.FindItemData(-1, newkey + 1)
962 self.list.SetStringItem(index, 0, str(newkey))
963 self.list.SetItemData(index, newkey)
966 if self.list.GetItemCount() > 0:
967 if self.list.selected < self.list.GetItemCount():
968 self.list.selectedkey = self.list.GetItemData(self.list.selected)
970 self.list.selected = self.list.GetItemCount() - 1
971 self.list.selectedkey = self.list.GetItemData(self.list.selected)
973 self.list.SetItemState(self.list.selected,
974 wx.LIST_STATE_SELECTED,
975 wx.LIST_STATE_SELECTED)
977 self.list.selected = wx.NOT_FOUND
978 self.list.selectedkey = -1
982 if self.statusbarWin[
'toggle'].GetSelection() == 7:
983 self.StatusbarUpdate()
984 if self.list.selectedkey > 0:
985 self.statusbarWin[
'goto'].SetValue(self.list.selectedkey)
990 Clears all values in selected item of GCP list and unchecks it
992 index = self.list.GetSelected()
995 self.list.SetStringItem(index, i,
'0.0')
996 self.list.SetStringItem(index, 4,
'')
997 self.list.SetStringItem(index, 5,
'')
998 self.list.CheckItem(index,
False)
999 key = self.list.GetItemData(index)
1002 self.
mapcoordlist[key] = [key, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
1006 Updates GCP and map coord maps and redraws
1007 active (checked) GCP markers
1009 self.
highest_only = UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'highestonly')
1011 self.
show_unused = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'unused')
1012 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'color')
1013 wxLowCol = wx.Colour(col[0], col[1], col[2], 255)
1014 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'hcolor')
1015 wxHiCol = wx.Colour(col[0], col[1], col[2], 255)
1016 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'scolor')
1017 wxSelCol = wx.Colour(col[0], col[1], col[2], 255)
1018 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'ucolor')
1019 wxUnCol = wx.Colour(col[0], col[1], col[2], 255)
1020 spx = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'size')
1021 wpx = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'width')
1022 font = self.GetFont()
1023 font.SetPointSize(int(spx) + 2)
1025 penOrig = polypenOrig =
None
1029 if coordtype ==
'source':
1030 mapWin = self.SrcMapWindow
1033 elif coordtype ==
'target':
1034 mapWin = self.TgtMapWindow
1040 message=
"%s%s." % (_(
"mapwin not defined for "),
1045 for idx
in range(self.list.GetItemCount()):
1047 key = self.list.GetItemData(idx)
1050 if not self.list.IsChecked(idx):
1067 if idx == self.list.selected:
1071 penOrig = mapWin.pen
1072 polypenOrig = mapWin.polypen
1073 mapWin.pen = wx.Pen(colour=wxCol, width=wpx, style=wx.SOLID)
1074 mapWin.polypen = wx.Pen(colour=wxCol, width=wpx, style=wx.SOLID)
1076 mapWin.pen.SetColour(wxCol)
1077 mapWin.polypen.SetColour(wxCol)
1079 coord = mapWin.Cell2Pixel((gcp[e_idx], gcp[n_idx]))
1080 mapWin.DrawCross(pdc=mapWin.pdcTmp, coords=coord,
1081 size=spx, text={
'text' :
'%s' % str(gcp[0]),
1085 'coords': [coord[0] + 5,
1091 mapWin.pen = penOrig
1092 mapWin.polypen = polypenOrig
1094 def SetGCPData(self, coordtype, coord, mapdisp=None, confirm=False):
1096 Inserts coordinates from file, mouse click on map, or after editing
1097 into selected item of GCP list and checks it for use
1100 index = self.list.GetSelected()
1101 if index == wx.NOT_FOUND:
1107 key = self.list.GetItemData(index)
1110 currloc = _(
"source")
1112 currloc = _(
"target")
1113 ret = wx.MessageBox(parent=self,
1114 caption=_(
"Set GCP coordinates"),
1115 message=_(
'Set %(coor)s coordinates for GCP No. %(key)s? \n\n'
1116 'East: %(coor0)s \n'
1117 'North: %(coor1)s') % \
1120 'coor0' : str(coord0),
1121 'coor1' : str(coord1) },
1122 style=wx.ICON_QUESTION | wx.YES_NO | wx.CENTRE)
1126 self.MapWindow.SetFocus()
1130 if coordtype ==
'source':
1131 self.list.SetStringItem(index, 1, str(coord0))
1132 self.list.SetStringItem(index, 2, str(coord1))
1135 elif coordtype ==
'target':
1136 self.list.SetStringItem(index, 3, str(coord0))
1137 self.list.SetStringItem(index, 4, str(coord1))
1141 self.list.SetStringItem(index, 5,
'0')
1142 self.list.SetStringItem(index, 6,
'0')
1150 Make a POINTS file or save GCP coordinates to existing POINTS file
1155 f = open(self.
file[
'points'], mode=
'w')
1157 f.write(
'# Ground Control Points File\n')
1161 f.write(
"#\tsource\t\ttarget\t\tstatus\n")
1162 f.write(
"#\teast\tnorth\teast\tnorth\t(1=ok, 0=ignore)\n")
1163 f.write(
"#----------------------- ----------------------- ---------------\n")
1165 for index
in range(self.list.GetItemCount()):
1166 if self.list.IsChecked(index) ==
True:
1171 coord0 = self.list.GetItem(index, 1).GetText()
1172 coord1 = self.list.GetItem(index, 2).GetText()
1173 coord2 = self.list.GetItem(index, 3).GetText()
1174 coord3 = self.list.GetItem(index, 4).GetText()
1175 f.write(coord0 +
' ' + coord1 +
' ' + coord2 +
' ' + coord3 +
' ' + check +
'\n')
1177 except IOError, err:
1179 message=
"%s <%s>. %s%s" % (_(
"Writing POINTS file failed"),
1180 self.
file[
'points'], os.linesep, err))
1187 shutil.copy(self.
file[
'points'], self.
file[
'points_bak'])
1188 self.parent.goutput.WriteLog(_(
'POINTS file saved for group <%s>') % self.
xygroup)
1193 Reads GCPs and georectified coordinates from POINTS file
1198 sourceMapWin = self.SrcMapWindow
1199 targetMapWin = self.TgtMapWindow
1202 if not sourceMapWin:
1204 message =
"%s. %s%s" % (_(
"source mapwin not defined"),
1207 if not targetMapWin:
1209 message=
"%s. %s%s" % (_(
"target mapwin not defined"),
1213 f = open(self.
file[
'points'],
'r')
1216 for line
in f.readlines():
1217 if line[0] ==
'#' or line ==
'':
1219 line = line.replace(
'\n',
'').strip()
1220 coords =
map(float, line.split())
1228 self.
SetGCPData(
'source', (coords[0], coords[1]), sourceMapWin)
1229 self.
SetGCPData(
'target', (coords[2], coords[3]), targetMapWin)
1230 index = self.list.GetSelected()
1231 if index != wx.NOT_FOUND:
1232 self.list.CheckItem(index, check)
1235 except IOError, err:
1237 message =
"%s <%s>. %s%s" % (_(
"Reading POINTS file failed"),
1238 self.
file[
'points'], os.linesep, err))
1253 """!Reload data from file"""
1256 shutil.copy(self.
file[
'points_bak'], self.
file[
'points'])
1260 self.mapcoordlist.append([ 0,
1268 self.list.LoadData()
1272 self.list.ClearColumnImage(self._col)
1276 sourceMapWin = self.SrcMapWindow
1277 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1279 targetMapWin = self.TgtMapWindow
1280 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1290 self.RMSError(self.xygroup,self.gr_order)
1292 sourceMapWin = self.SrcMapWindow
1293 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1294 if self.show_target:
1295 targetMapWin = self.TgtMapWindow
1296 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1300 Checks to make sure that the minimum number of GCPs have been defined and
1301 are active for the selected transformation order
1308 message=_(
'Insufficient points defined and active (checked) '
1309 'for selected rectification method.\n'
1310 '3+ points needed for 1st order,\n'
1311 '6+ points for 2nd order, and\n'
1312 '10+ points for 3rd order.'))
1319 Georectifies map(s) in group using i.rectify or v.transform
1327 if maptype ==
'cell':
1328 self.grwiz.SwitchEnv(
'source')
1335 busy = wx.BusyInfo(message=_(
"Rectifying images, please wait..."),
1339 ret, msg = gcmd.RunCommand(
'i.rectify',
1353 print >> sys.stderr, msg
1355 elif maptype ==
'vector':
1370 self.grwiz.SwitchEnv(
'source')
1373 f = open(self.
file[
'vgrp'])
1376 for vect
in f.readlines():
1377 vect = vect.strip(
'\n')
1380 vectlist.append(vect)
1385 for vect
in vectlist:
1387 self.parent.goutput.WriteLog(text = _(
'Transforming <%s>...') % vect,
1391 ret, out, err = gcmd.RunCommand(
'v.transform',
1395 pointsfile = self.
file[
'points'],
1396 getErrorMsg =
True, read =
True)
1399 self.VectGRList.append(self.
outname)
1402 self.parent.goutput.WriteLog(text = out, switchPage =
True)
1404 self.parent.goutput.WriteError(_(
'Georectification of vector map <%s> failed') %
1406 self.parent.goutput.WriteError(err)
1445 if os.path.isdir(vpath):
1446 self.parent.goutput.WriteWarning(_(
'Vector map <%s> already exists. '
1447 'Change extension name and '
1448 'georectify again.') % self.
outname)
1452 shutil.copytree(xyvpath, vpath)
1456 gcmd.GMessage(_(
'For all vector maps georectified successfully,') +
'\n' +
1457 _(
'you will need to copy any attribute tables') +
'\n' +
1458 _(
'and reconnect them to the georectified vectors'),
1461 self.grwiz.SwitchEnv(
'target')
1464 """!Print final message"""
1466 if maptype ==
'cell':
1469 returncode = kargs[
'returncode']
1472 self.VectGRList.append(self.
outname)
1473 print '*****vector list = ' + str(self.
VectGRList)
1475 self.parent.goutput.WriteError(_(
'Georectification of vector map <%s> failed') %
1480 """!GCP Manager settings"""
1481 dlg =
GrSettingsDialog(parent=self, id=wx.ID_ANY, title=_(
'GCP Manager settings'))
1483 if dlg.ShowModal() == wx.ID_OK:
1488 def UpdateColours(self, srcrender=False, srcrenderVector=False,
1489 tgtrender=
False, tgtrenderVector=
False):
1490 """!update colours"""
1491 highest_fwd_err = 0.0
1495 for index
in range(self.list.GetItemCount()):
1496 if self.list.IsChecked(index):
1497 key = self.list.GetItemData(index)
1501 self.list.SetItemTextColour(index, wx.BLACK)
1502 if highest_fwd_err < fwd_err:
1503 highest_fwd_err = fwd_err
1508 self.list.SetItemTextColour(index, wx.RED)
1510 self.list.SetItemTextColour(index, wx.BLACK)
1512 self.list.SetItemTextColour(index, wx.BLACK)
1515 self.list.SetItemTextColour(highest_idx, wx.RED)
1517 sourceMapWin = self.SrcMapWindow
1518 sourceMapWin.UpdateMap(render=srcrender, renderVector=srcrenderVector)
1520 targetMapWin = self.TgtMapWindow
1521 targetMapWin.UpdateMap(render=tgtrender, renderVector=tgtrenderVector)
1524 """!Quit georectifier"""
1525 ret = wx.MessageBox(parent=self,
1526 caption=_(
"Quit GCP Manager"),
1527 message=_(
'Save ground control points?'),
1528 style=wx.ICON_QUESTION | wx.YES_NO | wx.CANCEL | wx.CENTRE)
1530 if ret != wx.CANCEL:
1535 if os.path.exists(self.
file[
'points_bak']):
1536 shutil.copy(self.
file[
'points_bak'], self.
file[
'points'])
1538 if os.path.exists(self.
file[
'points_bak']):
1539 os.unlink(self.
file[
'points_bak'])
1544 self.grwiz.Cleanup()
1552 sets transformation order for georectifying
1557 numOfItems = self.list.GetItemCount()
1558 minNumOfItems = numOfItems
1566 diff = 6 - numOfItems
1573 for i
in range(minNumOfItems - numOfItems):
1576 return minNumOfItems
1580 Uses g.transform to calculate forward and backward error for each used GCP
1581 in POINTS file and insert error values into GCP list.
1582 Calculates total forward and backward RMS error for all used points
1592 self.grwiz.SwitchEnv(
'source')
1594 ret = gcmd.RunCommand(
'g.transform',
1600 self.grwiz.SwitchEnv(
'target')
1603 errlist = ret.splitlines()
1606 message=_(
'Could not calculate RMS Error.\n'
1607 'Possible error with g.transform.'))
1611 sdfactor = float(UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'sdfactor'))
1616 highest_fwd_err = 0.0
1620 for index
in range(self.list.GetItemCount()):
1621 key = self.list.GetItemData(index)
1622 if self.list.IsChecked(index):
1623 fwd_err, bkw_err = errlist[GCPcount].
split()
1624 self.list.SetStringItem(index, 5, fwd_err)
1625 self.list.SetStringItem(index, 6, bkw_err)
1628 self.list.SetItemTextColour(index, wx.BLACK)
1630 if highest_fwd_err < float(fwd_err):
1631 highest_fwd_err = float(fwd_err)
1635 sumsq_fwd_err += float(fwd_err)**2
1636 sumsq_bkw_err += float(bkw_err)**2
1637 sum_fwd_err += float(fwd_err)
1640 self.list.SetStringItem(index, 5,
'')
1641 self.list.SetStringItem(index, 6,
'')
1644 self.list.SetItemTextColour(index, wx.BLACK)
1648 sum_fwd_err /= GCPcount
1649 self.
rmsmean = sum_fwd_err /GCPcount
1650 self.
rmssd = (((sumsq_fwd_err/GCPcount) - self.
rmsmean**2)**0.5)
1658 self.list.SetItemTextColour(highest_idx, wx.RED)
1660 for index
in range(self.list.GetItemCount()):
1661 if self.list.IsChecked(index):
1662 key = self.list.GetItemData(index)
1664 self.list.SetItemTextColour(index, wx.RED)
1669 self.list.ResizeColumns()
1673 coord_file = utils.GetTempfile()
1674 newreg = {
'n' : 0.0,
's' : 0.0,
'e' : 0.0,
'w' : 0.0,}
1677 f = open(coord_file, mode=
'w')
1679 f.write(str(region[
'e']) +
" " + str(region[
'n']) +
"\n")
1681 f.write(str(region[
'e']) +
" " + str(region[
's']) +
"\n")
1683 f.write(str(region[
'w']) +
" " + str(region[
'n']) +
"\n")
1685 f.write(str(region[
'w']) +
" " + str(region[
's']) +
"\n")
1702 self.grwiz.SwitchEnv(
'source')
1705 ret = gcmd.RunCommand(
'g.transform',
1711 coords = coord_file)
1713 elif map ==
'target':
1714 ret = gcmd.RunCommand(
'g.transform',
1721 coords = coord_file)
1723 os.unlink(coord_file)
1725 self.grwiz.SwitchEnv(
'target')
1728 errlist = ret.splitlines()
1731 message=_(
'Could not calculate new extends.\n'
1732 'Possible error with g.transform.'))
1736 e, n = errlist[0].
split()
1744 for i
in range(1, 4):
1745 e, n = errlist[i].
split()
1748 if fe < newreg[
'w']:
1750 if fe > newreg[
'e']:
1752 if fn < newreg[
's']:
1754 if fn > newreg[
'n']:
1760 """!Show GCP Manager manual page"""
1761 cmdlist = [
'g.manual',
'entry=wxGUI.GCP_Manager']
1762 self.parent.goutput.RunCmd(cmdlist, compReg=
False,
1767 if self.activemap.GetSelection() == 0:
1769 self.
Map = self.SrcMap
1772 self.
Map = self.TgtMap
1777 self.MapWindow.SetFocus()
1782 self.toolbars[
'gcpdisp'].Enable(
'zoomback', enable = (len(self.MapWindow.zoomhistory) > 1))
1784 if self.activemap.GetSelection() != (win == self.TgtMapWindow):
1785 self.activemap.SetSelection(win == self.TgtMapWindow)
1786 self.StatusbarUpdate()
1789 """!Adjust map window to new extents
1793 self.Map.region[
'n'] = newreg[
'n']
1794 self.Map.region[
's'] = newreg[
's']
1795 self.Map.region[
'e'] = newreg[
'e']
1796 self.Map.region[
'w'] = newreg[
'w']
1798 self.MapWindow.ZoomHistory(self.Map.region[
'n'], self.Map.region[
's'],
1799 self.Map.region[
'e'], self.Map.region[
'w'])
1802 if self.Map.projinfo[
'proj'] ==
'll':
1803 if newreg[
'n'] > 90.0:
1805 if newreg[
's'] < -90.0:
1808 ce = newreg[
'w'] + (newreg[
'e'] - newreg[
'w']) / 2
1809 cn = newreg[
's'] + (newreg[
'n'] - newreg[
's']) / 2
1812 self.Map.region[
'center_easting'] = ce
1813 self.Map.region[
'center_northing'] = cn
1814 self.Map.region[
"ewres"] = (newreg[
'e'] - newreg[
'w']) / self.Map.width
1815 self.Map.region[
"nsres"] = (newreg[
'n'] - newreg[
's']) / self.Map.height
1816 self.Map.AlignExtentFromDisplay()
1818 self.MapWindow.ZoomHistory(self.Map.region[
'n'], self.Map.region[
's'],
1819 self.Map.region[
'e'], self.Map.region[
'w'])
1821 if self.MapWindow.redrawAll
is False:
1822 self.MapWindow.redrawAll =
True
1824 self.MapWindow.UpdateMap()
1825 self.StatusbarUpdate()
1828 """!Set target map window to match extents of source map window
1831 if not self.
MapWindow == self.TgtMapWindow:
1833 self.
Map = self.TgtMap
1837 newreg = self.
GetNewExtent(self.SrcMap.region,
'source')
1842 """!Set source map window to match extents of target map window
1845 if not self.
MapWindow == self.SrcMapWindow:
1847 self.
Map = self.SrcMap
1851 newreg = self.
GetNewExtent(self.TgtMap.region,
'target')
1858 point = wx.GetMousePosition()
1859 zoommenu = wx.Menu()
1862 zoomsource = wx.MenuItem(zoommenu, wx.ID_ANY, _(
'Adjust source display to target display'))
1863 zoommenu.AppendItem(zoomsource)
1866 zoomtarget = wx.MenuItem(zoommenu, wx.ID_ANY, _(
'Adjust target display to source display'))
1867 zoommenu.AppendItem(zoomtarget)
1872 self.PopupMenu(zoommenu)
1876 """!GCP Map Display resized, adjust Map Windows
1878 if self.toolbars[
'gcpdisp']:
1879 srcwidth, srcheight = self.SrcMapWindow.GetSize()
1880 tgtwidth, tgtheight = self.TgtMapWindow.GetSize()
1881 srcwidth = (srcwidth + tgtwidth) / 2
1882 self._mgr.GetPane(
"target").Hide()
1884 self._mgr.GetPane(
"source").BestSize((srcwidth, srcheight))
1885 self._mgr.GetPane(
"target").BestSize((srcwidth, tgtheight))
1887 self._mgr.GetPane(
"target").Show()
1893 ListCtrlAutoWidthMixin):
1895 def __init__(self, parent, gcp, id=wx.ID_ANY,
1896 pos=wx.DefaultPosition, size=wx.DefaultSize,
1897 style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_HRULES |
1900 wx.ListCtrl.__init__(self, parent, id, pos, size, style)
1906 CheckListCtrlMixin.__init__(self)
1907 ListCtrlAutoWidthMixin.__init__(self)
1917 self.Bind(wx.EVT_LIST_COL_CLICK, self.
OnColClick)
1927 for col
in (_(
'use'),
1933 _(
'Backward error')):
1934 self.InsertColumn(idx_col, col)
1938 info = wx.ListItem()
1939 info.SetMask(wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT)
1941 info.m_format = wx.LIST_FORMAT_LEFT
1944 for lbl
in (_(
'use'),
1950 _(
'Backward error')):
1952 self.InsertColumnInfo(idx_col, info)
1956 """!Load data into list"""
1957 self.DeleteAllItems()
1960 if os.path.isfile(self.gcp.file[
'points']):
1965 self.gcp.AddGCP(
None)
1971 wx.LIST_STATE_SELECTED,
1972 wx.LIST_STATE_SELECTED)
1978 """!Item is checked/unchecked"""
1982 sourceMapWin = self.gcp.SrcMapWindow
1983 sourceMapWin.UpdateMap(render=
False, renderVector=
False)
1984 if self.gcp.show_target:
1985 targetMapWin = self.gcp.TgtMapWindow
1986 targetMapWin.UpdateMap(render=
False, renderVector=
False)
1992 Appends an item to GCP list
2004 self.
selected = self.GetItemCount() - 1
2008 wx.LIST_STATE_SELECTED,
2009 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:
2077 message=_(
"Invalid coordinate value. Operation cancelled."))
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)
2139 utils.ListSortLower(vectlist)
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)
2400 rmsgridSizer.AddGrowableCol(1)
2404 label=_(
"Highlight highest RMS error only"))
2405 hh = UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'highestonly')
2406 self.highlighthighest.SetValue(hh)
2407 rmsgridSizer.Add(item=self.
highlighthighest, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
2410 rmslabel = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Highlight RMS error > M + SD * factor:"))
2411 rmslabel.SetToolTip(wx.ToolTip(_(
"Highlight GCPs with an RMS error larger than \n"
2412 "mean + standard deviation * given factor. \n"
2413 "Recommended values for this factor are between 1 and 2.")))
2414 rmsgridSizer.Add(item=rmslabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
2415 sdfactor = UserSettings.Get(group=
'gcpman', key=
'rms', subkey=
'sdfactor')
2416 self.
rmsWin = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
2417 size=(70,-1), style=wx.TE_NOHIDESEL)
2418 self.rmsWin.SetValue(
"%s" % str(sdfactor))
2419 if (self.parent.highest_only ==
True):
2420 self.rmsWin.Disable()
2422 self.
symbol[
'sdfactor'] = self.rmsWin.GetId()
2423 rmsgridSizer.Add(item=self.
rmsWin, flag=wx.ALIGN_RIGHT, pos=(1, 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)
2430 gridSizer.AddGrowableCol(1)
2436 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color:"))
2437 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2438 col = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'color')
2439 colWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2440 colour=wx.Colour(col[0],
2444 self.
symbol[
'color'] = colWin.GetId()
2445 gridSizer.Add(item=colWin,
2446 flag=wx.ALIGN_RIGHT,
2453 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for high RMS error:"))
2454 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2455 hcol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'hcolor')
2456 hcolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2457 colour=wx.Colour(hcol[0],
2461 self.
symbol[
'hcolor'] = hcolWin.GetId()
2462 gridSizer.Add(item=hcolWin,
2463 flag=wx.ALIGN_RIGHT,
2470 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for selected GCP:"))
2471 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2472 scol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'scolor')
2473 scolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2474 colour=wx.Colour(scol[0],
2478 self.
symbol[
'scolor'] = scolWin.GetId()
2479 gridSizer.Add(item=scolWin,
2480 flag=wx.ALIGN_RIGHT,
2487 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Color for unused GCPs:"))
2488 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2489 ucol = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'ucolor')
2490 ucolWin = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
2491 colour=wx.Colour(ucol[0],
2495 self.
symbol[
'ucolor'] = ucolWin.GetId()
2496 gridSizer.Add(item=ucolWin,
2497 flag=wx.ALIGN_RIGHT,
2503 label=_(
"Show unused GCPs"))
2504 shuu = UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'unused')
2505 self.showunused.SetValue(shuu)
2506 gridSizer.Add(item=self.
showunused, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2512 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Symbol size:"))
2513 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2514 symsize = int(UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'size'))
2515 sizeWin = wx.SpinCtrl(parent=panel, id=wx.ID_ANY,
2517 sizeWin.SetValue(symsize)
2518 self.
symbol[
'size'] = sizeWin.GetId()
2519 gridSizer.Add(item=sizeWin,
2520 flag=wx.ALIGN_RIGHT,
2527 label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
"Line width:"))
2528 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
2529 width = int(UserSettings.Get(group=
'gcpman', key=
'symbol', subkey=
'width'))
2530 widWin = wx.SpinCtrl(parent=panel, id=wx.ID_ANY,
2532 widWin.SetValue(width)
2533 self.
symbol[
'width'] = widWin.GetId()
2534 gridSizer.Add(item=widWin,
2535 flag=wx.ALIGN_RIGHT,
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.AddGrowableCol(1)
2600 gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
'Select interpolation method:')),
2601 pos=(0,0), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
2604 gridSizer.Add(item=self.
grmethod, pos=(0,1),
2605 flag=wx.ALIGN_RIGHT, border=5)
2606 self.grmethod.SetStringSelection(self.parent.gr_method)
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(event.GetString())
2650 message=_(
'RMS threshold factor must be > 0'))
2653 message=_(
'RMS threshold factor is < 1\n'
2654 'Too many points might be highlighted'))
2657 """!Source map to display selected"""
2660 tmp_map = event.GetString()
2662 if not tmp_map ==
'' and not tmp_map == src_map:
2666 """!Target map to display selected"""
2669 tmp_map = event.GetString()
2671 if not tmp_map == tgt_map:
2675 self.parent.gr_method = self.
methods[event.GetSelection()]
2678 self.parent.clip_to_region = event.IsChecked()
2681 self.parent.extension = event.GetString()
2689 UserSettings.Set(group=
'gcpman', key=
'rms', subkey=
'highestonly',
2690 value=self.highlighthighest.GetValue())
2692 UserSettings.Set(group=
'gcpman', key=
'rms', subkey=
'sdfactor',
2695 self.parent.sdfactor = self.
sdfactor
2696 if self.parent.rmsthresh > 0:
2697 self.parent.rmsthresh = self.parent.mean + self.parent.sdfactor * self.parent.rmssd
2699 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'color',
2700 value=tuple(wx.FindWindowById(self.
symbol[
'color']).GetColour()))
2701 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'hcolor',
2702 value=tuple(wx.FindWindowById(self.
symbol[
'hcolor']).GetColour()))
2703 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'scolor',
2704 value=tuple(wx.FindWindowById(self.
symbol[
'scolor']).GetColour()))
2705 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'ucolor',
2706 value=tuple(wx.FindWindowById(self.
symbol[
'ucolor']).GetColour()))
2707 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'unused',
2708 value=self.showunused.GetValue())
2709 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'size',
2710 value=wx.FindWindowById(self.
symbol[
'size']).GetValue())
2711 UserSettings.Set(group=
'gcpman', key=
'symbol', subkey=
'width',
2712 value=wx.FindWindowById(self.
symbol[
'width']).GetValue())
2715 srcrenderVector =
False
2717 tgtrenderVector =
False
2720 layers = self.parent.grwiz.SrcMap.GetListOfLayers()
2721 self.parent.grwiz.SrcMap.DeleteLayer(layers[0])
2724 cmdlist = [
'd.rast',
'map=%s' % src_map]
2725 self.parent.grwiz.SwitchEnv(
'source')
2726 name, found = utils.GetLayerNameFromCmd(cmdlist),
2727 self.parent.grwiz.SrcMap.AddLayer(type=
'raster', command=cmdlist, l_active=
True,
2728 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
2730 self.parent.grwiz.SwitchEnv(
'target')
2735 layers = self.parent.grwiz.TgtMap.GetListOfLayers()
2737 self.parent.grwiz.TgtMap.DeleteLayer(layers[0])
2741 cmdlist = [
'd.rast',
'map=%s' % tgt_map]
2742 name, found = utils.GetLayerNameFromCmd(cmdlist)
2743 self.parent.grwiz.TgtMap.AddLayer(type=
'raster', command=cmdlist, l_active=
True,
2744 name=name, l_hidden=
False, l_opacity=1.0, l_render=
False)
2747 if self.parent.show_target ==
False:
2748 self.parent.show_target =
True
2749 self.parent._mgr.GetPane(
"target").Show()
2750 self.parent._mgr.Update()
2751 self.parent.toolbars[
'gcpdisp'].Enable(
'zoommenu', enable =
True)
2752 self.parent.activemap.Enable()
2753 self.parent.TgtMapWindow.ZoomToMap(layers = self.parent.TgtMap.GetListOfLayers())
2755 if self.parent.show_target ==
True:
2756 self.parent.show_target =
False
2757 self.parent._mgr.GetPane(
"target").Hide()
2758 self.parent._mgr.Update()
2759 self.parent.activemap.SetSelection(0)
2760 self.parent.activemap.Enable(
False)
2761 self.parent.toolbars[
'gcpdisp'].Enable(
'zoommenu', enable =
False)
2763 self.parent.UpdateColours(srcrender, srcrenderVector, tgtrender, tgtrenderVector)
2766 """!Button 'Save' pressed"""
2769 UserSettings.ReadSettingsFile(settings=fileSettings)
2770 fileSettings[
'gcpman'] = UserSettings.Get(group=
'gcpman')
2771 file = UserSettings.SaveToFile(fileSettings)
2772 self.parent.parent.goutput.WriteLog(_(
'GCP Manager settings saved to file \'%s\'.') % file)
2776 """!Button 'Apply' pressed"""
2781 """!Button 'Cancel' pressed"""