g.gui.iclass.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: g.gui.iclass
  5. # AUTHOR(S): Anna Kratochvilova, Vaclav Petras
  6. # PURPOSE: The Map Swipe is a wxGUI component which allows the user to
  7. # interactively compare two maps
  8. # COPYRIGHT: (C) 2012-2013 by Anna Kratochvilova, and the GRASS Development Team
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. ############################################################################
  21. #%module
  22. #% label: Tool for supervised classification of imagery data.
  23. #% description: Generates spectral signatures for an image by allowing the user to outline regions of interest.
  24. #% keyword: general
  25. #% keyword: GUI
  26. #% keyword: classification
  27. #% keyword: supervised classification
  28. #% keyword: signatures
  29. #%end
  30. #%flag
  31. #% key: m
  32. #% description: Maximize window
  33. #%end
  34. #%option G_OPT_I_GROUP
  35. #% required: no
  36. #%end
  37. #%option G_OPT_I_SUBGROUP
  38. #% required: no
  39. #%end
  40. #%option G_OPT_R_MAP
  41. #% description: Name of raster map to load
  42. #% required: no
  43. #%end
  44. #%option G_OPT_V_MAP
  45. #% key: trainingmap
  46. #% label: Ground truth training map to load
  47. #% description:
  48. #% required: no
  49. #%end
  50. import os
  51. import grass.script as gscript
  52. def main():
  53. gscript.set_raise_on_error(False)
  54. options, flags = gscript.parser()
  55. import wx
  56. from grass.script.setup import set_gui_path
  57. set_gui_path()
  58. from core.settings import UserSettings
  59. from core.globalvar import CheckWxVersion
  60. from core.giface import StandaloneGrassInterface
  61. from core.utils import _
  62. from iclass.frame import IClassMapFrame
  63. group_name = subgroup_name = map_name = trainingmap_name = None
  64. if options['group']:
  65. if not options['subgroup']:
  66. gscript.fatal(_("Name of subgroup required"))
  67. group_name = gscript.find_file(name=options['group'],
  68. element='group')['name']
  69. if not group_name:
  70. gscript.fatal(_("Group <%s> not found") % options['group'])
  71. subgroups = gscript.read_command('i.group',
  72. group=group_name,
  73. flags='sg').splitlines()
  74. if options['subgroup'] not in subgroups:
  75. gscript.fatal(_("Subgroup <%s> not found") % options['subgroup'])
  76. subgroup_name = options['subgroup']
  77. if options['map']:
  78. map_name = gscript.find_file(name=options['map'],
  79. element='cell')['fullname']
  80. if not map_name:
  81. gscript.fatal(_("Raster map <%s> not found") % options['map'])
  82. if options['trainingmap']:
  83. trainingmap_name = gscript.find_file(name=options['trainingmap'],
  84. element='vector')['fullname']
  85. if not trainingmap_name:
  86. gscript.fatal(
  87. _("Vector map <%s> not found") %
  88. options['trainingmap'])
  89. # define display driver
  90. driver = UserSettings.Get(group='display', key='driver', subkey='type')
  91. if driver == 'png':
  92. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  93. else:
  94. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  95. # launch application
  96. app = wx.App()
  97. if not CheckWxVersion([2, 9]):
  98. wx.InitAllImageHandlers()
  99. # show main frame
  100. giface = StandaloneGrassInterface()
  101. frame = IClassMapFrame(parent=None, giface=giface)
  102. if not flags['m']:
  103. frame.CenterOnScreen()
  104. if group_name:
  105. frame.SetGroup(group_name, subgroup_name)
  106. if map_name:
  107. giface.WriteLog(_("Loading raster map <%s>...") % map_name)
  108. frame.trainingMapManager.AddLayer(map_name)
  109. if trainingmap_name:
  110. giface.WriteLog(_("Loading training map <%s>...") % trainingmap_name)
  111. frame.ImportAreas(trainingmap_name)
  112. frame.Show()
  113. if flags['m']:
  114. frame.Maximize()
  115. app.MainLoop()
  116. if __name__ == '__main__':
  117. main()