g.gui.iclass.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #%option G_OPT_I_GROUP
  31. #% required: no
  32. #%end
  33. #%option G_OPT_R_MAP
  34. #% description: Name of raster map to load
  35. #% required: no
  36. #%end
  37. import os
  38. import sys
  39. import wx
  40. import gettext
  41. import grass.script as grass
  42. if __name__ == '__main__':
  43. sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
  44. from core.settings import UserSettings
  45. from core.giface import StandaloneGrassInterface
  46. from iclass.frame import IClassMapFrame
  47. def main():
  48. group_name = map_name = None
  49. if options['group']:
  50. group_name = grass.find_file(name = options['group'], element = 'group')['name']
  51. if not group_name:
  52. grass.fatal(_("Group <%s> not found") % options['group'])
  53. if options['map']:
  54. map_name = grass.find_file(name = options['map'], element = 'cell')['fullname']
  55. if not map_name:
  56. grass.fatal(_("Raster map <%s> not found") % options['map'])
  57. # define display driver
  58. driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
  59. if driver == 'png':
  60. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  61. else:
  62. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  63. # launch application
  64. app = wx.PySimpleApp()
  65. wx.InitAllImageHandlers()
  66. # show main frame
  67. giface = StandaloneGrassInterface()
  68. frame = IClassMapFrame(parent = None, giface = giface)
  69. if group_name:
  70. frame.SetGroup(group_name)
  71. if map_name:
  72. giface.WriteLog(_("Loading raster map <%s>...") % map_name)
  73. frame.trainingMapManager.AddLayer(map_name)
  74. frame.Show()
  75. app.MainLoop()
  76. if __name__ == '__main__':
  77. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  78. grass.set_raise_on_error(False)
  79. options, flags = grass.parser()
  80. main()