vectorlib.dox 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*! \page vectorlib GRASS Vector Library
  2. by GRASS Development Team (https://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 boundary, simplifying 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. Two consecutive x,y,z pairs define an arc segment.
  64. <em>Nodes</em> are created automatically for the two endpoints of an arc.
  65. The 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. An area is defined by one or more
  68. boundaries that form a closed ring. A centroid is assigned to the area it is
  69. within/inside (geometrically). 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. Areas without centroids are from a
  72. user's perspective holes within another area, therefore not presented to
  73. a user as a real area, the equivalent of a polygon in Simple Feature Access.
  74. Each vector object may have none, one or more categories (cats). More
  75. categories can be distinguished by field number (field, called "layer"
  76. at user level). A vector object can also have multiple categories in the
  77. same layer, an example would be buffers where a single area might belong
  78. to multiple buffers of multiple buffered features. Single and
  79. multi-category support on module level is implemented. The z coordinate
  80. is optional and both 2D and 3D files may be written.
  81. The following <em>vector feature types (primitives)</em> are defined
  82. by the vector library (and holds by the coor file; see also \ref
  83. vlibFeatureTypes):
  84. - point: a point (2D or 3D) - GV_POINT
  85. - line: a directed sequence of connected vertices with two endpoints
  86. called nodes (2D or 3D) - GV_LINE
  87. - boundary: the border line to describe an area (2D only) - GV_BOUNDARY
  88. - centroid: a point within a closed boundary(ies) to describe an area
  89. (2D only) - GV_CENTROID
  90. - face: a 3D boundary (not implemented yet) - GV_FACE
  91. - kernel: a 3D centroid in a volume - GV_KERNEL
  92. From vector feature types mentioned above are derived:
  93. - area: the topological composition of a closed ring of boundary(ies)
  94. and optionally a centroid (2D only, 3D coordinates supported but
  95. ignored) - GV_AREA
  96. - isle: an area within area, not touching the boundaries of the outer
  97. area (2D only, 3D coordinates supported but ignored)
  98. - volume: a 3D corpus, the topological composition of faces and
  99. kernel (not implemented yet) - GV_VOLUME
  100. - hole: a volume within volume, 3D equivalent to isle within area (not
  101. implemented yet)
  102. Note that all lines and boundaries can consist of multiple segments.
  103. Area topology also holds information about isles. <em>Isles</em> are
  104. located within an area, not touching the boundaries of the outer
  105. area. Isles consist of one or more areas and are used internally by
  106. the vector library to maintain correct topology of areas.
  107. \section vlibVectorLevels Levels of read access
  108. There are two levels of read access to the vector data:
  109. - <i>Level One</i> provides simple access to the vector feature
  110. information. There is no access to topology information at this
  111. level.
  112. - <i>Level Two</i> provides full access to all the information
  113. including topology information. This level requires more from the
  114. programmer, more memory, and longer startup time. Without this level,
  115. areas are not available.
  116. The level of access is returned by Vect_open_old().
  117. <b>Example for sequential read access without topology:</b>
  118. \code
  119. int main
  120. {
  121. int type, ltype;
  122. struct Map_info Map;
  123. struct line_pnts *Points;
  124. struct line_cat *Cats;
  125. const char *name, *mapset;
  126. /* set open level to 1: no topology */
  127. Vect_set_open_level(1);
  128. if (Vect_open_old(&Map, name, mapset) < 1)
  129. G_fatal_error(_("Failed to open vector '%s'"), name);
  130. /* rewind vector file */
  131. Vect_rewind(&Map);
  132. Points = Vect_new_line_struct();
  133. Cats = Vect_new_cats_struct();
  134. while ((ltype = Vect_read_next_line(&Map, Points, Cats) > 0) {
  135. /* check for desired type */
  136. if (!(ltype & type))
  137. continue;
  138. /* process the feature */
  139. }
  140. exit(EXIT_SUCCESS);
  141. }
  142. \endcode
  143. <b>Example for random read access with topology:</b>
  144. \code
  145. int main
  146. {
  147. int line, nlines, type, ltype;
  148. struct Map_info Map;
  149. struct line_pnts *Points;
  150. struct line_cat *Cats;
  151. const char *name, *mapset;
  152. if (Vect_open_old(&Map, name, mapset) < 2)
  153. G_fatal_error(_("Failed to open vector '%s'"), name);
  154. Points = Vect_new_line_struct();
  155. Cats = Vect_new_cats_struct();
  156. nlines = Vect_get_num_lines(&Map);
  157. for (line = 1; line <= nlines; line++) {
  158. /* check for desired type */
  159. if (!(Vect_get_line_type(&Map, line) & type))
  160. continue;
  161. Vect_read_line(&Map, points, cats, line);
  162. /* process the feature */
  163. }
  164. exit(EXIT_SUCCESS);
  165. }
  166. \endcode
  167. <b>Example for working with areas (requires topology):</b>
  168. \code
  169. int main
  170. {
  171. int area, nareas;
  172. struct Map_info Map;
  173. struct line_cat *Cats;
  174. const char *name, *mapset;
  175. if (Vect_open_old(&Map, name, mapset) < 2)
  176. G_fatal_error(_("Failed to open vector '%s'"), name);
  177. Points = Vect_new_line_struct();
  178. Cats = Vect_new_cats_struct();
  179. nareas = Vect_get_num_areas(&Map);
  180. for (area = 1; area <= nareas; area++) {
  181. /* process the area */
  182. /* example: get area categories */
  183. if (Vect_get_area_cats(&Map, area, Cats) == -1)
  184. G_message(_("No category available for area %d"), area);
  185. }
  186. exit(EXIT_SUCCESS);
  187. }
  188. \endcode
  189. <em>Note:</em> Higher level of access are planned, so when checking
  190. success return codes for a particular level of access (when calling
  191. Vect_open_old() for example), the programmer should use >= instead of
  192. == for compatibility with future releases.
  193. An existing vector map can be opened for reading by Vect_open_old().
  194. A new vector map can be created (or open for writing) by
  195. Vect_open_new(). Vect_open_old() attempts to open a vector map at the
  196. highest possible level of access. It will return the number of the
  197. level at which the map was opened. Vect_open_new() always opens at level 1
  198. only. If you require that a vector map be opened at a lower level
  199. (e.g. one), you can call the routine <tt>Vect_set_open_level(1)</tt>;
  200. Vect_open_old() will then either open at level one or fail. If you
  201. instead require the highest level access possible, you should not use
  202. Vect_set_open_level(), but instead check the return value of
  203. Vect_open_old() to make sure it is greater than or equal to the lowest
  204. level at which you need access. This allows for future levels to work
  205. without need for module change.
  206. \section vlibCategoriesLayers Categories and Layers
  207. <i>Note: "layer" was called "field" in earlier version.</i>
  208. In GRASS, a "category" or "category number" is a vector feature ID
  209. used to link geometry to attributes which are stored in one or several
  210. (external) database table(s). This category number is stored into the
  211. vector geometry as well as a "cat" column (integer type) in each
  212. attribute database table. The category number is used to lookup an
  213. attribute assigned to a vector object. At user level, category numbers
  214. can be assigned to vector objects with the <tt>v.category</tt> command.
  215. In order to assign multiple attributes in different tables to vector
  216. objects, each map can hold multiple category numbers. This is achieved
  217. by assigning more than one "layer" to the map (<tt>v.db.connect</tt>
  218. command). The layer number determines which table to be used for
  219. attribute queries. For example, a cadastrial vector area map can be
  220. assigned on layer 1 to an attribute table containing landuse
  221. descriptions which are maintained by department A while layer 2 is
  222. assigned to an attribute table containing owner descriptions which are
  223. maintained by department B.
  224. Each vector feature inside a vector map has zero, one or more
  225. &lt;layer,category&gt; tuple(s). A user can (but not must) create
  226. attribute tables which are referenced by the layer, and rows which are
  227. essentially referenced by the &lt;layer,category&gt; pair.
  228. %Categories start with 1 (category '0' is allowed for OGR
  229. layers). %Categories do not have to be continuous.
  230. Information about categories holds \ref line_cats data structure.
  231. \section vlibAttributes Attributes
  232. For a user-centric view about attribute management, see the explanations
  233. in the <a href="https://grasswiki.osgeo.org/wiki/Vector_Database_Management">GRASS GIS Wiki</a>.
  234. The attribute data are stored in external database. Connection with the
  235. database is done through drivers based on \ref dbmilib. Records in a
  236. table are linked to vector entities by layer and category number. The
  237. layer identifies table and the category identifies record. I.e., for
  238. any unique combination
  239. \verbatim
  240. map+mapset+layer+category
  241. \endverbatim
  242. there exists one unique combination
  243. \verbatim
  244. driver+database+table+row
  245. \endverbatim
  246. The general DBMI settings are defined in the '$MAPSET/VAR' text file
  247. (maintained with <tt>db.connect</tt> command at user level).
  248. Note: vector boundaries are (typically) handled without category since adjacent
  249. parcels might have two different categories which prevents from a unique assignment.
  250. \section vlibGeometry Vector library feature geometry
  251. \subsection vlibFeatureTypes Feature types
  252. Feature types are defined in include/vect_dig_defines.h, see the list below:
  253. - GV_POINT
  254. - GV_LINE
  255. - GV_BOUNDARY
  256. - GV_CENTROID
  257. - GV_FACE
  258. - GV_KERNEL
  259. - GV_AREA
  260. - GV_VOLUME
  261. - GV_POINTS (GV_POINT | GV_CENTROID)
  262. - GV_LINES (GV_LINE | GV_BOUNDARY)
  263. Face and kernel are 3D equivalents of boundary and centroid, but there
  264. is no support (yet) for 3D topology (volumes). Faces are used in a
  265. couple of modules including NVIZ to visualize 3D buildings and other
  266. volumetric figures.
  267. \section vlibAuthors Authors
  268. - Radim Blazek (vector architecture) <radim.blazek gmail.com>
  269. - Roberto Micarelli (DGLib) <mi.ro iol.it>
  270. Updates for GRASS 7:
  271. - Markus Metz (file-based spatial index, vector topology)
  272. - Martin Landa (GEOS support, direct OGR read access, PostgreSQL/PostGIS support) <landa.martin gmail.com>
  273. \section vlibReferences References
  274. Text based on: R. Blazek, M. Neteler, and R. Micarelli. The new GRASS 5.1
  275. vector architecture. In Open source GIS - GRASS users conference 2002,
  276. Trento, Italy, 11-13 September 2002. University of Trento, Italy, 2002.
  277. <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>
  278. \section vlibSeealso See Also
  279. - \ref dbmilib
  280. - \ref veditlib
  281. */