g.gui.tplot.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: g.gui.tplot.py
  5. # AUTHOR(S): Luca Delucchi
  6. # PURPOSE: Temporal Plot Tool is a wxGUI component (based on matplotlib)
  7. # the user to see in a plot the values of one or more temporal
  8. # datasets for a queried point defined by a coordinate pair.
  9. # COPYRIGHT: (C) 2014-2015 by Luca Delucchi, and the GRASS Development Team
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. ############################################################################
  22. #%module
  23. #% description: Plots the values of temporal datasets.
  24. #% keywords: general
  25. #% keywords: GUI
  26. #% keywords: temporal
  27. #%end
  28. #%option G_OPT_STVDS_INPUTS
  29. #% key: stvds
  30. #% required: no
  31. #%end
  32. #%option G_OPT_STRDS_INPUTS
  33. #% key: strds
  34. #% required: no
  35. #%end
  36. #%option G_OPT_M_COORDS
  37. #% required: no
  38. #%end
  39. # TODO use option G_OPT_V_CATS
  40. #%option
  41. #% key: cats
  42. #% label: Categories of vectores features
  43. #% description: To use only with stvds
  44. #% required: no
  45. #%end
  46. #%option
  47. #% key: attr
  48. #% label: Name of attribute
  49. #% description: Name of attribute which represent data for plotting
  50. #% required: no
  51. #%end
  52. #%option G_OPT_F_OUTPUT
  53. #% required: no
  54. #% label: Name for output file
  55. #% description: Add extension to specify format (.png, .pdf, .svg)
  56. #%end
  57. #%option
  58. #% key: size
  59. #% type: string
  60. #% label: The size for output image
  61. #% description: It works only with output parameter
  62. #% required: no
  63. #%end
  64. import grass.script as gscript
  65. def main():
  66. options, flags = gscript.parser()
  67. import wx
  68. from grass.script.setup import set_gui_path
  69. set_gui_path()
  70. from core.utils import _
  71. from core.giface import StandaloneGrassInterface
  72. try:
  73. from tplot.frame import TplotFrame
  74. except ImportError as e:
  75. gscript.fatal(e.message)
  76. rasters = None
  77. if options['strds']:
  78. rasters = options['strds'].strip().split(',')
  79. coords = None
  80. if options['coordinates']:
  81. coords = options['coordinates'].strip().split(',')
  82. cats = None
  83. if options['cats']:
  84. cats = options['cats']
  85. output = options['output']
  86. vectors = None
  87. attr = None
  88. if options['stvds']:
  89. vectors = options['stvds'].strip().split(',')
  90. if not options['attr']:
  91. gscript.fatal(_("With stvds you have to set 'attr' option"))
  92. else:
  93. attr = options['attr']
  94. if coords and cats:
  95. gscript.fatal(_("With stvds it is not possible to use 'coordinates' "
  96. "and 'cats' options together"))
  97. elif not coords and not cats:
  98. gscript.warning(_("With stvds you have to use 'coordinates' or "
  99. "'cats' option"))
  100. app = wx.App()
  101. frame = TplotFrame(parent=None, giface=StandaloneGrassInterface())
  102. frame.SetDatasets(rasters, vectors, coords, cats, attr)
  103. if output:
  104. frame.OnRedraw()
  105. if options['size']:
  106. sizes = options['size'].strip().split(',')
  107. sizes = [int(s) for s in sizes]
  108. frame.canvas.SetSize(sizes)
  109. frame.canvas.figure.savefig(output)
  110. else:
  111. frame.Show()
  112. app.MainLoop()
  113. if __name__ == '__main__':
  114. main()