g.gui.animation.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/usr/bin/env python3
  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. # % keyword: general
  24. # % keyword: GUI
  25. # % keyword: display
  26. # % keyword: animation
  27. # %end
  28. # %option G_OPT_R_INPUTS
  29. # % key: raster
  30. # % description: Raster maps to animate
  31. # % required: no
  32. # % guisection: Input
  33. # %end
  34. # %option G_OPT_V_INPUTS
  35. # % key: vector
  36. # % label: Vector maps to animate
  37. # % required: no
  38. # % guisection: Input
  39. # %end
  40. # %option G_OPT_STRDS_INPUT
  41. # % key: strds
  42. # % description: Space time raster dataset to animate
  43. # % required: no
  44. # % guisection: Input
  45. # %end
  46. # %option G_OPT_STVDS_INPUT
  47. # % key: stvds
  48. # % description: Space time vector dataset to animate
  49. # % required: no
  50. # % guisection: Input
  51. # %end
  52. import grass.script as gscript
  53. from grass.exceptions import FatalError
  54. def main():
  55. options, flags = gscript.parser()
  56. # import wx only after running parser
  57. # to avoid issues when only interface is needed
  58. import grass.temporal as tgis
  59. import wx
  60. from grass.script.setup import set_gui_path
  61. set_gui_path()
  62. from core.giface import StandaloneGrassInterface
  63. from core.layerlist import LayerList
  64. from animation.frame import AnimationFrame, MAX_COUNT
  65. from animation.data import AnimLayer
  66. rast = options["raster"]
  67. vect = options["vector"]
  68. strds = options["strds"]
  69. stvds = options["stvds"]
  70. numInputs = 0
  71. if rast:
  72. numInputs += 1
  73. if vect:
  74. numInputs += 1
  75. if strds:
  76. numInputs += 1
  77. if stvds:
  78. numInputs += 1
  79. if numInputs > 1:
  80. gscript.fatal(
  81. _("%s=, %s=, %s= and %s= are mutually exclusive.")
  82. % ("raster", "vector", "strds", "stvds")
  83. )
  84. if numInputs > 0:
  85. # We need to initialize the temporal framework in case
  86. # a space time dataset was set on the command line so that
  87. # the AnimLayer() class works correctly
  88. try:
  89. tgis.init()
  90. except FatalError as e:
  91. print(e)
  92. layerList = LayerList()
  93. if rast:
  94. layer = AnimLayer()
  95. layer.mapType = "raster"
  96. layer.name = rast
  97. layer.cmd = ["d.rast", "map={name}".format(name=rast.split(",")[0])]
  98. layerList.AddLayer(layer)
  99. if vect:
  100. layer = AnimLayer()
  101. layer.mapType = "vector"
  102. layer.name = vect
  103. layer.cmd = ["d.vect", "map={name}".format(name=vect.split(",")[0])]
  104. layerList.AddLayer(layer)
  105. if strds:
  106. layer = AnimLayer()
  107. layer.mapType = "strds"
  108. layer.name = strds
  109. layer.cmd = ["d.rast", "map="]
  110. layerList.AddLayer(layer)
  111. if stvds:
  112. layer = AnimLayer()
  113. layer.mapType = "stvds"
  114. layer.name = stvds
  115. layer.cmd = ["d.vect", "map="]
  116. layerList.AddLayer(layer)
  117. app = wx.App()
  118. frame = AnimationFrame(
  119. parent=None,
  120. giface=StandaloneGrassInterface(),
  121. title=_("Animation Tool - GRASS GIS"),
  122. )
  123. frame.CentreOnScreen()
  124. frame.Show()
  125. if len(layerList) >= 1:
  126. # CallAfter added since it was crashing with wxPython 3 gtk
  127. wx.CallAfter(frame.SetAnimations, [layerList] + [None] * (MAX_COUNT - 1))
  128. app.MainLoop()
  129. if __name__ == "__main__":
  130. main()