t.rast.extract.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.rast.extract
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: Extract a subset of a space time raster dataset
  9. # COPYRIGHT: (C) 2011 by the GRASS Development Team
  10. #
  11. # This program is free software under the GNU General Public
  12. # License (version 2). Read the file COPYING that comes with GRASS
  13. # for details.
  14. #
  15. #############################################################################
  16. #%module
  17. #% description: Extracts a subset of a space time raster datasets.
  18. #% keywords: temporal
  19. #% keywords: extract
  20. #%end
  21. #%option G_OPT_STRDS_INPUT
  22. #%end
  23. #%option G_OPT_T_WHERE
  24. #%end
  25. #%option
  26. #% key: expression
  27. #% type: string
  28. #% description: r.mapcalc expression assigned to all extracted raster maps
  29. #% required: no
  30. #% multiple: no
  31. #%end
  32. #%option G_OPT_STRDS_OUTPUT
  33. #%end
  34. #%option
  35. #% key: base
  36. #% type: string
  37. #% description: The base name of the new created raster maps. This name will be extended with a numerical prefix
  38. #% required: no
  39. #% multiple: no
  40. #% gisprompt:
  41. #%end
  42. #%option
  43. #% key: nprocs
  44. #% type: integer
  45. #% description: Number of r.mapcalc processes to run in parallel
  46. #% required: no
  47. #% multiple: no
  48. #% answer: 1
  49. #%end
  50. #%flag
  51. #% key: n
  52. #% description: Register Null maps
  53. #%end
  54. import grass.script as grass
  55. import grass.temporal as tgis
  56. from multiprocessing import Process
  57. ############################################################################
  58. def main():
  59. # Get the options
  60. input = options["input"]
  61. output = options["output"]
  62. where = options["where"]
  63. expression = options["expression"]
  64. base = options["base"]
  65. nprocs = int(options["nprocs"])
  66. register_null = flags["n"]
  67. # Make sure the temporal database exists
  68. tgis.init()
  69. tgis.extract_dataset(input, output, "raster", where, expression,
  70. base, nprocs, register_null)
  71. ###############################################################################
  72. if __name__ == "__main__":
  73. options, flags = grass.parser()
  74. main()