pythonlib.dox 4.6 KB

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