t.sample.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.sample
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: Sample the input space time dataset(s) with a sample space time dataset and print the result to stdout
  9. # COPYRIGHT: (C) 2011-2014, Soeren Gebbert and 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: Samples the input space time dataset(s) with a sample space time dataset and print the result to stdout.
  18. #% keywords: temporal
  19. #% keywords: sampling
  20. #%end
  21. #%option G_OPT_STDS_INPUTS
  22. #%end
  23. #%option G_OPT_STDS_INPUT
  24. #% key: sample
  25. #% description: Name of the sample space time dataset
  26. #%end
  27. #%option G_OPT_STDS_TYPE
  28. #% key: intype
  29. #% guisection: Required
  30. #%end
  31. #%option G_OPT_STDS_TYPE
  32. #% key: samtype
  33. #% guisection: Required
  34. #% description: Type of the sample space time dataset
  35. #%end
  36. #%option G_OPT_T_SAMPLE
  37. #% key: method
  38. #% answer: during,overlap,contain,equal
  39. #%end
  40. #%option G_OPT_F_SEP
  41. #% description: Field separator between output columns, default is tabular " | "
  42. #% label: Do not use "," as this char is reserved to list several map ids in a sample granule
  43. #%end
  44. #%flag
  45. #% key: c
  46. #% description: Print the column names as first row
  47. #%end
  48. #%flag
  49. #% key: s
  50. #% description: Check spatial overlap
  51. #%end
  52. import grass.script as grass
  53. import grass.temporal as tgis
  54. ############################################################################
  55. def main():
  56. # Get the options
  57. inputs = options["inputs"]
  58. sampler = options["sample"]
  59. samtype = options["samtype"]
  60. intype = options["intype"]
  61. separator = grass.separator(options["separator"])
  62. method = options["method"]
  63. header = flags["c"]
  64. spatial = flags["s"]
  65. # Make sure the temporal database exists
  66. tgis.init()
  67. tgis.sample_stds_by_stds_topology(intype, samtype, inputs, sampler,
  68. header, separator, method, spatial,
  69. True)
  70. if __name__ == "__main__":
  71. options, flags = grass.parser()
  72. main()