forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.py
3584 lines (3040 loc) · 112 KB
/
manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
@package gcp.manager
@brief Georectification module for GRASS GIS. Includes ground control
point management and interactive point and click GCP creation
Classes:
- manager::GCPWizard
- manager::LocationPage
- manager::GroupPage
- manager::DispMapPage
- manager::GCPPanel
- manager::GCPDisplay
- manager::GCPList
- manager::VectGroup
- manager::EditGCP
- manager::GrSettingsDialog
(C) 2006-2014 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@author Original author Michael Barton
@author Original version improved by Martin Landa <landa.martin gmail.com>
@author Rewritten by Markus Metz redesign georectfier -> GCP Manage
@author Support for GraphicsSet added by Stepan Turek <stepan.turek seznam.cz> (2012)
"""
import os
import sys
import shutil
from copy import copy
import wx
from wx.lib.mixins.listctrl import ColumnSorterMixin, ListCtrlAutoWidthMixin
import wx.lib.colourselect as csel
from core import globalvar
if globalvar.wxPythonPhoenix:
from wx import adv as wiz
else:
from wx import wizard as wiz
import grass.script as grass
from core import utils
from core.render import Map
from gui_core.gselect import Select, LocationSelect, MapsetSelect
from gui_core.dialogs import GroupDialog
from gui_core.mapdisp import FrameMixin
from core.gcmd import RunCommand, GMessage, GError, GWarning
from core.settings import UserSettings
from gcp.mapdisplay import MapPanel
from core.giface import Notification
from gui_core.wrap import (
SpinCtrl,
Button,
StaticText,
StaticBox,
CheckListBox,
TextCtrl,
Menu,
ListCtrl,
BitmapFromImage,
CheckListCtrlMixin,
)
from location_wizard.wizard import GridBagSizerTitledPage as TitledPage
#
# global variables
#
global src_map
global tgt_map
global maptype
src_map = ""
tgt_map = {"raster": "", "vector": ""}
maptype = "raster"
def getSmallUpArrowImage():
stream = open(os.path.join(globalvar.IMGDIR, "small_up_arrow.png"), "rb")
try:
img = wx.Image(stream)
finally:
stream.close()
return img
def getSmallDnArrowImage():
stream = open(os.path.join(globalvar.IMGDIR, "small_down_arrow.png"), "rb")
try:
img = wx.Image(stream)
finally:
stream.close()
stream.close()
return img
class GCPWizard:
"""
Start wizard here and finish wizard here
"""
def __init__(self, parent, giface):
self.parent = parent # GMFrame
self._giface = giface
#
# get environmental variables
#
self.grassdatabase = grass.gisenv()["GISDBASE"]
#
# read original environment settings
#
self.target_gisrc = os.environ["GISRC"]
self.gisrc_dict = {}
try:
f = open(self.target_gisrc, "r")
for line in f.readlines():
line = line.replace("\n", "").strip()
if len(line) < 1:
continue
key, value = line.split(":", 1)
self.gisrc_dict[key.strip()] = value.strip()
finally:
f.close()
self.currentlocation = self.gisrc_dict["LOCATION_NAME"]
self.currentmapset = self.gisrc_dict["MAPSET"]
# location for xy map to georectify
self.newlocation = ""
# mapset for xy map to georectify
self.newmapset = ""
global maptype
global src_map
global tgt_map
# src_map = ''
# tgt_map = ''
maptype = "raster"
# GISRC file for source location/mapset of map(s) to georectify
self.source_gisrc = ""
self.src_maps = []
#
# define wizard pages
#
self.wizard = wiz.Wizard(
parent=parent, id=wx.ID_ANY, title=_("Setup for georectification")
)
self.startpage = LocationPage(self.wizard, self)
self.grouppage = GroupPage(self.wizard, self)
self.mappage = DispMapPage(self.wizard, self)
#
# set the initial order of the pages
#
self.startpage.SetNext(self.grouppage)
self.grouppage.SetPrev(self.startpage)
self.grouppage.SetNext(self.mappage)
self.mappage.SetPrev(self.grouppage)
#
# do pages layout
#
self.startpage.DoLayout()
self.grouppage.DoLayout()
self.mappage.DoLayout()
self.wizard.FitToPage(self.startpage)
# self.Bind(wx.EVT_CLOSE, self.Cleanup)
# self.parent.Bind(wx.EVT_ACTIVATE, self.OnGLMFocus)
success = False
#
# run wizard
#
if self.wizard.RunWizard(self.startpage):
success = self.OnWizFinished()
if not success:
GMessage(parent=self.parent, message=_("Georectifying setup canceled."))
self.Cleanup()
else:
GMessage(parent=self.parent, message=_("Georectifying setup canceled."))
self.Cleanup()
#
# start GCP display
#
if success:
# instance of render.Map to be associated with display
self.SwitchEnv("source")
self.SrcMap = Map(gisrc=self.source_gisrc)
self.SwitchEnv("target")
self.TgtMap = Map(gisrc=self.target_gisrc)
self.Map = self.SrcMap
#
# add layer to source map
#
if maptype == "raster":
rendertype = "raster"
cmdlist = ["d.rast", "map=%s" % src_map]
else: # -> vector layer
rendertype = "vector"
cmdlist = ["d.vect", "map=%s" % src_map]
self.SwitchEnv("source")
name, found = utils.GetLayerNameFromCmd(cmdlist)
self.SrcMap.AddLayer(
ltype=rendertype,
command=cmdlist,
active=True,
name=name,
hidden=False,
opacity=1.0,
render=False,
)
self.SwitchEnv("target")
web_service_layer = self.mappage.GetWebServiceLayers(name=tgt_map["raster"])
if tgt_map["raster"] and web_service_layer:
#
# add web service layer to target map
#
rendertype = web_service_layer["type"]
cmdlist = web_service_layer["cmd"]
name = tgt_map["raster"]
self.TgtMap.AddLayer(
ltype=rendertype,
command=cmdlist,
active=True,
name=name,
hidden=False,
opacity=1.0,
render=False,
)
elif tgt_map["raster"]:
#
# add raster layer to target map
#
rendertype = "raster"
cmdlist = ["d.rast", "map=%s" % tgt_map["raster"]]
name, found = utils.GetLayerNameFromCmd(cmdlist)
self.TgtMap.AddLayer(
ltype=rendertype,
command=cmdlist,
active=True,
name=name,
hidden=False,
opacity=1.0,
render=False,
)
if tgt_map["vector"]:
#
# add raster layer to target map
#
rendertype = "vector"
cmdlist = ["d.vect", "map=%s" % tgt_map["vector"]]
name, found = utils.GetLayerNameFromCmd(cmdlist)
self.TgtMap.AddLayer(
ltype=rendertype,
command=cmdlist,
active=True,
name=name,
hidden=False,
opacity=1.0,
render=False,
)
#
# start GCP Manager
#
# create superior Map Display frame
mapframe = wx.Frame(
parent=None,
id=wx.ID_ANY,
size=globalvar.MAP_WINDOW_SIZE,
style=wx.DEFAULT_FRAME_STYLE,
title=name,
)
# create GCP manager
gcpmgr = GCPDisplay(
parent=mapframe,
giface=self._giface,
grwiz=self,
id=wx.ID_ANY,
Map=self.SrcMap,
lmgr=self.parent,
title=name,
)
# load GCPs
gcpmgr.InitMapDisplay()
gcpmgr.CenterOnScreen()
gcpmgr.Show()
# need to update AUI here for wingrass
gcpmgr._mgr.Update()
else:
self.Cleanup()
def SetSrcEnv(self, location, mapset):
"""Create environment to use for location and mapset
that are the source of the file(s) to georectify
:param location: source location
:param mapset: source mapset
:return: False on error
:return: True on success
"""
self.newlocation = location
self.newmapset = mapset
# check to see if we are georectifying map in current working
# location/mapset
if (
self.newlocation == self.currentlocation
and self.newmapset == self.currentmapset
):
return False
self.gisrc_dict["LOCATION_NAME"] = location
self.gisrc_dict["MAPSET"] = mapset
self.source_gisrc = utils.GetTempfile()
try:
f = open(self.source_gisrc, mode="w")
for line in self.gisrc_dict.items():
f.write(line[0] + ": " + line[1] + "\n")
finally:
f.close()
return True
def SwitchEnv(self, grc):
"""
Switches between original working location/mapset and
location/mapset that is source of file(s) to georectify
"""
# check to see if we are georectifying map in current working
# location/mapset
if (
self.newlocation == self.currentlocation
and self.newmapset == self.currentmapset
):
return False
if grc == "target":
os.environ["GISRC"] = str(self.target_gisrc)
elif grc == "source":
os.environ["GISRC"] = str(self.source_gisrc)
return True
def OnWizFinished(self):
# self.Cleanup()
return True
def OnGLMFocus(self, event):
"""Layer Manager focus"""
# self.SwitchEnv('target')
event.Skip()
def Cleanup(self):
"""Return to current location and mapset"""
# here was also the cleaning of gcpmanagement from layer manager
# which is no longer needed
self.SwitchEnv("target")
self.wizard.Destroy()
class LocationPage(TitledPage):
"""
Set map type (raster or vector) to georectify and
select location/mapset of map(s) to georectify.
"""
def __init__(self, wizard, parent):
TitledPage.__init__(self, wizard, _("Select map type and location/mapset"))
self.parent = parent
self.grassdatabase = self.parent.grassdatabase
self.xylocation = ""
self.xymapset = ""
#
# layout
#
# map type
self.rb_maptype = wx.RadioBox(
parent=self,
id=wx.ID_ANY,
label=" %s " % _("Map type to georectify"),
choices=[_("raster"), _("vector")],
majorDimension=wx.RA_SPECIFY_COLS,
)
self.sizer.Add(
self.rb_maptype,
flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND,
border=5,
pos=(1, 1),
span=(1, 2),
)
# location
self.sizer.Add(
StaticText(parent=self, id=wx.ID_ANY, label=_("Select source location:")),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(2, 1),
)
self.cb_location = LocationSelect(parent=self, gisdbase=self.grassdatabase)
self.sizer.Add(
self.cb_location,
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(2, 2),
)
# mapset
self.sizer.Add(
StaticText(parent=self, id=wx.ID_ANY, label=_("Select source mapset:")),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(3, 1),
)
self.cb_mapset = MapsetSelect(
parent=self, gisdbase=self.grassdatabase, setItems=False
)
self.sizer.Add(
self.cb_mapset,
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(3, 2),
)
self.sizer.AddGrowableCol(2)
#
# bindings
#
self.Bind(wx.EVT_RADIOBOX, self.OnMaptype, self.rb_maptype)
self.Bind(wx.EVT_COMBOBOX, self.OnLocation, self.cb_location)
self.cb_mapset.Bind(wx.EVT_TEXT, self.OnMapset)
self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
# self.Bind(wx.EVT_CLOSE, self.parent.Cleanup)
def OnMaptype(self, event):
"""Change map type"""
global maptype
if event.GetInt() == 0:
maptype = "raster"
else:
maptype = "vector"
def OnLocation(self, event):
"""Sets source location for map(s) to georectify"""
self.xylocation = event.GetString()
# create a list of valid mapsets
tmplist = os.listdir(os.path.join(self.grassdatabase, self.xylocation))
self.mapsetList = []
for item in tmplist:
if os.path.isdir(
os.path.join(self.grassdatabase, self.xylocation, item)
) and os.path.exists(
os.path.join(self.grassdatabase, self.xylocation, item, "WIND")
):
if item != "PERMANENT":
self.mapsetList.append(item)
self.xymapset = "PERMANENT"
utils.ListSortLower(self.mapsetList)
self.mapsetList.insert(0, "PERMANENT")
self.cb_mapset.SetItems(self.mapsetList)
self.cb_mapset.SetStringSelection(self.xymapset)
if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnMapset(self, event):
"""Sets source mapset for map(s) to georectify"""
if self.xylocation == "":
GMessage(
_("You must select a valid location " "before selecting a mapset"),
parent=self,
)
return
self.xymapset = event.GetString()
if not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnPageChanging(self, event=None):
if event.GetDirection() and (self.xylocation == "" or self.xymapset == ""):
GMessage(
_(
"You must select a valid location "
"and mapset in order to continue"
),
parent=self,
)
event.Veto()
return
self.parent.SetSrcEnv(self.xylocation, self.xymapset)
def OnEnterPage(self, event=None):
if self.xylocation == "" or self.xymapset == "":
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
else:
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
class GroupPage(TitledPage):
"""
Set group to georectify. Create group if desired.
"""
def __init__(self, wizard, parent):
TitledPage.__init__(self, wizard, _("Select image/map group to georectify"))
self.parent = parent
self.grassdatabase = self.parent.grassdatabase
self.groupList = []
self.xylocation = ""
self.xymapset = ""
self.xygroup = ""
# default extension
self.extension = "_georect" + str(os.getpid())
#
# layout
#
# group
self.sizer.Add(
StaticText(parent=self, id=wx.ID_ANY, label=_("Select/create group:")),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(1, 1),
)
self.cb_group = wx.ComboBox(
parent=self,
id=wx.ID_ANY,
choices=self.groupList,
size=(350, -1),
style=wx.CB_DROPDOWN,
)
self.sizer.Add(
self.cb_group,
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(1, 2),
)
# create group
self.sizer.Add(
StaticText(
parent=self, id=wx.ID_ANY, label=_("Create group if none exists")
),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(2, 1),
)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
self.btn_mkgroup = Button(
parent=self, id=wx.ID_ANY, label=_("Create/edit group...")
)
self.btn_vgroup = Button(
parent=self, id=wx.ID_ANY, label=_("Add vector map to group...")
)
btnSizer.Add(self.btn_mkgroup, flag=wx.RIGHT, border=5)
btnSizer.Add(self.btn_vgroup, flag=wx.LEFT, border=5)
self.sizer.Add(
btnSizer,
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(2, 2),
)
# extension
self.sizer.Add(
StaticText(
parent=self, id=wx.ID_ANY, label=_("Extension for output maps:")
),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(3, 1),
)
self.ext_txt = TextCtrl(parent=self, id=wx.ID_ANY, value="", size=(350, -1))
self.ext_txt.SetValue(self.extension)
self.sizer.Add(
self.ext_txt,
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(3, 2),
)
self.sizer.AddGrowableCol(2)
#
# bindings
#
self.Bind(wx.EVT_COMBOBOX, self.OnGroup, self.cb_group)
self.Bind(wx.EVT_TEXT, self.OnExtension, self.ext_txt)
self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
self.Bind(wx.EVT_CLOSE, self.parent.Cleanup)
# hide vector group button by default
self.btn_vgroup.Hide()
def OnGroup(self, event):
self.xygroup = event.GetString()
def OnMkGroup(self, event):
"""Create new group in source location/mapset"""
if self.xygroup == "":
self.xygroup = self.cb_group.GetValue()
dlg = GroupDialog(parent=self, defaultGroup=self.xygroup)
dlg.DisableSubgroupEdit()
dlg.ShowModal()
gr, s = dlg.GetSelectedGroup()
if gr in dlg.GetExistGroups():
self.xygroup = gr
else:
gr = ""
dlg.Destroy()
self.OnEnterPage()
self.Update()
def OnVGroup(self, event):
"""Add vector maps to group"""
if self.xygroup == "":
self.xygroup = self.cb_group.GetValue()
vector_dir = os.path.join(
self.grassdatabase, self.xylocation, self.xymapset, "vector"
)
if os.path.exists(vector_dir):
dlg = VectGroup(
parent=self,
id=wx.ID_ANY,
grassdb=self.grassdatabase,
location=self.xylocation,
mapset=self.xymapset,
group=self.xygroup,
)
if dlg.ShowModal() != wx.ID_OK:
return
dlg.MakeVGroup()
self.OnEnterPage()
else:
GError(parent=self, message=_("No vector maps."))
def OnExtension(self, event):
self.extension = self.ext_txt.GetValue()
def OnPageChanging(self, event=None):
if event.GetDirection() and self.xygroup == "":
GMessage(
_("You must select a valid image/map " "group in order to continue"),
parent=self,
)
event.Veto()
return
if event.GetDirection() and self.extension == "":
GMessage(
_("You must enter an map name " "extension in order to continue"),
parent=self,
)
event.Veto()
return
def OnEnterPage(self, event=None):
global maptype
self.groupList = []
self.xylocation = self.parent.gisrc_dict["LOCATION_NAME"]
self.xymapset = self.parent.gisrc_dict["MAPSET"]
# create a list of groups in selected mapset
if os.path.isdir(
os.path.join(self.grassdatabase, self.xylocation, self.xymapset, "group")
):
tmplist = os.listdir(
os.path.join(
self.grassdatabase, self.xylocation, self.xymapset, "group"
)
)
for item in tmplist:
if os.path.isdir(
os.path.join(
self.grassdatabase,
self.xylocation,
self.xymapset,
"group",
item,
)
):
self.groupList.append(item)
if maptype == "raster":
self.btn_vgroup.Hide()
self.Bind(wx.EVT_BUTTON, self.OnMkGroup, self.btn_mkgroup)
elif maptype == "vector":
self.btn_vgroup.Show()
self.Bind(wx.EVT_BUTTON, self.OnMkGroup, self.btn_mkgroup)
self.Bind(wx.EVT_BUTTON, self.OnVGroup, self.btn_vgroup)
utils.ListSortLower(self.groupList)
self.cb_group.SetItems(self.groupList)
if len(self.groupList) > 0:
if self.xygroup and self.xygroup in self.groupList:
self.cb_group.SetStringSelection(self.xygroup)
else:
self.cb_group.SetSelection(0)
self.xygroup = self.groupList[0]
if self.xygroup == "" or self.extension == "":
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
else:
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
# switch to source
self.parent.SwitchEnv("source")
class DispMapPage(TitledPage):
"""
Select ungeoreferenced map to display for interactively
setting ground control points (GCPs).
"""
def __init__(self, wizard, parent):
TitledPage.__init__(
self,
wizard,
_("Select maps to display for ground control point (GCP) creation"),
)
self.parent = parent
global maptype
self.web_servc_lyrs_root_node_name = _("Map Display Web Service Layer(s)")
#
# layout
#
self.sizer.Add(
StaticText(
parent=self, id=wx.ID_ANY, label=_("Select source map to display:")
),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(1, 1),
)
self.srcselection = Select(
self,
id=wx.ID_ANY,
size=globalvar.DIALOG_GSELECT_SIZE,
type=maptype,
updateOnPopup=False,
)
self.sizer.Add(
self.srcselection,
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(1, 2),
)
self.sizer.Add(
StaticText(
parent=self,
id=wx.ID_ANY,
label=_("Select target raster map to display:"),
),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(2, 1),
)
self.tgtrastselection = Select(
self,
id=wx.ID_ANY,
size=globalvar.DIALOG_GSELECT_SIZE,
type="raster",
updateOnPopup=False,
extraItems=self.GetSelectTargetRasterExtraItems(),
)
self.sizer.Add(
self.tgtrastselection,
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(2, 2),
)
self.sizer.Add(
StaticText(
parent=self,
id=wx.ID_ANY,
label=_("Select target vector map to display:"),
),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(3, 1),
)
self.tgtvectselection = Select(
self,
id=wx.ID_ANY,
size=globalvar.DIALOG_GSELECT_SIZE,
type="vector",
updateOnPopup=False,
)
self.sizer.Add(
self.tgtvectselection,
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
border=5,
pos=(3, 2),
)
#
# bindings
#
self.srcselection.Bind(wx.EVT_TEXT, self.OnSrcSelection)
self.tgtrastselection.Bind(wx.EVT_TEXT, self.OnTgtRastSelection)
self.tgtvectselection.Bind(wx.EVT_TEXT, self.OnTgtVectSelection)
self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
self.Bind(wx.EVT_CLOSE, self.parent.Cleanup)
def OnSrcSelection(self, event):
"""Source map to display selected"""
global src_map
global maptype
src_map = self.srcselection.GetValue()
if src_map == "":
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
else:
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
try:
# set computational region to match selected map and zoom display
# to region
if maptype == "raster":
p = RunCommand("g.region", "raster=src_map")
elif maptype == "vector":
p = RunCommand("g.region", "vector=src_map")
if p.returncode == 0:
print("returncode = ", str(p.returncode))
self.parent.Map.region = self.parent.Map.GetRegion()
except:
pass
def OnTgtRastSelection(self, event):
"""Source map to display selected"""
global tgt_map
tgt_map["raster"] = self.tgtrastselection.GetValue()
def OnTgtVectSelection(self, event):
"""Source map to display selected"""
global tgt_map
tgt_map["vector"] = self.tgtvectselection.GetValue()
def OnPageChanging(self, event=None):
global src_map
global tgt_map
if event.GetDirection() and (src_map == ""):
GMessage(
_("You must select a source map " "in order to continue"), parent=self
)
event.Veto()
return
self.parent.SwitchEnv("target")
def OnEnterPage(self, event=None):
global maptype
global src_map
global tgt_map
self.srcselection.SetElementList(maptype)
if maptype == "raster":
ret = RunCommand(
"i.group",
parent=self,
read=True,
group=self.parent.grouppage.xygroup,
flags="g",
)
if ret:
self.parent.src_maps = ret.splitlines()
else:
GError(
parent=self,
message=_(
"No maps in selected group <%s>.\n"
"Please edit group or select another group."
)
% self.parent.grouppage.xygroup,
)
return
elif maptype == "vector":
grassdatabase = self.parent.grassdatabase
xylocation = self.parent.gisrc_dict["LOCATION_NAME"]
xymapset = self.parent.gisrc_dict["MAPSET"]
# make list of vectors to georectify from VREF
vgrpfile = os.path.join(
grassdatabase,
xylocation,
xymapset,
"group",
self.parent.grouppage.xygroup,
"VREF",
)
error_message = (
_(
"No maps in selected group <%s>.\n"
"Please edit group or select another group."
)
% self.parent.grouppage.xygroup
)
try:
with open(vgrpfile) as f:
for vect in f.readlines():
vect = vect.strip("\n")
if len(vect) < 1:
continue
self.parent.src_maps.append(vect)
except FileNotFoundError:
GError(parent=self, message=error_message, showTraceback=False)
return
if len(self.parent.src_maps) < 1:
GError(parent=self, message=error_message)
return
# filter out all maps not in group
self.srcselection.tcp.GetElementList(elements=self.parent.src_maps)
src_map = self.parent.src_maps[0]
self.srcselection.SetValue(src_map)
self.parent.SwitchEnv("target")
self.tgtrastselection.SetElementList("raster")