pythonlib.dox 4.9 KB

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