pythonlib.dox 5.0 KB

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