pythonlib.dox 5.2 KB

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