pythonlib.dox 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*! \page pythonlib GRASS Python Scripting Library
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. \section pythonIntro 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. - setup.py
  14. - array.py
  15. <b>Table of content</b>
  16. - \subpage pythonScripting
  17. - \subpage pythonModules
  18. - \subpage pythonCore
  19. - \subpage pythonDb
  20. - \subpage pythonRaster
  21. - \subpage pythonVector
  22. - \subpage pythonSetup
  23. - \subpage pythonArray
  24. \section pythonScripting GRASS scripting tasks for Python provided by "grass.script"
  25. Statement
  26. \code
  27. import grass.script as grass
  28. \endcode
  29. imports core.py, db.py, raster.py and vector.py modules.
  30. To import only selected module
  31. \code
  32. from grass.script import core as grass
  33. \endcode
  34. Sample script
  35. \code
  36. #!/usr/bin/env python
  37. #%module
  38. #% description: Checks if vector map is 3D
  39. #% keywords: vector
  40. #%end
  41. #%option
  42. #% key: map
  43. #% type: string
  44. #% gisprompt: old,vector,vector
  45. #% key_desc: name
  46. #% description: Name of vector map
  47. #% required: yes
  48. #%end
  49. import sys
  50. import grass.script as grass
  51. def main():
  52. info = grass.vector_info_topo(map = options['map'])
  53. if info['map3d']:
  54. print 'Vector map is 3D'
  55. else:
  56. print 'Vector map is 2D'
  57. return 0
  58. if __name__ == "__main__":
  59. options, flags = grass.parser()
  60. sys.exit(main())
  61. \endcode
  62. \section pythonModules List of modules
  63. \subsection pythonCore Core
  64. <b>GRASS-oriented interface to subprocess module</b>
  65. - python::core::exec_command()
  66. - python::core::feed_command()
  67. - python::core::make_command()
  68. - python::core::parse_command()
  69. - python::core::pipe_command()
  70. - python::core::read_command()
  71. - python::core::run_command()
  72. - python::core::start_command()
  73. - python::core::write_command()
  74. <b>Interface to g.message</b>
  75. These all run g.message, differing only in which flag (if any) is
  76. used. fatal() is error(), but also calls sys.exit(1).
  77. - python::core::debug()
  78. - python::core::error()
  79. - python::core::fatal()
  80. - python::core::info()
  81. - python::core::message()
  82. - python::core::verbose()
  83. - python::core::warning()
  84. <b>Interface to g.parser</b>
  85. Interface to g.parser, intended to be run from the top-level, e.g.
  86. \code
  87. if __name__ == "__main__":
  88. options, flags = grass.parser()
  89. main()
  90. \endcode
  91. - python::core::parser()
  92. <b>Interface to g.tempfile</b>
  93. Returns the name of a temporary file, created with g.tempfile.
  94. - python::core::tempfile()
  95. <b>Key-value parsers</b>
  96. - python::core::parse_key_val()
  97. <b>Interface to g.gisenv</b>
  98. - python::core::gisenv()
  99. <b>Interface to g.region</b>
  100. - python::core::del_temp_region()
  101. - python::core::region()
  102. - python::core::use_temp_region()
  103. <b>Interface to g.findfile</b>
  104. - python::core::find_file()
  105. <b>Interface to g.list</b>
  106. - python::core::list_grouped()
  107. - python::core::list_pairs()
  108. - python::core::list_strings()
  109. - python::core::mlist_grouped()
  110. <b>Interface to g.mapsets</b>
  111. - python::core::mapsets()
  112. <b>Interface to g.version</b>
  113. - python::core::version()
  114. <b>Color parsing</b>
  115. - python::core::parse_color()
  116. <b>Check GRASS environment variables</b>
  117. - python::core::overwrite()
  118. - python::core::verbosity()
  119. <b>Various utilities, not specific to GRASS</b>
  120. - python::core::basename()
  121. - python::core::find_program()
  122. - python::core::try_remove()
  123. - python::core::try_rmdir()
  124. - python::core::float_or_dms()
  125. \section pythonDb Database
  126. Interface for <tt>db.*</tt> modules.
  127. - python::db::db_connection()
  128. - python::db::db_describe()
  129. - python::db::db_select()
  130. \section pythonRaster Raster
  131. Interface for <tt>r.*</tt> modules.
  132. - python::raster::raster_history()
  133. - python::raster::raster_info()
  134. - python::raster::mapcalc()
  135. \section pythonVector Vector
  136. Interface for <tt>v.*</tt> modules.
  137. - python::vector::vector_columns()
  138. - python::vector::vector_db()
  139. - python::vector::vector_db_select()
  140. - python::vector::vector_history()
  141. - python::vector::vector_info_topo()
  142. - python::vector::vector_layer_db()
  143. \section pythonSetup Setup
  144. \code
  145. from grass.script import setup as gsetup
  146. \endcode
  147. - python::setup::init()
  148. \section pythonArray Array
  149. \code
  150. from grass.script import array as garray
  151. \endcode
  152. - python::array::array
  153. \section pythonAuthors Authors
  154. Glynn Clements
  155. Martin Landa <landa.martin gmail.com>
  156. */