g.gui.tplot.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 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: Allows the user to see in a plot the values of one or more temporal raser datasets for a queried point defined by a coordinate pair. Also allows to plot data of vector dataset for a defined categories and attribut.
  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. from core.giface import StandaloneGrassInterface
  66. def main():
  67. options, flags = gscript.parser()
  68. import wx
  69. from core.utils import _
  70. try:
  71. from tplot.frame import TplotFrame
  72. except ImportError as e:
  73. gscript.fatal(e.message)
  74. rasters = None
  75. if options['strds']:
  76. rasters = options['strds'].strip().split(',')
  77. vectors = None
  78. attr = None
  79. if options['stvds']:
  80. vectors = options['stvds'].strip().split(',')
  81. if not options['attr']:
  82. gscript.fatal(_("With stvds you have to use also 'attr' option"))
  83. else:
  84. attr = options['attr']
  85. coords = options['coordinates'].strip().split(',')
  86. output = options['output']
  87. app = wx.App()
  88. frame = TplotFrame(parent=None, giface=StandaloneGrassInterface())
  89. frame.SetDatasets(rasters, vectors, coords, None, attr)
  90. if output:
  91. frame.OnRedraw()
  92. if options['size']:
  93. sizes = options['size'].strip().split(',')
  94. sizes = [int(s) for s in sizes]
  95. frame.canvas.SetSize(sizes)
  96. if output.split('.')[-1].lower() == 'png':
  97. frame.canvas.print_png(output)
  98. if output.split('.')[-1].lower() in ['jpg', 'jpeg']:
  99. frame.canvas.print_jpg(output)
  100. if output.split('.')[-1].lower() in ['tif', 'tiff']:
  101. frame.canvas.print_tif(output)
  102. else:
  103. frame.Show()
  104. app.MainLoop()
  105. if __name__ == '__main__':
  106. main()