t.sample.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #% keyword: temporal
  19. #% keyword: sampling
  20. #% keyword: time
  21. #%end
  22. #%option G_OPT_STDS_INPUTS
  23. #%end
  24. #%option G_OPT_STDS_INPUT
  25. #% key: sample
  26. #% description: Name of the sample space time dataset
  27. #%end
  28. #%option G_OPT_STDS_TYPE
  29. #% key: intype
  30. #% guisection: Required
  31. #%end
  32. #%option G_OPT_STDS_TYPE
  33. #% key: samtype
  34. #% guisection: Required
  35. #% description: Type of the sample space time dataset
  36. #%end
  37. #%option G_OPT_T_SAMPLE
  38. #% key: method
  39. #% answer: during,overlap,contain,equal
  40. #%end
  41. #%option G_OPT_F_SEP
  42. #% description: Field separator between output columns, default is tabular " | "
  43. #% label: Do not use "," as this char is reserved to list several map ids in a sample granule
  44. #%end
  45. #%flag
  46. #% key: c
  47. #% description: Print the column names as first row
  48. #%end
  49. #%flag
  50. #% key: s
  51. #% description: Check spatial overlap
  52. #%end
  53. import grass.script as grass
  54. import grass.temporal as tgis
  55. ############################################################################
  56. def main():
  57. # Get the options
  58. inputs = options["inputs"]
  59. sampler = options["sample"]
  60. samtype = options["samtype"]
  61. intype = options["intype"]
  62. separator = grass.separator(options["separator"])
  63. method = options["method"]
  64. header = flags["c"]
  65. spatial = flags["s"]
  66. # Make sure the temporal database exists
  67. tgis.init()
  68. tgis.sample_stds_by_stds_topology(intype, samtype, inputs, sampler,
  69. header, separator, method, spatial,
  70. True)
  71. if __name__ == "__main__":
  72. options, flags = grass.parser()
  73. main()