t.sample.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 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: Sample the input space time dataset with a sample space time dataset and print the result to stdout
  18. #% keywords: dataset
  19. #% keywords: spacetime
  20. #% keywords: raster
  21. #% keywords: sample
  22. #%end
  23. #%option
  24. #% key: input
  25. #% type: string
  26. #% description: Name of a space time dataset
  27. #% required: yes
  28. #% multiple: no
  29. #%end
  30. #%option
  31. #% key: sample
  32. #% type: string
  33. #% description: Name of the sample space time dataset
  34. #% required: yes
  35. #% multiple: no
  36. #%end
  37. #%option
  38. #% key: intype
  39. #% type: string
  40. #% description: Type of the input space time dataset, default is space time raster dataset (strds)
  41. #% required: no
  42. #% options: strds, str3ds, stvds
  43. #% answer: strds
  44. #%end
  45. #%option
  46. #% key: samtype
  47. #% type: string
  48. #% description: Type of the sample space time dataset, default is space time raster dataset (strds)
  49. #% required: no
  50. #% options: strds, str3ds, stvds
  51. #% answer: strds
  52. #%end
  53. #%option
  54. #% key: method
  55. #% type: string
  56. #% description: The method to be used for sampling
  57. #% required: no
  58. #% multiple: yes
  59. #% options: start,during,overlap,contain,equal
  60. #% answer: during,overlap,contain,equal
  61. #%end
  62. #%option
  63. #% key: fs
  64. #% type: string
  65. #% description: The field separator character between the columns, default is tabular " | ". Do not use "," as this char is reserved to list several map ids in a sample granule
  66. #% required: no
  67. #%end
  68. #%flag
  69. #% key: h
  70. #% description: Print column names
  71. #%end
  72. import grass.script as grass
  73. import grass.temporal as tgis
  74. ############################################################################
  75. def main():
  76. # Get the options
  77. input = options["input"]
  78. sampler = options["sample"]
  79. samtype = options["samtype"]
  80. intype = options["intype"]
  81. separator = options["fs"]
  82. method = options["method"]
  83. header = flags["h"]
  84. method = method.split(",")
  85. # Make sure the temporal database exists
  86. tgis.create_temporal_database()
  87. tgis.sample_stds_by_stds_topology(intype, samtype, input, sampler, header, separator, method)
  88. if __name__ == "__main__":
  89. options, flags = grass.parser()
  90. main()