g.gui.iclass.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 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: gui
  26. #% keywords: imagery
  27. #% keywords: classification
  28. #% keywords: 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_R_MAP
  38. #% description: Name of raster map to load
  39. #% required: no
  40. #%end
  41. #%option G_OPT_V_MAP
  42. #% key: trainingmap
  43. #% label: Ground truth training map to load
  44. #% description:
  45. #% required: no
  46. #%end
  47. import os
  48. import sys
  49. import wx
  50. import gettext
  51. import grass.script as grass
  52. if __name__ == '__main__':
  53. sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
  54. from core.settings import UserSettings
  55. from core.giface import StandaloneGrassInterface
  56. from iclass.frame import IClassMapFrame
  57. def main():
  58. group_name = map_name = trainingmap_name = None
  59. if options['group']:
  60. group_name = grass.find_file(name = options['group'], element = 'group')['name']
  61. if not group_name:
  62. grass.fatal(_("Group <%s> not found") % options['group'])
  63. if options['map']:
  64. map_name = grass.find_file(name = options['map'], element = 'cell')['fullname']
  65. if not map_name:
  66. grass.fatal(_("Raster map <%s> not found") % options['map'])
  67. if options['trainingmap']:
  68. trainingmap_name = grass.find_file(name = options['trainingmap'], element = 'vector')['fullname']
  69. if not trainingmap_name:
  70. grass.fatal(_("Vector map <%s> not found") % options['trainingmap'])
  71. # define display driver
  72. driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
  73. if driver == 'png':
  74. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  75. else:
  76. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  77. # launch application
  78. app = wx.PySimpleApp()
  79. wx.InitAllImageHandlers()
  80. # show main frame
  81. giface = StandaloneGrassInterface()
  82. frame = IClassMapFrame(parent = None, giface = giface)
  83. if group_name:
  84. frame.SetGroup(group_name)
  85. if map_name:
  86. giface.WriteLog(_("Loading raster map <%s>...") % map_name)
  87. frame.trainingMapManager.AddLayer(map_name)
  88. if trainingmap_name:
  89. giface.WriteLog(_("Loading training map <%s>...") % trainingmap_name)
  90. frame.ImportAreas(trainingmap_name)
  91. if not flags['m']:
  92. frame.CenterOnScreen()
  93. frame.Show()
  94. if flags['m']:
  95. frame.Maximize()
  96. app.MainLoop()
  97. if __name__ == '__main__':
  98. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  99. grass.set_raise_on_error(False)
  100. options, flags = grass.parser()
  101. main()