g.gui.iclass.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #% keywords: general
  25. #% keywords: user interface
  26. #% keywords: GUI
  27. #% keywords: classification
  28. #% keywords: supervised classification
  29. #% keywords: signatures
  30. #%end
  31. #%flag
  32. #% key: m
  33. #% description: Maximize window
  34. #%end
  35. #%option G_OPT_I_GROUP
  36. #% required: no
  37. #%end
  38. #%option G_OPT_I_SUBGROUP
  39. #% required: no
  40. #%end
  41. #%option G_OPT_R_MAP
  42. #% description: Name of raster map to load
  43. #% required: no
  44. #%end
  45. #%option G_OPT_V_MAP
  46. #% key: trainingmap
  47. #% label: Ground truth training map to load
  48. #% description:
  49. #% required: no
  50. #%end
  51. import os
  52. import wx
  53. import grass.script as grass
  54. from core.settings import UserSettings
  55. from core.globalvar import CheckWxVersion
  56. from core.giface import StandaloneGrassInterface
  57. from core.utils import _, GuiModuleMain
  58. from iclass.frame import IClassMapFrame
  59. def main():
  60. group_name = subgroup_name = map_name = trainingmap_name = None
  61. if options['group']:
  62. if not options['subgroup']:
  63. grass.fatal(_("Name of subgroup required"))
  64. group_name = grass.find_file(name = options['group'], element = 'group')['name']
  65. if not group_name:
  66. grass.fatal(_("Group <%s> not found") % options['group'])
  67. if options['subgroup'] not in grass.read_command('i.group', group = group_name, flags = 'sg').splitlines():
  68. grass.fatal(_("Subgroup <%s> not found") % options['subgroup'])
  69. subgroup_name = options['subgroup']
  70. if options['map']:
  71. map_name = grass.find_file(name = options['map'], element = 'cell')['fullname']
  72. if not map_name:
  73. grass.fatal(_("Raster map <%s> not found") % options['map'])
  74. if options['trainingmap']:
  75. trainingmap_name = grass.find_file(name = options['trainingmap'], element = 'vector')['fullname']
  76. if not trainingmap_name:
  77. grass.fatal(_("Vector map <%s> not found") % options['trainingmap'])
  78. # define display driver
  79. driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
  80. if driver == 'png':
  81. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  82. else:
  83. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  84. # launch application
  85. app = wx.App()
  86. if not CheckWxVersion([2, 9]):
  87. wx.InitAllImageHandlers()
  88. # show main frame
  89. giface = StandaloneGrassInterface()
  90. frame = IClassMapFrame(parent = None, giface = giface)
  91. if not flags['m']:
  92. frame.CenterOnScreen()
  93. if group_name:
  94. frame.SetGroup(group_name, subgroup_name)
  95. if map_name:
  96. giface.WriteLog(_("Loading raster map <%s>...") % map_name)
  97. frame.trainingMapManager.AddLayer(map_name)
  98. if trainingmap_name:
  99. giface.WriteLog(_("Loading training map <%s>...") % trainingmap_name)
  100. frame.ImportAreas(trainingmap_name)
  101. frame.Show()
  102. if flags['m']:
  103. frame.Maximize()
  104. app.MainLoop()
  105. if __name__ == '__main__':
  106. grass.set_raise_on_error(False)
  107. options, flags = grass.parser()
  108. GuiModuleMain(main)