pythonlib.dox 4.2 KB

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