g.gui.iclass.py 3.9 KB

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