pythonlib.dox 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. <b>Interface to \gmod{g.mapsets}</b>
  100. - python::script::core::mapsets()
  101. <b>Interface to \gmod{g.version}</b>
  102. - python::script::core::version()
  103. <b>Color parsing</b>
  104. - python::script::core::parse_color()
  105. <b>Check GRASS environment variables</b>
  106. - python::script::core::overwrite()
  107. - python::script::core::verbosity()
  108. <b>Create new GRASS location</b>
  109. - python::script::core::create_location()
  110. <b>Others</b>
  111. - python::script::core::find_program()
  112. \subsection pythonUtils Utils
  113. - python::script::utils::float_or_dms()
  114. - python::script::utils::separator()
  115. - python::script::utils::diff_files()
  116. - python::script::utils::try_remove()
  117. - python::script::utils::try_rmdir()
  118. - python::script::utils::basename()
  119. - python::script::utils::parse_key_val()
  120. - python::script::utils::decode()
  121. - python::script::utils::encode()
  122. \subsection pythonDb Database
  123. Interface for <tt>db.*</tt> modules.
  124. - python::script::db::db_connection()
  125. - python::script::db::db_describe()
  126. - python::script::db::db_select()
  127. \subsection pythonRaster Raster
  128. Interface for <tt>r.*</tt> modules.
  129. - python::script::raster::raster_history()
  130. - python::script::raster::raster_info()
  131. - python::script::raster::mapcalc()
  132. \subsection pythonVector Vector
  133. Interface for <tt>v.*</tt> modules.
  134. - python::script::vector::vector_columns()
  135. - python::script::vector::vector_db()
  136. - python::script::vector::vector_db_select()
  137. - python::script::vector::vector_history()
  138. - python::script::vector::vector_info_topo()
  139. - python::script::vector::vector_layer_db()
  140. \subsection pythonSetup Setup
  141. \code
  142. from grass.script import setup as gsetup
  143. \endcode
  144. - python::script::setup::init()
  145. \subsection pythonArray Array
  146. \code
  147. from grass.script import array as garray
  148. \endcode
  149. - python::script::array::array
  150. \section pythonAuthors Authors
  151. Glynn Clements
  152. Martin Landa <landa.martin gmail.com>
  153. */