grasspythonlib.dox 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*! \page pythonlib GRASS Python scripting library
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. \section intro Introduction
  4. The code in <tt>lib/python/</tt> provides <b>grass.script</b> in order
  5. to support GRASS scripts written in Python. The <tt>scripts/</tt>
  6. directory of GRASS contains a series of examples actually provided to
  7. the end users.
  8. See code in:
  9. - core.py
  10. - db.py
  11. - raster.py
  12. - vector.py
  13. <b>Table of content</b>
  14. - \subpage scripting
  15. - \subpage modules
  16. - \subpage core
  17. - \subpage db
  18. - \subpage raster
  19. - \subpage vector
  20. \section scripting GRASS scripting tasks for Python provided by "grass.script"
  21. Usage:
  22. \code
  23. import grass.script as grass
  24. \endcode
  25. or just import selected module, e.g.
  26. \code
  27. from grass.script import core as grass
  28. \endcode
  29. Sample script
  30. \code
  31. #!/usr/bin/env python
  32. #%Module
  33. #% description: Checks if vector map is 3D
  34. #% keywords: vector
  35. #%End
  36. #%option
  37. #% key: map
  38. #% type: string
  39. #% gisprompt: old,vector,vector
  40. #% key_desc: name
  41. #% description: Name of vector map
  42. #% required: yes
  43. #%end
  44. import sys
  45. import grass.script as grass
  46. def main():
  47. info = grass.parse_command('v.info',
  48. flags = 't',
  49. map = options['map'])
  50. if info['map3d'] == '1':
  51. print 'Vector map is 3D'
  52. else:
  53. print 'Vector map is 2D'
  54. return 0
  55. if __name__ == "__main__":
  56. options, flags = grass.parser()
  57. sys.exit(main())
  58. \endcode
  59. \section modules List of modules
  60. \subsection core Core
  61. <b>GRASS-oriented interface to subprocess module</b>
  62. - exec_command()
  63. - feed_command()
  64. - make_command()
  65. - parse_command()
  66. - pipe_command()
  67. - read_command()
  68. - run_command()
  69. - start_command()
  70. - write_command()
  71. <b>Interface to g.message</b>
  72. These all run g.message, differing only in which flag (if any) is
  73. used. fatal() is error(), but also calls sys.exit(1).
  74. - debug()
  75. - error()
  76. - fatal()
  77. - info()
  78. - message()
  79. - verbose()
  80. - warning()
  81. <b>Interface to g.parser</b>
  82. Interface to g.parser, intended to be run from the top-level, e.g.
  83. \code
  84. if __name__ == "__main__":
  85. options, flags = grass.parser()
  86. main()
  87. \endcode
  88. - parser()
  89. <b>Interface to g.tempfile</b>
  90. Returns the name of a temporary file, created with g.tempfile.
  91. - tempfile()
  92. <b>Key-value parsers</b>
  93. - parse_key_val()
  94. <b>Interface to g.gisenv</b>
  95. - gisenv()
  96. <b>Interface to g.region</b>
  97. - del_temp_region()
  98. - region()
  99. - use_temp_region()
  100. <b>Interface to g.findfile</b>
  101. - find_file()
  102. <b>Interface to g.list</b>
  103. - list_grouped()
  104. - list_pairs()
  105. - list_strings()
  106. - mlist_grouped()
  107. <b>Color parsing</b>
  108. - parse_color()
  109. <b>Check GRASS environment variables</b>
  110. - overwrite()
  111. - verbosity()
  112. <b>Various utilities, not specific to GRASS</b>
  113. - basename()
  114. - find_program()
  115. - try_remove()
  116. - try_rmdir()
  117. - float_or_dms()
  118. \section db Database
  119. Interface for <tt>db.*</tt> modules.
  120. \code
  121. from grass.script import db as grass
  122. \endcode
  123. - db_connection()
  124. - db_describe()
  125. - db_select()
  126. \section raster Raster
  127. Interface for <tt>r.*</tt> modules.
  128. \code
  129. from grass.script import raster as grass
  130. \endcode
  131. - raster_history()
  132. - raster_info()
  133. - mapcalc()
  134. \section vector Vector
  135. Interface for <tt>v.*</tt> modules.
  136. \code
  137. from grass.script import vector as grass
  138. \endcode
  139. - vector_columns()
  140. - vector_db()
  141. - vector_db_select()
  142. - vector_history()
  143. - vector_info_topo()
  144. - vector_layer_db()
  145. */