grasslib.dox 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*! \mainpage GRASS 7 Programmer's Manual
  2. <!-- * doxygenized from "GRASS 5 Programmer's Manual"
  3. by M. Neteler 2/2004
  4. * updated 8/2005, 2006, 2007, 2008
  5. -->
  6. <a href="http://grass.osgeo.org">GRASS GIS</a> (<b>Geographic
  7. Resources Analysis Support System</b>) is an open source, Free
  8. Software <em>Geographical Information System</em> (GIS) with raster,
  9. topological %vector, image processing, and graphics production
  10. functionality that operates on various platforms through a graphical
  11. user interface (GUI) or command line interface (CLI). It is released
  12. under GNU General Public License (GPL).
  13. This manual introduces the reader to the <i>Geographic Resources
  14. Analysis Support System</i> from the programming perspective. Design
  15. theory, system support libraries, system maintenance, and system
  16. enhancement are all presented. Standard GRASS 4.x conventions are
  17. still used in much of the code. This work is part of ongoing research
  18. being performed by the <a
  19. href="http://grass.osgeo.org/community/team.php">GRASS Development
  20. Team</a>, an international team of programmers, GRASS module authors
  21. are cited within their module's source code and the contributed manual
  22. pages.
  23. &copy; 2000-2009 GRASS Development Team<br> Published
  24. under GNU Free Documentation License (GFDL)
  25. http://www.fsf.org/copyleft/fdl.html
  26. This manual comes with ABSOLUTELY NO WARRANTY. The development of
  27. GRASS software and this manual is kindly supported by the <a
  28. href="http://www.osgeo.org">Open Source Geospatial Foundation</a>, who
  29. provides the GRASS main infrastructure.
  30. Main web site: <a
  31. href="http://grass.osgeo.org">http://grass.osgeo.org</a>
  32. <b>Table of contents</b>
  33. - \subpage corelibs
  34. - \subpage libs
  35. - \subpage interfaces
  36. - \subpage gui
  37. - \subpage location
  38. - \subpage Compiling_and_Installing_GRASS_Modules
  39. - \subpage Makefile_Variables
  40. - \subpage Constructing_a_Makefile
  41. - \subpage Multiple_Architecture_Conventions
  42. - \subpage vectmodules
  43. - \subpage vectmodules_oper
  44. <i>Missing entries below are either not yet uploaded to SVN (need to
  45. be migrated from GRASS 5 Programmer's manual) or are simply
  46. undocumented.</i>
  47. <!-- original:
  48. http://trac.osgeo.org/grass/browser/grass-web/trunk/images/grass7_arch.odp
  49. -->
  50. \image html "grass7_arch.png" "GRASS 7 Architecture"
  51. <p>
  52. <b>PLEASE UPDATE FOR GRASS 7</b>
  53. \section corelibs Principal library
  54. (the name refers to the directory name in lib/ in the source code)
  55. - gis: \ref gislib
  56. - raster: \ref rasterlib
  57. - vector: \ref vectorlib
  58. \section libs Further libraries
  59. (the name refers to the directory name in lib/ in the source code)
  60. - arraystats: Library of statistics for arrays of doubles - \ref arraystats (new, under development)
  61. - bitmap: Bitmap library for X Window Bitmaps - \ref bitmap
  62. - btree: Binary tree library - \ref btree
  63. - cairodriver: \ref cairodriver
  64. - cdhc: Library for testing normality and exponentiality - \ref cdhc
  65. - cluster: \ref clusterlib (image processing)
  66. - datetime: DateTime library - \ref datetime
  67. - db: \ref dbmilib
  68. - display: \ref displaylib
  69. - %driver: Graphics monitor driver
  70. - dspf: DSPF libary - \ref dspf (obsolete?)
  71. - edit: Raster edit library (cellhd, history, cats) - \ref edit
  72. - external: External libraries from other projects (such as shapelib) - \ref external
  73. - fonts: Hershey library - \ref fonts
  74. - g3d: \ref g3dlib
  75. - gmath: \ref gmathlib (generic mathematical functions and BLAS/LAPACK library wrapper)
  76. - gpde: \ref gpdelib (partial differential equations library)
  77. - imagery: \ref imagerylib
  78. - init: \ref init (GRASS initialization code + scripts)
  79. - linkm: Linked list memory manager - \ref linkm (obsolete?)
  80. - ogsf: \ref ogsflib (OpenGL (R) ported gsurf library (required for NVIZ))
  81. - pngdriver: PNG display driver library - \ref pngdriver
  82. - proj: \ref projlib (wrapper to PROJ4 projection library)
  83. - psdriver: PostScript display driver library - \ref psdriver
  84. - python: \ref pythonlib
  85. - raster: \ref rasterlib
  86. - rowio: \ref rowiolib
  87. - rst: Library for interpolation with regularized splines with tension - \ref rst
  88. - segment: \ref segmentlib (segment library for segmented raster reading)
  89. - sites: Old Sites library, now interfaced to \ref vectorlib - \ref sites
  90. - stats: Raster stats library - \ref stats
  91. - symbol: Drawing symbols for %point %vector data library - \ref symbol
  92. - vask: Cursor management library - \ref vask
  93. - %vector: \ref vectorlib (GRASS Vector and Direct Graph Library)
  94. - vedit: \ref veditlib - %vector editing
  95. - neta: \ref netalib
  96. - nviz: \ref nvizlib (used by wxGUI Nviz extension and CLI-based Nviz module)
  97. <!--<li>image3: extra imagery library (mainly still unused) - \ref image3lib-->
  98. <!--<li>D: display library - \ref d_displaylib-->
  99. <!--<li>front.end: interface for interactive modules library - \ref frontend-->
  100. \section interfaces Interfaces
  101. - GRASS <a href="http://download.osgeo.org/grass/grass7_progman/swig/">SWIG interface</a>
  102. - \ref pythonlib
  103. \section gui GUI
  104. - <a href="http://download.osgeo.org/grass/grass7_progman/gui/wxpython/">wxGUI</a></li>
  105. \section location File structure of GRASS Location
  106. A GRASS <b>raster map</b> consists of several files in several subdirectories in a mapset,
  107. organized as follows:
  108. - <b>cellhd/</b>:
  109. map header including projection code, coordinates representing
  110. the spatial extent of the raster map, number of rows and columns, resolution,
  111. and information about map compression;</li>
  112. - <b>cell/, fcell/ or grid3/</b>:
  113. generic matrix of values in a compressed, portable
  114. format which depends on the raster data type (integer, floating %point or 3D grid);</li>
  115. - <b>hist/</b>:
  116. history file which contains metadata such as the data source,
  117. the command that was used to generate the raster map, or
  118. other information provided by the user;</li>
  119. - <b>cats/</b>:
  120. optional category file which contains text or numeric labels assigned
  121. to the raster map categories;</li>
  122. - <b>colr/</b>:
  123. optional color table;</li>
  124. - <b>cell_misc/</b>:
  125. optional timestamp, range of values, quantization rules (for floating %point maps)
  126. and null (no-data) files; </li>
  127. A GRASS <b>%vector maps</b> are stored in several separate files in a
  128. single directory (see \ref vectorlib). While the
  129. attributes are stored in either a DBF file, a SQLite file or in an
  130. external DBMS (PostgreSQL, MySQL, ODBC), the geometric data are saved
  131. as follows:
  132. - <b>head</b>: %vector map ASCII header with information about the map creation
  133. (date and name), its scale and threshold;</li>
  134. - <b>coor</b>: binary geometry file which includes the coordinates of graphic
  135. elements (primitives) that define the %vector feature;</li>
  136. - <b>topo</b>: binary topology file describes the spatial relationships between the
  137. map's graphic elements;</li>
  138. - <b>hist</b>: history ASCII file with complete commands that were used to
  139. create the %vector map, as well as the name and date/time of the map
  140. creation;</li>
  141. - <b>cidx</b>: binary category index file which is used to %link the %vector
  142. object IDs to the attribute table rows;</li>
  143. - <b>dbln</b>: ASCII file which contains definition(s) of %link to attribute
  144. storage in database (DBMS).</li>
  145. <!-- original:
  146. http://trac.osgeo.org/grass/browser/grass-web/trunk/images/loc_struct.odg
  147. -->
  148. \image html "loc_struct.png" "Diagram of GRASS file structure"
  149. \section Compiling_and_Installing_GRASS_Modules Compiling and Installing GRASS Modules
  150. GRASS modules are compiled and installed using the UNIX <tt>make</tt>
  151. command, which reads a file named <tt>Makefile</tt> (see \ref
  152. Multiple_Architecture_Conventions for more information) and then runs
  153. the compiler. The GRASS compilation process allows for
  154. multiple-architecture compilation from a single copy of the source
  155. code (for instance, if the source code is NFS mounted to various
  156. machines with differing architectures). This chapter assumes that the
  157. programmer is familiar with <tt>make</tt> and its accompanying
  158. Makefile.
  159. \todo Explain ''auto-conf''
  160. \todo Include contents of SUBMITTING and INSTALL files from source code
  161. To compile enter following:
  162. \verbatim
  163. ./configure
  164. make
  165. make install
  166. \endverbatim
  167. Then the code will be compiled into "/usr/local/grass-7.x.y" directory. The start
  168. script "grass7x" will be placed into "/usr/local/bin/".
  169. Optionally other target directories can be specified while "configuring":
  170. \verbatim
  171. ./configure --prefix=/opt/grass-7.x.y --with-bindir=/usr/bin
  172. make
  173. make install
  174. \endverbatim
  175. This will store the GRASS binaries into the directory
  176. "/opt/grass-7.x.y" and the script mentioned above into "/usr/bin".
  177. The script "make" is required to compile single modules. The
  178. compilation process and requirements are discussed in more detail now.
  179. \subsection Makefile_Variables Makefile Variables
  180. \todo Update the list.
  181. <b>GRASS Libraries</b>. The following variables name the various GRASS
  182. libraries:
  183. - <i>GISLIB</i> - This names the <b>GIS Library</b>, which is the
  184. principal GRASS library. See \ref GIS_Library for details about this
  185. library, and \ref Loading_the_GIS_Library for a sample Makefile which
  186. loads this library.
  187. - <i>SEGMENTLIB</i> - This names the <b>Segment Library</b>, which
  188. manages large matrix data. See \ref Segment_Library for details about
  189. this library, and \ref Loading_the_Vask_Library for a sample
  190. <i>Makefile</i> which loads this library.
  191. - <i>RASTERLIB</i> - This names the <b>Raster Graphics Library</b>,
  192. which communicates with GRASS graphics drivers. See \ref
  193. Raster_Graphics_Library for details about this library, and \ref
  194. Loading_the_Raster_Graphics_Library for a sample <i>Makefile</i> which
  195. loads this library.
  196. - <i>DISPLAYLIB</i> - This names the <b>Display Graphics Library</b>,
  197. which provides a higher level graphics interface to
  198. <i>RASTERLIB</i>. See Display_Graphics_Library for details about this
  199. library, and Loading_the_Display_Graphics_Library for a sample
  200. <i>Makefile</i> which loads this library.
  201. <b>UNIX Libraries:</b> The following variables name some useful UNIX
  202. system libraries:
  203. - <i>MATHLIB</i> This names the math library. It should be used
  204. instead of the -lm loader option.
  205. - <i>CURSES</i> This names both the curses and termcap libraries. It
  206. should be used instead of the -lcurses/-lncurses and
  207. -ltermcap loader options. Do not use <tt>$CURSES</tt> if you use
  208. <tt>$VASK</tt>.
  209. - <i>TERMLIB</i> This names the termcap library. It should be used
  210. -instead of the ltermcap or -ltermlib loader options. Do not use
  211. -<tt>$TERMLIB</tt> if you use <tt>$VASK</tt> or <tt>$CURSES</tt>.
  212. <b>Compiler and loader variables.</b> The following variables are
  213. related to compiling and loading C programs:
  214. - <i>EXTRA\_CFLAGS</i> This variable can be used to add additional
  215. options to <tt>$CFLAGS</tt>. It has no predefined values. It is
  216. usually used to specify additional -I include directories, or -D
  217. preprocessor defines.
  218. \subsection Constructing_a_Makefile Constructing a Makefile
  219. The complete syntax for a <i>Makefile</i> is discussed in the UNIX
  220. documentation for <tt>make</tt> and will not be repeated here. The
  221. essential idea is that a target (e.g. a GRASS module) is to be built
  222. from a list of dependencies (e.g. object files, libraries, etc.). The
  223. relationship between the target, its dependencies, and the rules for
  224. constructing the target is expressed according to the following
  225. syntax:
  226. \code
  227. target: dependencies
  228. actions
  229. more actions
  230. \endcode
  231. If the target does not exist, or if any of the dependencies have a newer
  232. date than the target (i.e., have changed), the actions will be executed to
  233. build the target. The actions must be indented using a TAB. <tt>make</tt> is
  234. picky about this. It does not like spaces in place of the TAB.
  235. \section Multiple_Architecture_Conventions Multiple-Architecture Conventions
  236. The following conventions allow for multiple architecture compilation on a
  237. machine that uses a common or networked GRASS source code directory tree.
  238. Object files and library archives are compiled into subdirectories
  239. that represent the architecture that they were compiled on. These
  240. subdirectories are created in the $SRC directory as OBJ.<tt>arch</tt>
  241. and LIB.<tt>arch</tt>, where <tt>arch</tt> represents the architecture
  242. of the compiling machine. Thus, for example, $SRC/OBJ.sun4 would
  243. contain the object files for Sun/4 and SPARC architectures, and
  244. <tt>$SRC/LIB.686-pc-linux-gnu</tt> would contain library archives for
  245. Linux architectures. Likewise, <tt>$SRC/OBJ.686-pc-linux-gnu</tt>
  246. would contain the object files for Linux architectures, and
  247. <tt>$SRC/LIB.686-pc-linux-gnu</tt> would contain library archives for
  248. Linux architectures.
  249. Note that 'arch' is defined for a specific architecture during setup and
  250. compilation of GRASS, it is not limited to sun4 or any specific string.
  251. \section vectmodules Vector modules and their parameters/flags
  252. A module is a GRASS command invoked by the user.
  253. \subsection vectmodules_oper Modules operation
  254. Each module which modifies and writes data must read from
  255. <b>input=</b> and write to <b>output=</b> so that data may not be
  256. lost. For example <tt>v.spag</tt> works on <b>map=</b> at in GRASS GIS
  257. 5.0 but if program (system) crashes or threshold was specified
  258. incorrectly and vector was not backuped, data were lost. In this case
  259. </b>map=</b> option should be replaced by <b>input=</b> and
  260. <b>output=</b>.
  261. Topology is always built by default if the coor file was modified.
  262. Dimensionality is generally kept. Input 2D vector is written as 2D, 3D
  263. as 3D. There are a few modules which change the dimension on purpose.
  264. \subsection vectmodulesopt Modules parameters/flags
  265. <b>-b</b> do not build topo file; by default topo file is written
  266. <b>-t</b> create new table, default
  267. <b>-u</b> don't create new table
  268. <b>-z</b> write 3D vector map (if input was 2D)
  269. <b>map=</b> input vector map for modules without output
  270. <b>input=</b> input vector map
  271. <b>output=</b> output vector map
  272. <b>type=</b> type of elements: point,line,boundary,centroid,area
  273. <b>cat=</b> category or category list (example: 1,5,9-13,35)
  274. <b>layer=</b> layer number
  275. <b>where=</b> condition of SQL statement for selection of records
  276. <b>column=</b> column name (in external table)
  277. */