vectorlib_files.dox 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*! \page vlibFormat Vector format description
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. \tableofcontents
  4. \par Table of contents
  5. - \ref vlibDirectoryStructure
  6. - \ref vlibDblnFileFormat
  7. - \ref vlibCoorFileFormat
  8. - \ref vlibCoorFileHead
  9. - \ref vlibCoorFileBody
  10. \section vlibDirectoryStructure Directory structure
  11. Vector map is stored in a number of data files. Vector map directory
  12. structure and file names were changed in GRASS 6 with respect to
  13. previous GRASS versions. All vector files for one vector map are
  14. stored in one directory:
  15. \verbatim
  16. $MAPSET/vector/vector_name/
  17. \endverbatim
  18. This directory contains these files:
  19. - <b>coor</b> - binary file, coordinates [former dig/ file] (see \ref vlibCoorFileFormat)
  20. - <b>topo</b> - binary file, topology [former dig_plus/ file] (see \ref vlibTopoFileFormat)
  21. - <b>sidx</b> - binary file, spatial index (see \ref vlibSidxFileFormat)
  22. - <b>cidx</b> - binary file, category index (see \ref vlibCidxFileFormat)
  23. - <b>head</b> - text file, header information [former part of dig/ file] (see \ref vlibHeadFileFormat)
  24. - <b>dbln</b> - text file, link(s) to attribute table(s) (see \ref vlibDblnFileFormat)
  25. - <b>hist</b> - text file, vector map change history
  26. - <b>frmt</b> - text file, format description (external formats only)
  27. - <b>fidx</b> - binary file, feature index (OGR format only)
  28. \section vlibHeadFileFormat Header file format specification
  29. The header contains meta information, a description of the
  30. vector map and many other information. The file is an unordered list
  31. of key/value entries. The <i>key</i> is a string separated from
  32. <i>value</i> by a colon and optional whitespace.
  33. Keywords are:
  34. - ORGANIZATION - organization that digitized the data
  35. - DIGIT DATE - date the data was digitized
  36. - DIGIT NAME - person who digitized the data
  37. - MAP NAME - title of the original source map
  38. - MAP DATE - date of the original source map
  39. - MAP SCALE - scale of the original source map
  40. - OTHER INFO - other comments about the map
  41. - ZONE - zone of the map (e.g., UTM zone)
  42. - MAP THRESH - digitizing threshold
  43. This information holds \ref dig_head data structure.
  44. \section vlibDblnFileFormat DB link file format specification
  45. Each vector maps has its own DBMI settings stored in the
  46. '$MAPSET/vector/vector_name/dbln' text file. For each pair <em>vector map +
  47. layer</em>, all of <em>table, key column, database, driver</em> must be
  48. defined in a new row. This definition must be written to
  49. '$MAPSET/vector/vector_name/dbln' text file. Each row in the 'dbln'
  50. file contains names separated by spaces in following order ([ ] -
  51. optional):
  52. \verbatim
  53. map[@mapset] layer table [key [database [driver]]]
  54. \endverbatim
  55. If key, database or driver are omitted (on second and higher row only)
  56. the last definition is used. When reading a vector map from another
  57. mapset (if mapset is specified along with map name), definitions in
  58. the related "dbln" file may overwrite the DBMI definition in the
  59. current mapset. This means that the map-wise definition is always
  60. "stronger".
  61. Wild cards <b>*</b> and <b>?</b> may be used in map and mapset names.
  62. Variables $GISDBASE, $LOCATION_NAME, $MAPSET, and $MAP may be used in
  63. table, key, database and driver names (function
  64. Vect_subst_var()). Note that $MAPSET is not the current mapset but
  65. mapset of the map the rule is defined for.
  66. Note that vector features in GRASS vector maps may have attributes in
  67. different tables or may be without attributes. Boundaries form areas
  68. but it may happen that some boundaries are not closed (such boundaries
  69. would not appear in polygon layer). Boundaries may have
  70. attributes. All types may be mixed in one vector map.
  71. The link to the table is permanent and it is stored in 'dbln' file in
  72. vector directory. Tables are considered to be a part of the vector and
  73. the command <tt>g.remove</tt>, for example, deletes linked tables of
  74. the vector. Attributes must be joined with geometry.
  75. Information about database links holds \ref dblinks data structure.
  76. <b>Examples:</b>
  77. Examples are written mostly for the DBF driver, where database is full
  78. path to the directory with dbf files and table name is the name of dbf
  79. file without .dbf extension:
  80. \verbatim
  81. * 1 mytable id $GISDBASE/$LOCATION_NAME/$MAPSET/vector/$MAP dbf
  82. \endverbatim
  83. This definition says that entities with category of layer 1 are linked
  84. to dbf tables with names "mytable.dbf" saved in vector directories of
  85. each map. The attribute column containing the category numbers is
  86. called "id".
  87. \verbatim
  88. * 1 $MAP id $GISDBASE/$LOCATION_NAME/$MAPSET/dbf dbf
  89. \endverbatim
  90. Similar as above but all dbf files are in one directory dbf/ in mapset
  91. and names of dbf files are $MAP.dbf
  92. \verbatim
  93. water* 1 rivers id /home/grass/dbf dbf
  94. water* 2 lakes lakeid /home/guser/mydb
  95. trans* 1 roads key basedb odbc
  96. trans* 5 rails
  97. \endverbatim
  98. These definitions define more layers (called "field" in the API) for
  99. one vector map i.e. in one vector map may be more features linked to
  100. more attribute tables. Definitions on first 2 rows are applied for
  101. example on maps water1, water2, ... so that more maps may share one
  102. table.
  103. \verbatim
  104. water@PERMANENT 1 myrivers id /home/guser/mydbf dbf
  105. \endverbatim
  106. This definion overwrites the definition saved in PERMANENT/VAR and
  107. links the water map from PERMANENT mapset to the user's table.
  108. Modules should be written so that connections to databases for each
  109. vector layer are independent. It should be possible to read attributes
  110. of an input vector map from one database and write to some other and
  111. even with some other driver (should not be a problem).
  112. There are open questions, however. For one, how does one distinguish when
  113. new tables should be written and when not? For example, definitions:
  114. \verbatim
  115. river 1 river id water odbc
  116. river.backup* 1 NONE
  117. \endverbatim
  118. could be used to say that tables should not be copied for backups of
  119. map river because table is stored in a reliable RDBMS.
  120. \section vlibs Vector libraries
  121. Besides internal library functions there are two main libraries:
  122. - Vlib (Vector library), see \ref vlibIntro
  123. - DGLib (Directed Graph Library), see \ref dglib
  124. For historical reasons, there are two internal libraries:
  125. - diglib (with dig_*() functions), GRASS 3.x/4.x
  126. - Vlib (with V1_*(), V2_*() and Vect_*() functions), since GRASS 4.x
  127. (except for the 5.7 interim version)
  128. The vector library was introduced in GRASS 4.0 to hide internal vector
  129. files' formats and structures. In GRASS 6/7, everything is accessed via
  130. Vect_*() functions, for example:
  131. Old 4.x code:
  132. \code
  133. xx = Map.Att[Map.Area[area_num].att].x;
  134. \endcode
  135. New 6.x/7.x functions:
  136. \code
  137. centroid = Vect_get_area_centroid(Map, area_num);
  138. Vect_read_line(Map, line_p, NULL, centroid);
  139. Vect_line_get_point(line_p, 0, &xx, NULL, NULL);
  140. \endcode
  141. In GRASS 6/7, all internal, mostly non-topological vector functions are
  142. hidden from the modules' API (mainly dig_*(), V1_*() and V2_*()
  143. functions). All available Vect_*() functions are topological vector
  144. functions.
  145. The following include file contains definitions and structures
  146. required by some of the routines in this library. The programmer
  147. should therefore include this file in any code that uses the vector
  148. library:
  149. \code
  150. #include <grass/vector.h>
  151. \endcode
  152. <i>Note: For details please read Blazek et al. 2002 (see below) as
  153. well as the references in this document.</i>
  154. \subsection vlibHistory Historical notes
  155. The vector library in GRASS 4.0 changed significantly from the
  156. <em>Digit Library</em> (diglib) used in GRASS 3.1. Below is an
  157. overview of why the changes were made.
  158. The Digit Library was a collage of subroutines created for developing
  159. the map development programs. Few of these subroutines were actually
  160. designed as a user access library. They required individuals to assume
  161. too much responsibility and control over what happened to the data
  162. file. Thus when it came time to change vector data file formats for
  163. GRASS 4.0, many modules also required modification. The two different
  164. access levels for 3.0 vector files provided very different ways of
  165. calling the library; they offered little consistency for the user.
  166. The Digit Library was originally designed to only have one file open
  167. for read or write at a time. Although it was possible in some cases to
  168. get around this, one restriction was the global head structure. Since
  169. there was only one instance of this, there could only be one copy of
  170. that information, and thus, only one open vector file.
  171. The solution to these problems was to design a new user library as an
  172. interface to the vector data files. This new library was designed to
  173. provide a simple consistent interface, which hides as much of the
  174. details of the data format as possible. It also could be extended for
  175. future enhancements without the need to change existing programs.
  176. The new vector library in GRASS 4 provided routines for opening,
  177. closing, reading, and writing vector files, as well as several support
  178. functions. The Digit Library has been replaced, so that all existing
  179. modules was converted to use the new library. Those routines that
  180. existed in the Digit Library and were not affected by these changes
  181. continue to exist in unmodified form, and were included in the vector
  182. library. Most of the commonly used routines have been discarded, and
  183. replaced by the new vector routines.
  184. Instead the global head structure was used own local version of
  185. it. The structure that replaced structure head is structure \ref
  186. dig_head. There were still two levels of interface to the vector files
  187. (future releases may include more). Level one provided access only to
  188. arc (i.e. polyline) information and to the type of line (AREA, LINE,
  189. DOT). Level two provided access to polygons (areas), attributes, and
  190. network topology.
  191. \subsection vlibCoorFileFormat Coor file format specification
  192. In the coor file the following is stored: 'line' (element) type,
  193. number of attributes and layer number for each category. Coordinates
  194. in binary file are stored as double (8 bytes). See \ref Coor_info data
  195. structure.
  196. \subsubsection vlibCoorFileHead Header
  197. <table border="1" style="border-collapse: collapse" cellpadding="5">
  198. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  199. <tr><td>Version_Major</td> <td>C</td> <td>1</td> <td>file version (major)</td></tr>
  200. <tr><td>Version_Minor</td> <td>C</td> <td>1</td> <td>file version (minor)</td></tr>
  201. <tr><td>Back_Major</td> <td>C</td> <td>1</td> <td>supported from GRASS version (major)</td></tr>
  202. <tr><td>Back_Minor</td> <td>C</td> <td>1</td> <td>supported from GRASS version (minor)</td></tr>
  203. <tr><td>byte_order</td> <td>C</td> <td>1</td> <td>little or big endian flag</td></tr>
  204. <tr><td>head_size</td> <td>L</td> <td>1</td> <td>header size of coor file</td></tr>
  205. <tr><td>with_z</td> <td>C</td> <td>1</td> <td>2D or 3D flag; zero for 2D</td></tr>
  206. <tr><td>size</td> <td>L</td> <td>1</td> <td>coor file size</td></tr>
  207. </table>
  208. \section vlibCoorFileBody Body
  209. The body consists of line records:
  210. <table border="1" style="border-collapse: collapse" cellpadding="5">
  211. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  212. <tr><td>record header</td><td>C</td><td>1</td><td>
  213. - 0. bit: 1 - alive, 0 - dead line
  214. - 1. bit: 1 - categories, 0 - no categories
  215. - 2.-3. bit: type - one of: GV_POINT, GV_LINE, GV_BOUNDARY, GV_CENTROID, GV_FACE, GV_KERNEL
  216. - 4.-7. bit: reserved, not used
  217. </td></tr>
  218. <tr><td>ncats</td><td>I</td><td>1</td><td>number of categories
  219. (written only if categories exist) </td></tr>
  220. <tr><td>field</td><td>I</td><td>ncats</td><td>field identifier,
  221. distinguishes between more categories append to one feature (written
  222. only if categories exist; field is called "layer" at user
  223. level)</td></tr>
  224. <tr><td>cat</td><td>I</td><td>ncats</td><td>category value (written
  225. only if categories exist)</td></tr>
  226. <tr><td>ncoor</td><td>I</td><td>1</td><td>written for GV_LINES and GV_BOUNDARIES
  227. only</td></tr>
  228. <tr><td>x</td><td>D</td><td>ncoor</td><td>x coordinate</td></tr>
  229. <tr><td>y</td><td>D</td><td>ncoor</td><td>y coordinate</td></tr>
  230. <tr><td>z</td><td>D</td><td>ncoor</td><td>z coordinate; present if
  231. with_z in head is set to 1</td></tr> </table>
  232. Types used in coor file:
  233. <table border="1" style="border-collapse: collapse" cellpadding="5">
  234. <tr><td><b>Type</b></td><td><b>Name</b></td><td><b>Size in Bytes</b></td></tr>
  235. <tr><td>D</td><td>Double</td><td>8</td></tr>
  236. <tr><td>L</td><td>Long </td><td>4</td></tr>
  237. <tr><td>I</td><td>Int </td><td>4</td></tr>
  238. <tr><td>S</td><td>Short </td><td>4</td></tr>
  239. <tr><td>C</td><td>Char </td><td>1</td></tr>
  240. </table>
  241. */