t.sample.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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-2017, Soeren Gebbert and the GRASS Development Team
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. #############################################################################
  22. #%module
  23. #% description: Samples the input space time dataset(s) with a sample space time dataset and print the result to stdout.
  24. #% keyword: temporal
  25. #% keyword: sampling
  26. #% keyword: time
  27. #%end
  28. #%option G_OPT_STDS_INPUTS
  29. #%end
  30. #%option G_OPT_STDS_INPUT
  31. #% key: sample
  32. #% description: Name of the sample space time dataset
  33. #%end
  34. #%option G_OPT_STDS_TYPE
  35. #% key: intype
  36. #% guisection: Required
  37. #%end
  38. #%option G_OPT_STDS_TYPE
  39. #% key: samtype
  40. #% guisection: Required
  41. #% description: Type of the sample space time dataset
  42. #%end
  43. #%option G_OPT_T_SAMPLE
  44. #% key: method
  45. #% answer: during,overlap,contain,equal
  46. #%end
  47. #%option G_OPT_F_SEP
  48. #% description: Field separator between output columns, default is tabular " | "
  49. #% label: Do not use "," as this char is reserved to list several map ids in a sample granule
  50. #%end
  51. #%flag
  52. #% key: c
  53. #% description: Print the column names as first row
  54. #%end
  55. #%flag
  56. #% key: s
  57. #% description: Check for spatial topological overlap
  58. #%end
  59. import grass.script as grass
  60. ############################################################################
  61. def main():
  62. # lazy imports
  63. import grass.temporal as tgis
  64. # Get the options
  65. inputs = options["inputs"]
  66. sampler = options["sample"]
  67. samtype = options["samtype"]
  68. intype = options["intype"]
  69. separator = grass.separator(options["separator"])
  70. method = options["method"]
  71. header = flags["c"]
  72. spatial = flags["s"]
  73. # Make sure the temporal database exists
  74. tgis.init()
  75. tgis.sample_stds_by_stds_topology(intype, samtype, inputs, sampler,
  76. header, separator, method, spatial,
  77. True)
  78. if __name__ == "__main__":
  79. options, flags = grass.parser()
  80. main()