vectorlib.dox 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*! \page vectorlib GRASS Vector Library
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. \tableofcontents
  4. \par Related pages
  5. - \subpage vlibDescription
  6. - \subpage vlibFormat
  7. - \subpage vlibTopology
  8. - \subpage vlibIndices
  9. - \subpage vlibAscii
  10. - \subpage vlibTin
  11. - \subpage vlibFAQ
  12. - \subpage vlibLists
  13. \par Data providers for external formats
  14. - \subpage vlibOgr
  15. - \subpage vlibPg
  16. \par Related libraries
  17. - \subpage veditlib
  18. - \subpage netalib
  19. \section vlibBackground Background
  20. Generally, the vector data model is used to describe geographic
  21. phenomena which may be represented by geometric entities like
  22. <em>points</em>, <em>lines</em>, and <em>areas</em>. The GRASS vector
  23. data model includes the description of <em>topology</em>, where
  24. besides the coordinates describing the location of the primitives
  25. (points, lines, boundaries, centroids, faces, kernels, and volumes),
  26. their spatial relations are also stored. In general, topological GIS
  27. requires a data structure where the common boundary between two
  28. adjacent areas is stored as a single line, simplifying the vector data
  29. maintenance.
  30. \section vlibIntro Introduction
  31. The GRASS 6/7 vector format is very similar to the previous GRASS 4.x
  32. (5.0/5.3) vector format.
  33. This description covers the new GRASS 6/7 vector library architecture.
  34. This new architecture overcomes the vector limitations of GRASS
  35. 4.x-5.4.x by extending the vector support with attributes stored in
  36. the external relational databases, and by new 3D capabilities. Besides
  37. internal file based storage the geometry may alternatively be stored
  38. in a PostGIS database (accessible via OGR interface). This enables
  39. users to maintain large data sets with simultaneous write
  40. access. External GIS formats such as SHAPE-files may be used directly,
  41. without requiring format conversion. All vector data accessed through
  42. the OGR interface have only pseudo-topology and only a limited subset
  43. of vector operations can be performed.
  44. The current implementation includes:
  45. - <em>multi-layer</em>: features in one vector map may represent more
  46. layers and may be linked to more external tables (see \ref
  47. vlibCategoriesLayers)
  48. - <em>2D and 3D vector geometry</em> with full topology support for 2D and
  49. partial topology support for 3D (see \ref vlibTopoManagement)
  50. - <em>multi-format</em>: external data formats supported (SHAPE-file,
  51. OGR sources etc.)
  52. - <em>portability</em>: platform independent internal format, read- and
  53. writable on 32bit, 64bit etc. computer architectures
  54. - <em>network analysis</em> using integrated dglib library
  55. - <em>spatial index</em>: based on R-tree method for fast vector
  56. geometry access (see \ref vlibSpidx)
  57. - <em>multi-attribute</em>: attributes saved in external Relational
  58. Database Management System (RDBMS) connected through DBMI
  59. library and drivers (see \ref vlibAttributes)
  60. \section vlibVectorMap Vector map definition (native format)
  61. GRASS vector maps are stored in an <em>arc-node</em> representation,
  62. consisting of curves called arcs. An arc is stored as a series of
  63. x,y,z coordinate pairs. The two endpoints of an arc are called
  64. <em>nodes</em>. Two consecutive x,y,z pairs define an arc segment. The
  65. user specifies the type of input to GRASS; GRASS doesn't decide. GRASS
  66. supports feature type definition which allows for multiple types to
  67. co-exist in the same map. A centroid is assigned to the area it is
  68. within/inside (geometrically). An area is defined by one or more
  69. boundaries that form a losed ring. The category to which an area belongs
  70. is stored with the centroid. Such centroids are stored in the same binary
  71. 'coor' file with other primitives. Each element may have none, one or
  72. more categories (cats). More cats can be distinguished by field number
  73. (field, called "layer" at user level). Single and multi-category
  74. support on modules level are implemented. The z coordinate is optional
  75. and both 2D and 3D files may be written.
  76. The following <em>vector feature types (primitives)</em> are defined
  77. by the vector library (and holds by the coor file; see also \ref
  78. vlibFeatureTypes):
  79. - point: a point (2D or 3D) - GV_POINT
  80. - line: a directed sequence of connected vertices with two endpoints
  81. called nodes (2D or 3D) - GV_LINE
  82. - boundary: the border line to describe an area (2D only) - GV_BOUNDARY
  83. - centroid: a point within a closed boundary(ies) to describe an area
  84. (2D only) - GV_CENTROID
  85. - face: a 3D boundary (not implemented yet) - GV_FACE
  86. - kernel: a 3D centroid in a volume - GV_KERNEL
  87. From vector feature types mentioned above are derived:
  88. - area: the topological composition of a closed ring of boundary(ies)
  89. and optionally a centroid (2D only, 3D coordinates supported but
  90. ignored) - GV_AREA
  91. - isle: an area within area, not touching the boundaries of the outer
  92. area (2D only, 3D coordinates supported but ignored)
  93. - volume: a 3D corpus, the topological composition of faces and
  94. kernel (not implemented yet) - GV_VOLUME
  95. - hole: a volume within volume, 3D equivalent to isle within area (not
  96. implemented yet)
  97. Note that all lines and boundaries can consist of multiple segments.
  98. Area topology also holds information about isles. <em>Isles</em> are
  99. located within an area, not touching the boundaries of the outer
  100. area. Isles consist of one or more areas and are used internally by
  101. the vector library to maintain correct topology of areas.
  102. \section vlibVectorLevels Levels of read access
  103. There are two levels of read access to the vector data:
  104. - <i>Level One</i> provides simple access to the vector feature
  105. information. There is no access to topology information at this
  106. level.
  107. - <i>Level Two</i> provides full access to all the information
  108. including topology information. This level requires more from the
  109. programmer, more memory, and longer startup time. Without this level,
  110. areas are not available.
  111. The level of access is retured by Vect_open_old().
  112. <b>Example for sequential read access without topology:</b>
  113. \code
  114. int main
  115. {
  116. int type, ltype;
  117. struct Map_info Map;
  118. struct line_pnts *Points;
  119. struct line_cat *Cats;
  120. const char *name, *mapset;
  121. /* set open level to 1: no topology */
  122. Vect_set_open_level(1);
  123. if (Vect_open_old(&Map, name, mapset) < 1)
  124. G_fatal_error(_("Failed to open vector '%s'"), name);
  125. /* rewind vector file */
  126. Vect_rewind(&Map);
  127. Points = Vect_new_line_struct();
  128. Cats = Vect_new_cats_struct();
  129. while ((ltype = Vect_read_next_line(&Map, Points, Cats) > 0) {
  130. /* check for desired type */
  131. if (!(ltype & type))
  132. continue;
  133. /* process the feature */
  134. }
  135. exit(EXIT_SUCCESS);
  136. }
  137. \endcode
  138. <b>Example for random read access with topology:</b>
  139. \code
  140. int main
  141. {
  142. int line, nlines, type, ltype;
  143. struct Map_info Map;
  144. struct line_pnts *Points;
  145. struct line_cat *Cats;
  146. const char *name, *mapset;
  147. if (Vect_open_old(&Map, name, mapset) < 2)
  148. G_fatal_error(_("Failed to open vector '%s'"), name);
  149. Points = Vect_new_line_struct();
  150. Cats = Vect_new_cats_struct();
  151. nlines = Vect_get_num_lines(&Map);
  152. for (line = 1; line <= nlines; line++) {
  153. /* check for desired type */
  154. if (!(Vect_get_line_type(&Map, line) & type))
  155. continue;
  156. Vect_read_line(&Map, points, cats, line);
  157. /* process the feature */
  158. }
  159. exit(EXIT_SUCCESS);
  160. }
  161. \endcode
  162. <b>Example for working with areas (requires topology):</b>
  163. \code
  164. int main
  165. {
  166. int area, nareas;
  167. struct Map_info Map;
  168. struct line_cat *Cats;
  169. const char *name, *mapset;
  170. if (Vect_open_old(&Map, name, mapset) < 2)
  171. G_fatal_error(_("Failed to open vector '%s'"), name);
  172. Points = Vect_new_line_struct();
  173. Cats = Vect_new_cats_struct();
  174. nareas = Vect_get_num_areas(&Map);
  175. for (area = 1; area <= nareas; area++) {
  176. /* process the area */
  177. /* example: get area categories */
  178. if (Vect_get_area_cats(&Map, area, Cats) == -1)
  179. G_message(_("No catagory available for area %d"), area);
  180. }
  181. exit(EXIT_SUCCESS);
  182. }
  183. \endcode
  184. <em>Note:</em> Higher level of access are planned, so when checking
  185. success return codes for a particular level of access (when calling
  186. Vect_open_old() for example), the programmer should use >= instead of
  187. == for compatibility with future releases.
  188. An existing vector map can be opened for reading by Vect_open_old().
  189. A new vector map can be created (or open for writing) by
  190. Vect_open_new(). Vect_open_old() attempts to open a vector map at the
  191. highest possible level of access. It will return the number of the
  192. level at which the map was opened. Vect_open_new() always opens at level 1
  193. only. If you require that a vector map be opened at a lower level
  194. (e.g. one), you can call the routine <tt>Vect_set_open_level(1)</tt>;
  195. Vect_open_old() will then either open at level one or fail. If you
  196. instead require the highest level access possible, you should not use
  197. Vect_set_open_level(), but instead check the return value of
  198. Vect_open_old() to make sure it is greater than or equal to the lowest
  199. level at which you need access. This allows for future levels to work
  200. without need for module change.
  201. \section vlibCategoriesLayers Categories and Layers
  202. <i>Note: "layer" was called "field" in earlier version.</i>
  203. In GRASS, a "category" or "category number" is a vector feature ID
  204. used to link geometry to attributes which are stored in one or several
  205. (external) database table(s). This category number is stored into the
  206. vector geometry as well as a "cat" column (integer type) in each
  207. attribute database table. The category number is used to lookup an
  208. attribute assigned to a vector object. At user level, category numbers
  209. can be assigned to vector objects with the <tt>v.category</tt> command.
  210. In order to assign multiple attributes in different tables to vector
  211. objects, each map can hold multiple category numbers. This is achieved
  212. by assigning more than one "layer" to the map (<tt>v.db.connect</tt>
  213. command). The layer number determines which table to be used for
  214. attribute queries. For example, a cadastrial vector area map can be
  215. assigned on layer 1 to an attribute table containing landuse
  216. descriptions which are maintained by department A while layer 2 is
  217. assigned to an attribute table containing owner descriptions which are
  218. maintained by department B.
  219. Each vector feature inside a vector map has zero, one or more
  220. &lt;layer,category&gt; tuple(s). A user can (but not must) create
  221. attribute tables which are referenced by the layer, and rows which are
  222. essentially referenced by the &lt;layer,category&gt; pair.
  223. %Categories start with 1 (category '0' is allowed for OGR
  224. layers). %Categories do not have to be continuous.
  225. Information about categories holds \ref line_cats data structure.
  226. \section vlibAttributes Attributes
  227. The old GRASS 4.x 'dig_cats' files are not used any more and vectors'
  228. attributes are stored in external database. Connection with the
  229. database is done through drivers based on \ref dbmilib. Records in a
  230. table are linked to vector entities by layer and category number. The
  231. layer identifies table and the category identifies record. I.e., for
  232. any unique combination
  233. \verbatim
  234. map+mapset+layer+category
  235. \endverbatim
  236. there exists one unique combination
  237. \verbatim
  238. driver+database+table+row
  239. \endverbatim
  240. The general DBMI settings are defined in the '$MAPSET/VAR' text file
  241. (maintained with <tt>db.connect</tt> command at user level).
  242. \section vlibGeometry Vector library feature geometry
  243. \subsection vlibFeatureTypes Feature types
  244. Feature types are defined in include/vect_dig_defines.h, see the list bellow:
  245. - GV_POINT
  246. - GV_LINE
  247. - GV_BOUNDARY
  248. - GV_CENTROID
  249. - GV_FACE
  250. - GV_KERNEL
  251. - GV_AREA
  252. - GV_VOLUME
  253. - GV_POINTS (GV_POINT | GV_CENTROID)
  254. - GV_LINES (GV_LINE | GV_BOUNDARY)
  255. Face and kernel are 3D equivalents of boundary and centroid, but there
  256. is no support (yet) for 3D topology (volumes). Faces are used in a
  257. couple of modules including NVIZ to visualize 3D buildings and other
  258. volumetric figures.
  259. \section vlibAuthors Authors
  260. - Radim Blazek (vector architecture) <radim.blazek gmail.com>
  261. - Roberto Micarelli (DGLib) <mi.ro iol.it>
  262. Updates for GRASS 7:
  263. - Markus Metz (file-based spatial index, vector topology)
  264. - Martin Landa (GEOS support, direct OGR read access, PostgreSQL/PostGIS support) <landa.martin gmail.com>
  265. \section vlibReferences References
  266. Text based on: R. Blazek, M. Neteler, and R. Micarelli. The new GRASS 5.1
  267. vector architecture. In Open source GIS - GRASS users conference 2002,
  268. Trento, Italy, 11-13 September 2002. University of Trento, Italy, 2002.
  269. <a href="http://www.ing.unitn.it/~grass/conferences/GRASS2002/proceedings/proceedings/pdfs/Blazek_Radim.pdf">http://www.ing.unitn.it/~grass/conferences/GRASS2002/proceedings/proceedings/pdfs/Blazek_Radim.pdf</a>
  270. \section vlibSeealso See Also
  271. - \ref dbmilib
  272. - \ref veditlib
  273. */