g.gui.animation.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: Animation
  5. # AUTHOR(S): Anna Kratochvilova
  6. # PURPOSE: Tool for animating a series of GRASS raster and vector maps
  7. # or a space time raster dataset
  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. #% description: Tool for animating a series of raster and vector maps or a space time raster or vector dataset.
  23. #% keywords: general
  24. #% keywords: user interface
  25. #% keywords: GUI
  26. #% keywords: display
  27. #% keywords: animation
  28. #%end
  29. #%option G_OPT_R_INPUTS
  30. #% key: rast
  31. #% description: Raster maps to animate
  32. #% required: no
  33. #% guisection: Input
  34. #%end
  35. #%option G_OPT_V_INPUTS
  36. #% key: vect
  37. #% label: Vector maps to animate
  38. #% required: no
  39. #% guisection: Input
  40. #%end
  41. #%option G_OPT_STRDS_INPUT
  42. #% key: strds
  43. #% description: Space time raster dataset to animate
  44. #% required: no
  45. #% guisection: Input
  46. #%end
  47. #%option G_OPT_STVDS_INPUT
  48. #% key: stvds
  49. #% description: Space time vector dataset to animate
  50. #% required: no
  51. #% guisection: Input
  52. #%end
  53. import os
  54. import wx
  55. import grass.script as grass
  56. import grass.temporal as tgis
  57. from core.globalvar import CheckWxVersion
  58. from core.utils import _, GuiModuleMain
  59. from core.giface import StandaloneGrassInterface
  60. from core.layerlist import LayerList
  61. from animation.frame import AnimationFrame, MAX_COUNT
  62. from animation.data import AnimLayer
  63. def main():
  64. rast = options['rast']
  65. vect = options['vect']
  66. strds = options['strds']
  67. stvds = options['stvds']
  68. numInputs = 0
  69. if rast:
  70. numInputs += 1
  71. if vect:
  72. numInputs += 1
  73. if strds:
  74. numInputs += 1
  75. if stvds:
  76. numInputs += 1
  77. if numInputs > 1:
  78. grass.fatal(_("%s=, %s=, %s= and %s= are mutually exclusive.") %
  79. ("rast", "vect", "strds", "stvds"))
  80. if numInputs > 0:
  81. # We need to initialize the temporal framework in case
  82. # a space time dataset was set on the command line so that
  83. # the AnimLayer() class works correctly
  84. tgis.init()
  85. layerList = LayerList()
  86. if rast:
  87. layer = AnimLayer()
  88. layer.mapType = 'rast'
  89. layer.name = rast
  90. layer.cmd = ['d.rast', 'map={name}'.format(name=rast.split(',')[0])]
  91. layerList.AddLayer(layer)
  92. if vect:
  93. layer = AnimLayer()
  94. layer.mapType = 'vect'
  95. layer.name = vect
  96. layer.cmd = ['d.vect', 'map={name=}'.format(name=vect.split(',')[0])]
  97. layerList.AddLayer(layer)
  98. if strds:
  99. layer = AnimLayer()
  100. layer.mapType = 'strds'
  101. layer.name = strds
  102. layer.cmd = ['d.rast', 'map=']
  103. layerList.AddLayer(layer)
  104. if stvds:
  105. layer = AnimLayer()
  106. layer.mapType = 'stvds'
  107. layer.name = stvds
  108. layer.cmd = ['d.vect', 'map=']
  109. layerList.AddLayer(layer)
  110. app = wx.App()
  111. if not CheckWxVersion([2, 9]):
  112. wx.InitAllImageHandlers()
  113. frame = AnimationFrame(parent=None, giface=StandaloneGrassInterface())
  114. frame.CentreOnScreen()
  115. frame.Show()
  116. if len(layerList) >= 1:
  117. frame.SetAnimations([layerList] + [None] * (MAX_COUNT - 1))
  118. app.MainLoop()
  119. if __name__ == '__main__':
  120. options, flags = grass.parser()
  121. GuiModuleMain(main)