t.sample.py 2.2 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 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: Samples the input space time dataset(s) with a sample space time dataset and print the result to stdout.
  18. #% keywords: temporal
  19. #% keywords: sample
  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. #%end
  30. #%option G_OPT_STDS_TYPE
  31. #% key: samtype
  32. #% description: Type of the sample space time dataset
  33. #%end
  34. #%option G_OPT_T_SAMPLE
  35. #% key: method
  36. #% answer: during,overlap,contain,equal
  37. #%end
  38. #%option
  39. #% key: fs
  40. #% type: string
  41. #% description: Field separator character between the output columns, default is tabular " | ". Do not use "," as this char is reserved to list several map ids in a sample granule
  42. #% required: no
  43. #%end
  44. #%flag
  45. #% key: c
  46. #% description: Print column names
  47. #%end
  48. #%flag
  49. #% key: s
  50. #% description: Check spatial overlap to perform spatio-temporal sampling
  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 = options["fs"]
  62. method = options["method"]
  63. header = flags["c"]
  64. spatial = flags["s"]
  65. method = method.split(",")
  66. # Make sure the temporal database exists
  67. tgis.create_temporal_database()
  68. tgis.sample_stds_by_stds_topology(intype, samtype, inputs, sampler, header, separator, method, spatial)
  69. if __name__ == "__main__":
  70. options, flags = grass.parser()
  71. main()