vectorlib.dox 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463
  1. /*! \page vectorlib GRASS Vector Library
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. <b>Table of contents</b>
  4. - \subpage vlibBackground
  5. - \subpage vlibIntro
  6. - \subpage vlibVectorMap
  7. - \subpage vlibVectorLevels
  8. - \subpage vlibDirectoryStructure
  9. - \subpage vlibHeadFileFormat
  10. - \subpage vlibCategoriesLayers
  11. - \subpage vlibAttributes
  12. - \subpage vlibDblnFileFormat
  13. - \subpage vlibs
  14. - \subpage vlibHistory
  15. - \subpage vlibStructures
  16. - \subpage vlibMap_info
  17. - \subpage vlibPlus_head
  18. - \subpage vlibDig_head
  19. - \subpage vlibGeometry
  20. - \subpage vlibFeatureTypes
  21. - \subpage vlibCoorFileFormat
  22. - \subpage vlibCoorFileHead
  23. - \subpage vlibCoorFileBody
  24. - \subpage vlibTopoManagement
  25. - \subpage vlibTopoFileFormat
  26. - \subpage vlibTopoFileHead
  27. - \subpage vlibTopoFileBody
  28. - \subpage vlibTopoLevels
  29. - \subpage vlibTopoExamples
  30. - \subpage vlibTopoMemory
  31. - \subpage vlibSpidx
  32. - \subpage vlibSidxFileFormat
  33. - \subpage vlibCidx
  34. - \subpage vlibCidxFileFormat
  35. - \subpage vlibCidxFileHead
  36. - \subpage vlibTin
  37. - \subpage vlibOgrIface
  38. - \subpage vlibFrmtFileFormat
  39. - \subpage vlibFidxFileFormat
  40. - \subpage vlibDglib
  41. - \subpage vlibAscii
  42. - \subpage vlibFunc
  43. - \subpage vlibAuthors
  44. - \subpage vlibReferences
  45. - \subpage vlibSeealso
  46. \section vlibBackground Background
  47. Generally, the vector data model is used to describe geographic
  48. phenomena which may be represented by geometric entities like points,
  49. lines, and areas. The GRASS vector data model includes the description
  50. of topology, where besides the coordinates describing the location of
  51. the primitives (points, lines, boundaries, centroids, faces, and
  52. kernels), their spatial relations are also stored. In general,
  53. topological GIS requires a data structure where the common boundary
  54. between two adjacent areas is stored as a single line, simplifying the
  55. vector data maintenance.
  56. \section vlibIntro Introduction
  57. The GRASS 6/7 vector format is very similar to the previous GRASS 4.x
  58. (5.0/5.3) vector format.
  59. This description covers the new GRASS 6 vector library architecture.
  60. This new architecture overcomes the vector limitations of GRASS
  61. 4.x-5.4.x by extending the vector support with attributes stored in
  62. the external relational databases, and by new 3D capabilities. Besides
  63. internal file based storage the geometry may alternatively be stored
  64. in a PostGIS database (accessible via OGR interface). This enables
  65. users to maintain large data sets with simultaneous write
  66. access. External GIS formats such as SHAPE-files may be used directly,
  67. without requiring format conversion.
  68. The current implementation includes:
  69. - <b>multi-layer</b>: features in one vector map may represent more
  70. layers and may be linked to more external tables (see \ref
  71. vlibCategoriesLayers);
  72. - 2D and 3D vector geometry with full topology support for 2D and
  73. partial topology support for 3D (see \ref vlibTopoManagement);
  74. - <b>multi-format</b>: external data formats supported (SHAPE-file,
  75. OGR sources etc.);
  76. - <b>portability</b>: platform independent internal format, read- and
  77. writable on 32bit, 64bit etc. computer architectures;
  78. - integrated \ref vlibDglib - support for vector network analysis;
  79. - <b>spatial index</b>: based on R-tree method for fast vector
  80. geometry access (see \ref vlibSpidx);
  81. - <b>multi-attribute</b>: attributes saved in external Relational
  82. Database Management System (RDBMS) connected through DBMI
  83. library and drivers (\ref vlibAttributes);
  84. \subsection vlibVectorMap Vector map
  85. GRASS vector maps are stored in an <em>arc-node</em> representation,
  86. consisting of curves called arcs. An arc is stored as a series of
  87. x,y,z coordinate pairs. The two endpoints of an arc are called
  88. <em>nodes</em>. Two consecutive x,y,z pairs define an arc segment. The
  89. user specifies the type of input to GRASS; GRASS doesn't decide. GRASS
  90. allows for the feature definition which allows for multiple types to
  91. co-exist in the same map. Centroid are assigned to area it is
  92. within/inside (geometrically). An area is identified by an x,y,z
  93. centroid point geometrically inside with a category number (ID). This
  94. identifies the area. Such centroids are stored in the same binary
  95. 'coor' file with other primitives. Each element may have none, one or
  96. more categories (cats). More cats are distinguished by field number
  97. (field, called "layer" at user level). Single and multi-category
  98. support on modules level are implemented. Z-coordinate is optional and
  99. both 2D and 3D files may be written.
  100. The following vector feature types (primitives) are defined by the
  101. vector library (and holds by the coor file; see also \ref
  102. vlibFeatureTypes):
  103. - point: a point (2D or 3D);
  104. - line: a directed sequence of connected vertices with two endpoints
  105. called nodes (2D or 3D);
  106. - boundary: the border line to describe an area (2D only);
  107. - centroid: a point within a closed boundary(ies) to describe an area
  108. (2D only);
  109. - face: a 3D boundary (not implemented yet);
  110. - kernel: a 3D centroid in a volume.
  111. From vector feature types mentioned above are derived:
  112. - node: start/endpoints of lines and boundaries (2D or 3D);
  113. - area: the topological composition of a closed ring of boundary(ies)
  114. and optionally a centroid (2D only, 3D coordinates supported but ignored);
  115. - isle: an area within area, not touching the boundaries of the outer
  116. area (2D only, 3D coordinates supported but ignored);
  117. - edge: a 3D node connecting faces (not implemented yet)
  118. - volume: a 3D corpus, the topological composition of faces and kernel
  119. (not implemented yet);
  120. - hole: a volume within volume, 3D equivalent to isle within area (not
  121. implemented yet).
  122. Note that all lines and boundaries can consist of multiple segments.
  123. Area topology also holds information about isles. Isles are located within an area, not
  124. touching the boundaries of the outer area. Isles consist of one or more areas
  125. and are used internally by the vector libraries to maintain correct topology of areas.
  126. \subsubsection vlibVectorLevels Levels of read access
  127. There are two levels of read access to the vector data:
  128. - <i>Level One</i> provides simple access to the vector feature
  129. information. There is no access to topology information at this
  130. level.
  131. - <i>Level Two</i> provides full access to all the information
  132. including topology information. This level requires more from the
  133. programmer, more momory, and longer startup time.
  134. Level of access is retured by Vect_open_old().
  135. Note: Higher level of access are planned, so when checking success
  136. return codes for a particular level of access (when calling
  137. Vect_open_old() for example), the programmer should use >= instead of
  138. == for compatibility with future releases.
  139. An existing vector map can be open for reading by Vect_open_old(). New
  140. vector map can be created (or open for writing) by
  141. Vect_open_new(). Vect_open_old() attempts to open a vector map at the
  142. highest possible level of access. It will return the number of the
  143. level at which it opened. Vect_open_new() always opens at level 1
  144. only. If you require that a vector map be opened at a lower level
  145. (e.g. one), you can call the routine Vect_set_open_level(1);
  146. Vect_open_old() will then either open at level one or fail. If you
  147. instead require the highest level access possible, you should not use
  148. Vect_set_open_level(), but instead check the return value of
  149. Vect_open_old() to make sure it is greater than or equal to the lowest
  150. level at which you need access. This allows for future levels to work
  151. without need for module change.
  152. \subsubsection vlibDirectoryStructure Directory structure
  153. Vector map is stored in a number of data files. Vector map directory
  154. structure and file names were changed in GRASS 6 with respect to
  155. previous GRASS versions. All vector files for one vector map are
  156. stored in one directory:
  157. \verbatim
  158. $MAPSET/vector/vector_name/
  159. \endverbatim
  160. This directory contains these files:
  161. - <b>coor</b> - binary file, coordinates [former dig/ file] (see \ref vlibCoorFileFormat)
  162. - <b>topo</b> - binary file, topology [former dig_plus/ file] (see \ref vlibTopoFileFormat)
  163. - <b>sidx</b> - binary file, spatial index (see \ref vlibSidxFileFormat)
  164. - <b>cidx</b> - binary file, category index (see \ref vlibCidxFileFormat)
  165. - <b>head</b> - text file, header information [former part of dig/ file] (see \ref vlibHeadFileFormat)
  166. - <b>dbln</b> - text file, link(s) to attribute table(s) (see \ref vlibDblnFileFormat)
  167. - <b>hist</b> - text file, vector map change history
  168. - <b>frmt</b> - text file, format description (external format only)
  169. - <b>fidx</b> - binary file, feature index (OGR format only)
  170. \subsubsection vlibHeadFileFormat Head file format specification
  171. The header contains historical information, a description of the
  172. vector map and many other information. The file is an unordered list
  173. of key/value entries. The <i>key</i> is a string separated from
  174. <i>value</i> by a colon and optional whitespace. Keywords are:
  175. <table border="1" style="border-collapse: collapse">
  176. <tr><td>ORGANIZATION</td><td>organization that digitized the data</td></tr>
  177. <tr><td>DIGIT DATE</td><td>date the data was digitized</td></tr>
  178. <tr><td>DIGIT NAME</td><td>person who digitized the data</td></tr>
  179. <tr><td>MAP NAME</td><td>title of the original source map</td></tr>
  180. <tr><td>MAP DATE</td><td>date of the original source map</td></tr>
  181. <tr><td>MAP SCALE</td><td>scale of the original source map</td></tr>
  182. <tr><td>OTHER INFO</td><td>other comments about the map</td></tr>
  183. <tr><td>ZONE</td><td>zone of the map (e.g., UTM zone)</td></tr>
  184. <tr><td>MAP THRESH</td><td>digitizing threshold</td></tr>
  185. </table>
  186. \subsection vlibCategoriesLayers Categories and layers
  187. <i>Note: "layer" was called "field" in earlier version.</i>
  188. In GRASS, a "category" or "category number" is a vector feature ID
  189. used to link geometry to attributes which are stored in one or several
  190. (external) database table(s). This category number is stored into the
  191. vector geometry as well as a "cat" column (integer type) in each
  192. attribute database table. The category number is used to lookup an
  193. attribute assigned to a vector object. At user level, category numbers
  194. can be assigned to vector objects with the <tt>v.category</tt> command.
  195. In order to assign multiple attributes in different tables to vector
  196. objects, each map can hold multiple category numbers. This is achieved
  197. by assigning more than one "layer" to the map (<tt>v.db.connect</tt>
  198. command). The layer number determines which table to be used for
  199. attribute queries. For example, a cadastrial vector area map can be
  200. assigned on layer 1 to an attribute table containing landuse
  201. descriptions which are maintained by department A while layer 2 is
  202. assigned to an attribute table containing owner descriptions which are
  203. maintained by department B.
  204. Each vector feature inside a vector map has zero, one or more
  205. &lt;layer,category&gt; tuple(s). A user can (but not must) create
  206. attribute tables which are referenced by the layer, and rows which are
  207. essentially referenced by the &lt;layer,category&gt; pair.
  208. Categories start with 1 (category '0' is allowed for OGR
  209. layers). Categories do not have to be continuous.
  210. \subsection vlibAttributes Attributes
  211. The old GRASS 4.x 'dig_cats' files are not used any more and vectors'
  212. attributes are stored in external database. Connection with the
  213. database is done through drivers based on \ref dbmilib. Records in a
  214. table are linked to vector entities by layer and category number. The
  215. layer identifies table and the category identifies record. I.e., for
  216. any unique combination
  217. \verbatim
  218. map+mapset+layer+category
  219. \endverbatim
  220. there exists one unique combination
  221. \verbatim
  222. driver+database+table+row
  223. \endverbatim
  224. Information about database links holds <tt>dblinks</tt> structure.
  225. \code
  226. struct dblinks
  227. {
  228. struct field_info *field; /* pointer to the first field_info structure */
  229. int alloc_fields; /* number of allocated slots */
  230. int n_fields; /* number of available fields */
  231. };
  232. \endcode
  233. The general DBMI settings are defined in the '$MAPSET/VAR' text file
  234. (maintained with <tt>db.connect</tt> command at user level).
  235. \subsection vlibDblnFileFormat Dbln file format specification
  236. Each vector maps has its own DBMI settings stored in the
  237. '$MAPSET/vector/vector_name/dbln' text file. For each pair <b>vector map +
  238. layer</b>, all of <b>table, key column, database, driver</b> must be
  239. defined in a new row. This definition must be written to
  240. '$MAPSET/vector/vector_name/dbln' text file. Each row in the 'dbln'
  241. file contains names separated by spaces in following order ([ ] -
  242. optional):
  243. \verbatim
  244. map[@mapset] layer table [key [database [driver]]]
  245. \endverbatim
  246. If key, database or driver are omitted (on second and higher row only)
  247. the last definition is used. When reading a vector map from another
  248. mapset (if mapset is specified along with map name), definitions in
  249. the related "dbln" file may overwrite the DBMI definition in the
  250. current mapset. This means that the map-wise definition is always
  251. "stronger".
  252. Wild cards <b>*</b> and <b>?</b> may be used in map and mapset names.
  253. Variables $GISDBASE, $LOCATION_NAME, $MAPSET, and $MAP may be used in
  254. table, key, database and driver names (function
  255. Vect_subst_var()). Note that $MAPSET is not the current mapset but
  256. mapset of the map the rule is defined for.
  257. Note that vector features in GRASS vector maps may have attributes in
  258. different tables or may be without attributes. Boundaries form areas
  259. but it may happen that some boundaries are not closed (such boundaries
  260. would not appear in polygon layer). Boundaries may have
  261. attributes. All types may be mixed in one vector map.
  262. The link to the table is permanent and it is stored in 'dbln' file in
  263. vector directory. Tables are considered to be a part of the vector and
  264. the command <tt>g.remove</tt>, for example, deletes linked tables of
  265. the vector. Attributes must be joined with geometry.
  266. <b>Examples:</b>
  267. Examples are written mostly for the DBF driver, where database is full
  268. path to the directory with dbf files and table name is the name of dbf
  269. file without .dbf extension:
  270. \verbatim
  271. * 1 mytable id $GISDBASE/$LOCATION_NAME/$MAPSET/vector/$MAP dbf
  272. \endverbatim
  273. This definition says that entities with category of layer 1 are linked
  274. to dbf tables with names "mytable.dbf" saved in vector directories of
  275. each map. The attribute column containing the category numbers is
  276. called "id".
  277. \verbatim
  278. * 1 $MAP id $GISDBASE/$LOCATION_NAME/$MAPSET/dbf dbf
  279. \endverbatim
  280. Similar as above but all dbf files are in one directory dbf/ in mapset
  281. and names of dbf files are $MAP.dbf
  282. \verbatim
  283. water* 1 rivers id /home/grass/dbf dbf
  284. water* 2 lakes lakeid /home/guser/mydb
  285. trans* 1 roads key basedb odbc
  286. trans* 5 rails
  287. \endverbatim
  288. These definitions define more layers (called "field" in the API) for
  289. one vector map i.e. in one vector map may be more features linked to
  290. more attribute tables. Definitions on first 2 rows are applied for
  291. example on maps water1, water2, ... so that more maps may share one
  292. table.
  293. \verbatim
  294. water@PERMANENT 1 myrivers id /home/guser/mydbf dbf
  295. \endverbatim
  296. This definion overwrites the definition saved in PERMANENT/VAR and
  297. links the water map from PERMANENT mapset to the user's table.
  298. Modules should be written so that connections to databases for each
  299. vector layer are independent. It should be possible to read attributes
  300. of an input vector map from one database and write to some other and
  301. even with some other driver (should not be a problem).
  302. There are open questions, however. For one, how does one distinguish when
  303. new tables should be written and when not? For example, definitions:
  304. \verbatim
  305. river 1 river id water odbc
  306. river.backup* 1 NONE
  307. \endverbatim
  308. could be used to say that tables should not be copied for backups of
  309. map river because table is stored in a reliable RDBMS.
  310. \section vlibs Vector libraries
  311. Besides internal library functions there are two main libraries:
  312. - Vlib (Vector library), see \ref vlibIntro
  313. - DGLib (Directed Graph Library), see \ref vlibDglib
  314. For historical reasons, there are two internal libraries:
  315. - diglib (with dig_*() functions), GRASS 3.x/4.x
  316. - Vlib (with V1_*(), V2_*() and Vect_*() functions), since GRASS 4.x
  317. (except for the 5.7 interim version)
  318. The vector library was introduced in GRASS 4.0 to hide internal vector
  319. files' formats and structures. In GRASS 6/7, everything is accessed via
  320. Vect_*() functions, for example:
  321. Old 4.x code:
  322. \code
  323. xx = Map.Att[Map.Area[area_num].att].x;
  324. \endcode
  325. New 6.x/7.x functions:
  326. \code
  327. centroid = Vect_get_area_centroid(Map, area_num);
  328. Vect_read_line(Map, line_p, NULL, centroid);
  329. Vect_line_get_point(line_p, 0, &xx, NULL, NULL);
  330. \endcode
  331. In GRASS 6/7, all internal, mostly non-topological vector functions are
  332. hidden from the modules' API (mainly dig_*(), V1_*() and V2_*()
  333. functions). All available Vect_*() functions are topological vector
  334. functions.
  335. The following include file contains definitions and structures
  336. required by some of the routines in this library. The programmer
  337. should therefore include this file in any code that uses the vector
  338. library:
  339. \code
  340. #include <grass/vector.h>
  341. \endcode
  342. <i>Note: For details please read Blazek et al. 2002 (see below) as
  343. well as the references in this document.</i>
  344. \subsection vlibHistory Historical notes
  345. The vector library in GRASS 4.0 changed significantly from the
  346. <b>Digit Library</b> (diglib) used in GRASS 3.1. Below is an overview
  347. of why the changes were made.
  348. The Digit Library was a collage of subroutines created for developing
  349. the map development programs. Few of these subroutines were actually
  350. designed as a user access library. They required individuals to assume
  351. too much responsibility and control over what happened to the data
  352. file. Thus when it came time to change vector data file formats for
  353. GRASS 4.0, many modules also required modification. The two different
  354. access levels for 3.0 vector files provided very different ways of
  355. calling the library; they offered little consistency for the user.
  356. The Digit Library was originally designed to only have one file open
  357. for read or write at a time. Although it was possible in some cases to
  358. get around this, one restriction was the global head structure. Since
  359. there was only one instance of this, there could only be one copy of
  360. that information, and thus, only one open vector file.
  361. The solution to these problems was to design a new user library as an
  362. interface to the vector data files. This new library was designed to
  363. provide a simple consistent interface, which hides as much of the
  364. details of the data format as possible. It also could be extended for
  365. future enhancements without the need to change existing programs.
  366. The new vector library in GRASS 4 provided routines for opening,
  367. closing, reading, and writing vector files, as well as several support
  368. functions. The Digit Library has been replaced, so that all existing
  369. modules was converted to use the new library. Those routines that
  370. existed in the Digit Library and were not affected by these changes
  371. continue to exist in unmodified form, and were included in the vector
  372. library. Most of the commonly used routines have been discarded, and
  373. replaced by the new vector routines.
  374. Instead the global head structure was used own local version of
  375. it. The structure that replaced struct head is struct dig_head. There
  376. were still two levels of interface to the vector files (future
  377. releases may include more). Level one provided access only to arc
  378. (i.e. polyline) information and to the type of line (AREA, LINE,
  379. DOT). Level two provided access to polygons (areas), attributes, and
  380. network topology.
  381. \section vlibStructures Vector library structures
  382. \subsection vlibMap_info Map_info structure
  383. The token that is used to identify each vector map is the Map_info
  384. structure. It maintains all information about an individual open
  385. vector map. The structure must be passed to the mosy vector library
  386. routines.
  387. \code
  388. struct Map_info
  389. {
  390. /* common info for all formats */
  391. int format; /* format (native, ogr) */
  392. int temporary; /* temporary file flag, not yet used */
  393. struct dblinks *dblnk; /* info about db links */
  394. struct Plus_head plus; /* topo file head info */
  395. /* graph-related section */
  396. int graph_line_type; /* line type used to build the graph */
  397. dglGraph_s graph; /* graph structure */
  398. dglSPCache_s spCache; /* shortest path cache */
  399. double *edge_fcosts; /* costs used for graph, (dglGetEdge()
  400. is not supported for _DGL_V1) */
  401. double *edge_bcosts;
  402. double *node_costs; /* node costs */
  403. int cost_multip; /* edge and node costs
  404. multiplicator */
  405. /* All of these apply only to runtime, and none get written out
  406. to the dig_plus file
  407. */
  408. int open; /* should be 0x5522AA22 if opened correctly
  409. or 0x22AA2255 if closed
  410. anything else implies that structure has
  411. never been initialized
  412. */
  413. int mode; /* Open mode - read, write, rw */
  414. int level; /* Topology level - 1, 2, (3) */
  415. int head_only; /* only header is opened */
  416. int support_updated; /* support files were updated */
  417. plus_t next_line; /* for level 2 sequential reads */
  418. char *name; /* for 4.0 just name, and mapset */
  419. char *mapset; /* mapset name */
  420. /* location and gisdbase is usefull if changed (v.proj or external apps) */
  421. char *location; /* location name */
  422. char *gisdbase; /* gisdbase path */
  423. /* constraints for reading in lines (not polys yet) */
  424. int Constraint_region_flag;
  425. int Constraint_type_flag;
  426. double Constraint_N;
  427. double Constraint_S;
  428. double Constraint_E;
  429. double Constraint_W;
  430. double Constraint_T;
  431. double Constraint_B;
  432. int Constraint_type;
  433. int proj;
  434. /* format specific */
  435. /* native */
  436. struct gvfile dig_fp; /* dig file pointer */
  437. struct dig_head head; /* coor file head */
  438. /* non native */
  439. struct Format_info fInfo; /* format information */
  440. /* history file */
  441. FILE *hist_fp;
  442. /* temporary solution for sites */
  443. struct site_att *site_att; /* array of attributes loaded from db */
  444. int n_site_att; /* number of attributes in site_att array */
  445. int n_site_dbl; /* number of double attributes for one site */
  446. int n_site_str; /* number of string attributes for one site */
  447. };
  448. \endcode
  449. \subsection vlibPlus_head Plus_head structure
  450. <tt>Plus_head</tt> holds basic topology-related information about vector map.
  451. \code
  452. struct Plus_head
  453. {
  454. int Version_Major; /* version codes */
  455. int Version_Minor;
  456. int Back_Major; /* earliest version that can use this data format */
  457. int Back_Minor;
  458. int spidx_Version_Major; /* version codes for spatial index */
  459. int spidx_Version_Minor;
  460. int spidx_Back_Major; /* earliest version that can use this data format */
  461. int spidx_Back_Minor;
  462. int cidx_Version_Major; /* version codes for category index */
  463. int cidx_Version_Minor;
  464. int cidx_Back_Major; /* earliest version that can use this data format */
  465. int cidx_Back_Minor;
  466. int with_z; /* 2D/3D vector data */
  467. int spidx_with_z; /* 2D/3D spatial index */
  468. int off_t_size; /* offset size here because Plus_head
  469. is available to all releveant
  470. functions */
  471. long head_size; /* topo header size */
  472. long spidx_head_size; /* spatial index header size */
  473. long cidx_head_size; /* category index header size */
  474. int release_support; /* release memory occupied by support
  475. (topo, spatial, category) */
  476. struct Port_info port; /* portability information */
  477. struct Port_info spidx_port; /* portability information for
  478. spatial index */
  479. struct Port_info cidx_port; /* portability information for
  480. category index */
  481. int mode; /* read, write, RW */
  482. int built; /* the highest level of topology
  483. currently available
  484. (GV_BUILD_*) */
  485. struct bound_box box; /* vector map bounding box */
  486. /* topology info */
  487. struct P_node **Node; /* struct P_node array of pointers
  488. 1st item is 1 for */
  489. struct P_line **Line; /* struct P_line array of pointers
  490. all these (not 0) */
  491. struct P_area **Area;
  492. struct P_isle **Isle;
  493. /* add here P_FACE, P_VOLUME, P_HOLE */
  494. plus_t n_nodes; /* current number of nodes */
  495. plus_t n_edges; /* current number of edges */
  496. plus_t n_lines; /* current number of lines */
  497. plus_t n_areas; /* current number of areas */
  498. plus_t n_isles; /* current number of isles */
  499. plus_t n_faces; /* current number of faces */
  500. plus_t n_volumes; /* current number of volumes */
  501. plus_t n_holes; /* current number of holes */
  502. plus_t n_plines; /* current number of points */
  503. plus_t n_llines; /* current number of lines */
  504. plus_t n_blines; /* current number of boundaries */
  505. plus_t n_clines; /* current number of centroids */
  506. plus_t n_flines; /* current number of faces */
  507. plus_t n_klines; /* current number of kernels*/
  508. plus_t n_vfaces; /* current number of volumes */
  509. plus_t n_hfaces; /* current number of hole faces */
  510. plus_t alloc_nodes; /* number of nodes we have alloc'ed
  511. space for i.e. array size - 1 */
  512. plus_t alloc_edges; /* number of edges we have alloc'ed space for */
  513. plus_t alloc_lines; /* number of lines we have alloc'ed space for */
  514. plus_t alloc_areas; /* number of areas we have alloc'ed space for */
  515. plus_t alloc_isles; /* number of isles we have alloc'ed space for */
  516. plus_t alloc_faces; /* number of faces we have alloc'ed space for */
  517. plus_t alloc_volumes; /* number of volumes we have alloc'ed space for */
  518. plus_t alloc_holes; /* number of holes we have alloc'ed space for */
  519. off_t Node_offset; /* offset of array of nodes in topo file */
  520. off_t Edge_offset; /* offset of array of edges in topo file */
  521. off_t Line_offset; /* offset of array of lines in topo file */
  522. off_t Area_offset; /* offset of array of areas in topo file */
  523. off_t Isle_offset; /* offset of array of isles in topo file */
  524. off_t Volume_offset; /* offset of array of volumes in topo file */
  525. off_t Hole_offset; /* offset of array of holes in topo file */
  526. int Spidx_built; /* set to 1 if spatial index is available */
  527. int Spidx_new; /* set to 1 if new spatial index will be generated */
  528. struct gvfile spidx_fp; /* spatial index file pointer */
  529. char *spidx_node_fname; /* node spatial index file name */
  530. off_t Node_spidx_offset; /* offset of nodes in sidx file */
  531. off_t Line_spidx_offset; /* offset of lines in sidx file */
  532. off_t Area_spidx_offset; /* offset of areas in sidx file */
  533. off_t Isle_spidx_offset; /* offset of isles in sidx file */
  534. off_t Face_spidx_offset; /* offset of faces in sidx file */
  535. off_t Volume_spidx_offset; /* offset of volumes in sidx file */
  536. off_t Hole_spidx_offset; /* offset of holes in sidx file */
  537. struct RTree *Node_spidx; /* node spatial index */
  538. struct RTree *Line_spidx; /* line spatial index */
  539. struct RTree *Area_spidx; /* area spatial index */
  540. struct RTree *Isle_spidx; /* isle spatial index */
  541. struct RTree *Face_spidx; /* face spatial index */
  542. struct RTree *Volume_spidx; /* volume spatial index */
  543. struct RTree *Hole_spidx; /* hole spatial index */
  544. /* Category index
  545. By default, category index is not updated */
  546. int update_cidx; /* update category index if vector is modified */
  547. int n_cidx; /* number of cat indexes (one for each field) */
  548. int a_cidx; /* allocated space for cat indexes */
  549. struct Cat_index *cidx; /* array of category indexes */
  550. int cidx_up_to_date; /* set to 1 when cidx is created and reset to 0 whenever any line is changed */
  551. off_t coor_size; /* size of coor file */
  552. long coor_mtime; /* time of last coor modification */
  553. /* Level2 update: list of lines and nodes updated (topo info for
  554. the line was changed) by last write/rewrite/delete operation.
  555. Lines/nodes in the list may be deleted (e.g. delete boundary:
  556. first added for delete area and then delete */
  557. int do_uplist; /* used internaly in diglib to know if list is maintained */
  558. int *uplines; /* array of updated lines */
  559. int alloc_uplines; /* allocated array */
  560. int n_uplines; /* number of updated lines */
  561. int *upnodes; /* array of updated nodes */
  562. int alloc_upnodes; /* allocated array */
  563. int n_upnodes; /* number of updated nodes */
  564. };
  565. \endcode
  566. \subsection vlibDig_head dig_head structure
  567. <tt>dig_head</tt> holds header data of vector map (see \ref vlibMap_info).
  568. \code
  569. struct dig_head
  570. {
  571. /* elements */
  572. char *organization; /* orgranization name */
  573. char *date; /* map date */
  574. char *your_name; /* user name */
  575. char *map_name; /* map name */
  576. char *source_date; /* source date */
  577. long orig_scale; /* original scale */
  578. char *line_3; /* comments */
  579. int plani_zone; /* zone */
  580. double digit_thresh; /* threshold for digitization */
  581. /* Programmers should NOT touch any thing below here */
  582. /* Library takes care of everything for you */
  583. /* coor elements */
  584. int Version_Major; /* backward compatibility info */
  585. int Version_Minor;
  586. int Back_Major;
  587. int Back_Minor;
  588. int with_z; /* 2D/3D vector data */
  589. off_t size; /* coor file size */
  590. long head_size; /* coor header size */
  591. struct Port_info port; /* portability information */
  592. off_t last_offset; /* offset of last read line */
  593. struct recycle *recycle; /* recycle dead line, not implemented yet */
  594. struct Map_info *Map; /* X-ref to Map_info struct (needed?) */
  595. };
  596. \endcode
  597. \section vlibGeometry Vector library feature geometry
  598. \subsection vlibFeatureTypes Feature types
  599. \code
  600. #define GV_POINT 0x01
  601. #define GV_LINE 0x02
  602. #define GV_BOUNDARY 0x04
  603. #define GV_CENTROID 0x08
  604. #define GV_FACE 0x10
  605. #define GV_KERNEL 0x20
  606. #define GV_AREA 0x40
  607. #define GV_VOLUME 0x80
  608. #define GV_POINTS (GV_POINT | GV_CENTROID )
  609. #define GV_LINES (GV_LINE | GV_BOUNDARY )
  610. \endcode
  611. Face and kernel are 3D equivalents of boundary and centroid, but there
  612. is no support (yet) for 3D topology (volumes). Faces are used in a
  613. couple of modules including NVIZ to visualize 3D buildings and other
  614. volumetric figures.
  615. \subsection vlibCoorFileFormat Coor file format specification
  616. In the coor file the following is stored: 'line' (element) type,
  617. number of attributes and layer number for each category. Coordinates
  618. in binary file are stored as double (8 bytes).
  619. \subsubsection vlibCoorFileHead Header
  620. <table border="1" style="border-collapse: collapse">
  621. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  622. <tr><td>Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
  623. <tr><td>Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
  624. <tr><td>Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
  625. <tr><td>Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
  626. <tr><td>byte_order</td><td>C</td><td>1</td><td>little or big endian
  627. flag; files are written in machine native order but
  628. files in both little and big endian order may be
  629. read; zero for little endian</td></tr>
  630. <tr><td>size</td><td>L</td><td>1</td><td>coor file size</td></tr>
  631. <tr><td>with_z</td><td>C</td><td>1</td><td>2D or 3D flag; zero for 2D</td></tr>
  632. <tr><td>reserved</td><td>C</td><td>10</td><td>not used</td></tr>
  633. </table>
  634. \subsubsection vlibCoorFileBody Body
  635. The body consists of line records:
  636. <table border="1" style="border-collapse: collapse">
  637. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  638. <tr><td>record header</td><td>C</td><td>1</td><td>
  639. <UL>
  640. <LI><B>0. bit</B> : 1 - alive, 0 - dead line
  641. <LI><B>1. bit</B> : 1 - categories, 0 - no categories
  642. <LI><B>2.-3. bit</B> : type - one of: GV_POINT, GV_LINE,
  643. GV_BOUNDARY, GV_CENTROID
  644. <LI><B>4.-7. bit</B> : reserved, not used
  645. </UL>
  646. </td></tr>
  647. <tr><td>ncats</td><td>I</td><td>1</td><td>number of categories
  648. (written only if categories exist) </td></tr>
  649. <tr><td>field</td><td>I</td><td>ncats</td><td>field identifier,
  650. distinguishes between more categories append to one feature (written
  651. only if categories exist; field is called "layer" at user
  652. level)</td></tr>
  653. <tr><td>cat</td><td>I</td><td>ncats</td><td>category value (written
  654. only if categories exist)</td></tr>
  655. <tr><td>ncoor</td><td>I</td><td>1</td><td>written for GV_LINES and GV_BOUNDARIES
  656. only</td></tr>
  657. <tr><td>x</td><td>D</td><td>ncoor</td><td>x coordinate</td></tr>
  658. <tr><td>y</td><td>D</td><td>ncoor</td><td>y coordinate</td></tr>
  659. <tr><td>z</td><td>D</td><td>ncoor</td><td>z coordinate; present if
  660. with_z in head is set to 1</td></tr> </table>
  661. <B>Types used in coor file</B>
  662. <table border="1" style="border-collapse: collapse">
  663. <tr><td>Type</td><td>Name</td><td>Size in Bytes</td></tr>
  664. <tr><td>D</td><td>Double</td><td>8</td></tr>
  665. <tr><td>L</td><td>Long </td><td>4</td></tr>
  666. <tr><td>I</td><td>Int </td><td>4</td></tr>
  667. <tr><td>S</td><td>Short </td><td>4</td></tr>
  668. <tr><td>C</td><td>Char </td><td>1</td></tr>
  669. </table>
  670. \section vlibTopoManagement Vector library topology management
  671. Topology general characteristics:
  672. - geometry and attributes are stored separately
  673. (don't read both if it is not necessary (usually it is not))</li>
  674. - the format is topological (areas build from boundaries)</li>
  675. - currently only 2D topology is supported
  676. Topology is written for native format while pseudo-topology is written
  677. for OGR sources, SHAPE-link.
  678. The following rules apply to the vector data:
  679. - Lines should not cross each other (i.e., lines which would cross must
  680. be split at their intersection to form distict lines).
  681. - Linear primitives which share nodes at exactly same points (i.e.,
  682. must be snapped together). This is particulary important since nodes
  683. are not exactly represented in the coor file, but only implicitly as
  684. endpoints of lines.
  685. - Common area boundaries should appear only once (i.e., should not be
  686. double digitized).
  687. - Areas must be explicitly closed. This means that it must be possible
  688. to complete each area by following one or more boundaries that are
  689. connected by common nodes, and that such tracings result is closed
  690. areas.
  691. - It is recommended that area features and linear features be placed
  692. in separate layers. However if area features and linear features
  693. must appear in one layer, common boundaries should be digitized only
  694. once. A boundary that is also a line (e.g., a road which is also a
  695. field boundary), should be digitized as a boundary to complete the
  696. area. The area feature should be labeled by a centroid as an
  697. area. Additionally, the common boundary itself (i.e., the boundary
  698. which is also a line) should be labeled as a line by a distict
  699. category number.
  700. Vector map topology can be cleaned at user level by <tt>v.clean</tt>
  701. command.
  702. \subsection vlibTopoFileFormat Topo file format specification
  703. Topo file is read by Vect_open_topo().
  704. \subsubsection vlibTopoFileHead Header
  705. Note: <tt>plus</tt> is instance of <tt>Plus_head</tt> structure.
  706. <table border="1" style="border-collapse: collapse">
  707. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  708. <tr><td>plus->Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
  709. <tr><td>plus->Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
  710. <tr><td>plus->Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
  711. <tr><td>plus->Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
  712. <tr><td>plus->port->byte_order</td><td>C</td><td>1</td><td>little or big endian
  713. flag; files are written in machine native order but
  714. files in both little and big endian order may be
  715. readl; zero for little endian</td></tr>
  716. <tr><td>plus->head_size</td><td>L</td><td>1</td><td>header size</td></tr>
  717. <tr><td>plus->with_z</td><td>C</td><td>1</td><td>2D or 3D flag; zero for 2D</td></tr>
  718. <tr><td>plus->box</td><td>D</td><td>6</td><td>Bounding box coordinates (N,S,E,W,T,B)</td></tr>
  719. <tr><td>plus->n_nodes, plus->n_lines, etc.</td><td>I</td><td>7</td><td>Number of
  720. nodes, edges, lines, areas, isles, volumes and holes</td></tr>
  721. <tr><td>plus->n_plines, plus->n_llines, etc.</td><td>I</td><td>7</td><td>Number of
  722. points, lines, boundaries, centroids, faces and kernels</td></tr>
  723. <tr><td>plus->Node_offset, plus->Edge_offset,
  724. etc.</td><td>L</td><td>7</td><td>Offset value for nodes, edges, lines,
  725. areas, isles, volumes and holes</td></tr>
  726. <tr><td>plus->coor_size</td><td>L</td><td>1</td><td>File size</td></tr>
  727. </table>
  728. \subsubsection vlibTopoFileBody Body (nodes, lines, areas, isles)
  729. <b>Nodes</b>
  730. For each node (n_nodes):
  731. <table border="1" style="border-collapse: collapse">
  732. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  733. <tr><td>n_lines</td><td>I</td><td>1</td><td>Number of lines (0 for dead node)</td></tr>
  734. <tr><td>lines</td><td>I</td><td>n_lines</td><td>Line ids</td></tr>
  735. <tr><td>angles</td><td>D</td><td>n_lines</td><td>Angle value</td></tr>
  736. <tr><td>n_edges</td><td>I</td><td>1</td><td>Reserved for edges (only for with_z)</td></tr>
  737. <tr><td>x,y</td><td>D</td><td>2</td><td>Coordinate pair</td></tr>
  738. <tr><td>z</td><td>D</td><td>1</td><td>Only for with_z</td></tr>
  739. </table>
  740. \code
  741. struct P_node
  742. {
  743. double x; /* X coordinate */
  744. double y; /* Y coordinate */
  745. double z; /* Z coordinate */
  746. plus_t alloc_lines; /* allocated space for lines */
  747. plus_t n_lines; /* number of attached lines (size of
  748. lines, angle). If 0, then is
  749. degenerate node, for snappingi ???
  750. */
  751. plus_t *lines; /* list of connected lines */
  752. float *angles; /* respected angles; angles for
  753. lines/boundaries are in radians
  754. between -PI and PI. Value for
  755. points or lines with identical
  756. points (degenerated) is set to
  757. -9. */
  758. };
  759. \endcode
  760. <b>Lines</b>
  761. For each line (n_lines):
  762. <table border="1" style="border-collapse: collapse">
  763. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  764. <tr><td>feature type</td><td>C</td><td>1</td><td>0 for dead</td></tr>
  765. <tr><td>offset</td><td>L</td><td>1</td><td>Line offset</td></tr>
  766. <tr><td>N1</td><td>I</td><td>1</td><td>First node id (only if feature type is GV_POINTS, GV_LINES or GV_KERNEL)</td></tr>
  767. <tr><td>N2</td><td>I</td><td>1</td><td>Second node id (only if feature type is GV_LINE or GV_BOUNDARY)</td></tr>
  768. <tr><td>left</td><td>I</td><td>1</td><td>Left area id for feature type GV_BOUNDARY / Area id for feature type GV_CENTROID</td></tr>
  769. <tr><td>right</td><td>I</td><td>1</td><td>Right area id (for feature type GV_BOUNDARY)</td></tr>
  770. <tr><td>vol</td><td>I</td><td>1</td><td>Reserved for kernel (volume number, for feature type GV_KERNEL)</td></tr>
  771. <tr><td>N,S,E,W</td><td>D</td><td>4</td><td>Line bounding box (for feature type GV_LINE, GV_BOUNDARY or GV_FACE)</td></tr>
  772. <tr><td>T,B</td><td>D</td><td>2</td><td>Line bounding box for 3D (only if with_z=1)</td></tr>
  773. </table>
  774. \code
  775. struct P_line
  776. {
  777. plus_t N1; /* start node */
  778. plus_t N2; /* end node */
  779. plus_t left; /* area/isle number to left, negative
  780. for isle area number for centroid,
  781. negative for duplicate centroid
  782. */
  783. plus_t right; /* area/isle number to right, negative
  784. * for isle */
  785. double N; /* line bounding Box */
  786. double S;
  787. double E;
  788. double W;
  789. double T; /* top */
  790. double B; /* bottom */
  791. off_t offset; /* offset in coor file for line */
  792. int type; /* line type */
  793. };
  794. \endcode
  795. <b>Areas</b>
  796. For each area (n_areas):
  797. <table border="1" style="border-collapse: collapse">
  798. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  799. <tr><td>n_lines</td><td>I</td><td>1</td><td>number of boundaries</td></tr>
  800. <tr><td>lines</td><td>I</td><td>n_lines</td><td>Line ids</td></tr>
  801. <tr><td>n_isles</td><td>I</td><td>1</td><td>Number of isles</td></tr>
  802. <tr><td>isles</td><td>I</td><td>n_isles</td><td>Isle ids</td></tr>
  803. <tr><td>centroid</td><td>I</td><td>1</td><td>Centroid id</td></tr>
  804. <tr><td>N,S,E,W</td><td>D</td><td>4</td><td>Area bounding box</td></tr>
  805. <tr><td>T,B</td><td>D</td><td>2</td><td>Area bounding box for 3D (only if with_z=1)</td></tr>
  806. </table>
  807. \code
  808. struct P_area
  809. {
  810. double N; /* area bounding Box */
  811. double S;
  812. double E;
  813. double W;
  814. double T; /* top */
  815. double B; /* bottom */
  816. plus_t n_lines; /* number of boundary lines */
  817. plus_t alloc_lines; /* allocated space */
  818. plus_t *lines; /* list of boundary lines, negative
  819. means direction N2 to N1, lines are
  820. in clockwise order */
  821. /********* Above this line is compatible with P_isle **********/
  822. plus_t centroid; /* number of first centroid within area */
  823. plus_t n_isles; /* number of islands inside */
  824. plus_t alloc_isles;
  825. plus_t *isles; /* 1st generation interior islands */
  826. };
  827. \endcode
  828. <b>Isles</b>
  829. For each isle (n_isle):
  830. <table border="1" style="border-collapse: collapse">
  831. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  832. <tr><td>n_lines</td><td>I</td><td>1</td><td>number of boundaries</td></tr>
  833. <tr><td>lines</td><td>I</td><td>n_lines</td><td>Line ids</td></tr>
  834. <tr><td>area</td><td>I</td><td>1</td><td>Outer area id</td></tr>
  835. <tr><td>N,S,E,W</td><td>D</td><td>4</td><td>Isle bounding box</td></tr>
  836. <tr><td>T,B</td><td>D</td><td>2</td><td>Isle bounding box for 3D (only if with_z=1)</td></tr>
  837. </table>
  838. \code
  839. struct P_isle
  840. {
  841. double N; /* isle bounding Box */
  842. double S;
  843. double E;
  844. double W;
  845. double T; /* top */
  846. double B; /* bottom */
  847. plus_t n_lines; /* number of boundary lines */
  848. plus_t alloc_lines;
  849. plus_t *lines; /* list of boundary lines, negative
  850. means direction N2 to N1, lines are
  851. in counter clockwise order */
  852. /********* Above this line is compatible with P_area **********/
  853. plus_t area; /* area it exists w/in, if any */
  854. };
  855. \endcode
  856. \subsection vlibTopoLevels Topology levels
  857. The vector library defines more <i>topology levels</i> (only for level
  858. of access 2):
  859. \code
  860. #define GV_BUILD_NONE 0
  861. #define GV_BUILD_BASE 1
  862. #define GV_BUILD_AREAS 2
  863. #define GV_BUILD_ATTACH_ISLES 3
  864. #define GV_BUILD_CENTROIDS 4
  865. #define GV_BUILD_ALL GV_BUILD_CENTROIDS
  866. \endcode
  867. GV_BOUNDARY contains geometry and it is used to build areas.
  868. GV_LINE cannot form an area.
  869. \subsection vlibTopoExamples Topology examples
  870. \subsubsection vlibTopoExample1 Topology Example 1
  871. A polygon may be formed by many boundaries (more primitives but connected).
  872. One boundary is shared by adjacent areas.
  873. \verbatim
  874. +--1--+--5--+
  875. | | |
  876. 2 A 4 B 6
  877. | | |
  878. +--3--+--7--+
  879. 1,2,3,4,5,6,7 = 7 boundaries (primitives)
  880. A,B = 2 areas
  881. \endverbatim
  882. \subsubsection vlibTopoExample2 Topology Example 2
  883. This is handled correctly in GRASS: A can be filled, B filled differently.
  884. \verbatim
  885. +---------+
  886. | A |
  887. +-----+ |
  888. | B | |
  889. +-----+ |
  890. | |
  891. +---------+
  892. \endverbatim
  893. In GRASS, whenever an 'inner' ring touches the boundary of an outside
  894. area, even in one point, it is no longer an 'inner' ring (Isle in
  895. GRASS topology), it is simply another area. A, B above can never be
  896. exported from GRASS as polygon A with inner ring B because there are
  897. only 2 areas A and B and one island formed by A and B together.
  898. \subsubsection vlibTopoExample3 Topology Example 3
  899. This is handled correctly in GRASS: Areas A1, A2, and A3 can be filled differently.
  900. \verbatim
  901. +---------------------+
  902. | A1 |
  903. + +------+------+ |
  904. | | A2 | A3 | |
  905. + +------+------+ |
  906. | I1 |
  907. +---------------------+
  908. \endverbatim
  909. In GRASS, whenever an 'inner' ring does not touch the boundary of an
  910. outside area, also not in one point, it is an 'inner' ring (Isle). The
  911. areas A2 and A3 form a single Isle I1 located within area A1. The size
  912. of Isle I1 is substracted from the size of Area A1 when calculating
  913. the size of Area A1. Any centroids falling into Isle I1 are excluded
  914. when searching for a centroid that can be attached to Area A1. A1
  915. above can be exported from GRASS as polygon A1 with inner ring I1.
  916. \subsubsection vlibTopoExample4 Topology Example 4
  917. v.in.ogr/v.clean can identify dangles and change the type from boundary
  918. to line (in TIGER data for example).
  919. Distinction between line and boundary isn't important only for dangles. Example:
  920. \verbatim
  921. +-----+-----+
  922. | . |
  923. | . |
  924. +.....+.....+
  925. | . |
  926. | x . |
  927. +-----+-----+
  928. ---- road + boundary of one parcel => type boundary
  929. .... road => type line
  930. x parcel centroid (identifies whole area)
  931. \endverbatim
  932. Because lines are not used to build areas, we have only one
  933. area/centroid, instead of 4 which would be necessary in TIGER.
  934. \subsection vlibTopoMemory Topology memory management
  935. Topology is generated for all kinds of vector types. Memory is not
  936. released by default. The programmer can force the library to release
  937. the memory by using Vect_set_release_support(). But: The programmer
  938. cannot run Vect_set_release_support() in mid process because all
  939. vectors are needed in the spatial index, which is needed to build topology.
  940. Topology is also necessary for points in case of a vector network
  941. because the graph is built using topology information about lines
  942. and points.
  943. The topology structure does not only store the topology but also
  944. the 'line' bounding box and line offset in coor file (index).
  945. The existing spatial index is using line ID in 'topology' structure
  946. to identify lines in 'coor' file. Currently it is not possible to build
  947. spatial index without topology.
  948. \section vlibSpidx Vector library spatial index management
  949. Spatial index (based on R-tree) is created with topology.
  950. Spatial index occupies a lot of memory but it is necessary for
  951. topology building. Also, it takes a long time to release the memory
  952. occupied by spatial index (dig_spidx_free()).
  953. The function building topology (Vect_build()) is usually called
  954. at the end of modules (before Vect_close()) so it is faster to call
  955. exit() and operating system releases all the memory much faster.
  956. By default the memory is not released.
  957. It is possible to call Vect_set_release_support() before Vect_close()
  958. to enforce memory release, but it takes a long time on large files.
  959. The spatial index is stored in file and not loaded for old vectors that
  960. are not updated, saving a lot of memory. Spatial queries are done in
  961. file.
  962. Currently most of the modules do not release the memory occupied for
  963. spatial index and work like this (pseudocode):
  964. \code
  965. int main
  966. {
  967. Vect_open_new();
  968. /* writing new vector */
  969. Vect_build();
  970. Vect_close(); /* memory is not released */
  971. }
  972. \endcode
  973. In general it is possible to free the memory with Vect_set_release_support()
  974. such as:
  975. \code
  976. int main
  977. {
  978. Vect_open_new();
  979. /* writing new vector */
  980. Vect_build();
  981. Vect_set_release_support();
  982. Vect_close(); /* memory is released */
  983. }
  984. \endcode
  985. but it takes longer.
  986. It makes sense to release the spatial index if it is used only at the beginning
  987. of a module or in permanently running programs like QGIS. Note that this
  988. applies only when creating a new vector or updating an old vector.
  989. For example:
  990. \code
  991. int main
  992. {
  993. Vect_open_update();
  994. /* select features using spatial index, e.g. Vect_select_lines_by_box() */
  995. Vect_set_release_support();
  996. Vect_close(); /* memory is released */
  997. /* do some processing which needs memory */
  998. }
  999. \endcode
  1000. \subsection vlibSidxFileFormat Sidx file format specification
  1001. Spatial index file ('sidx') is read by Vect_open_sidx().
  1002. \subsubsection vlibSidxFileHead Header
  1003. Note: <tt>plus</tt> is instance of <tt>Plus_head</tt> structure.
  1004. <table border="1" style="border-collapse: collapse">
  1005. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  1006. <tr><td>plus->spidx_Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
  1007. <tr><td>plus->spidx_Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
  1008. <tr><td>plus->spidx_Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
  1009. <tr><td>plus->spidx_Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
  1010. <tr><td>plus->spidx_port->byte_order</td><td>C</td><td>1</td><td>little or big endian
  1011. flag; files are written in machine native order but
  1012. files in both little and big endian order may be
  1013. readl; zero for little endian</td></tr>
  1014. <tr><td>plus->spidx_port.off_t_size</td><td>C</td><td>1</td><td>off_t size (LFS)</td></tr>
  1015. <tr><td>plus->spidx_head_size</td><td>L</td><td>1</td><td>header size</td></tr>
  1016. <tr><td>plus->spidx_with_z</td><td>C</td><td>1</td><td>2D/3D vector data</td></tr>
  1017. <tr><td>ndims</td><td>C</td><td>1</td><td>Number of dimensions</td></tr>
  1018. <tr><td>nsides</td><td>C</td><td>1</td><td>Number of sides</td></tr>
  1019. <tr><td>nodesize</td><td>I</td><td>1</td><td>Node size</td></tr>
  1020. <tr><td>nodecard</td><td>I</td><td>1</td><td>Node card (?)</td></tr>
  1021. <tr><td>leafcard</td><td>I</td><td>1</td><td>Leaf card (?)</td></tr>
  1022. <tr><td>min_node_fill</td><td>I</td><td>1</td><td>Minimum node fill (?)</td></tr>
  1023. <tr><td>min_leaf_fill</td><td>I</td><td>1</td><td>Minimum leaf fill (?)</td></tr>
  1024. <tr><td>plus->Node_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
  1025. <tr><td>plus->Node_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
  1026. <tr><td>plus->Node_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
  1027. <tr><td>plus->Node_spidx_offset</td><td>O</td><td>1</td><td>Node offset</td></tr>
  1028. <tr><td>plus->Line_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
  1029. <tr><td>plus->Line_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
  1030. <tr><td>plus->Line_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
  1031. <tr><td>plus->Line_spidx_offset</td><td>O</td><td>1</td><td>Line offset</td></tr>
  1032. <tr><td>plus->Area_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
  1033. <tr><td>plus->Area_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
  1034. <tr><td>plus->Area_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
  1035. <tr><td>plus->Area_spidx_offset</td><td>O</td><td>1</td><td>Area offset</td></tr>
  1036. <tr><td>plus->Isle_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
  1037. <tr><td>plus->Isle_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
  1038. <tr><td>plus->Isle_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
  1039. <tr><td>plus->Isle_spidx_offset</td><td>O</td><td>1</td><td>Isle offset</td></tr>
  1040. <tr><td>plus->Face_spidx_offset</td><td>O</td><td>1</td><td>Face offset</td></tr>
  1041. <tr><td>plus->Volume_spidx_offset</td><td>O</td><td>1</td><td>Volume offset</td></tr>
  1042. <tr><td>plus->Hole_spidx_offset</td><td>O</td><td>1</td><td>Hole offset</td></tr>
  1043. <tr><td>plus->coor_size</td><td>O</td><td>1</td><td>Coor file size</td></tr>
  1044. </table>
  1045. \section vlibCidx Vector library category index management
  1046. The category index (stored in the cidx file) improves the performance of all
  1047. selections by cats/attributes (SQL, e.g. 'd.vect cats=27591', 'v.extract list=20000-21000').
  1048. This avoids that all selections have to be made by looping through all vector lines.
  1049. Category index is also essential for simple feature representation of GRASS vectors.
  1050. Category index is created for each field. In memory, it is stored in
  1051. \code
  1052. struct Cat_index
  1053. {
  1054. int field; /* field number */
  1055. int n_cats; /* number of items in cat array */
  1056. int a_cats; /* allocated space in cat array */
  1057. int (*cat)[3]; /* array of cats (cat, type, lines/area) */
  1058. int n_ucats; /* number of unique cats (not updated) */
  1059. int n_types; /* number of types in type */
  1060. int type[7][2]; /* number of elements for each type
  1061. * (point, line, boundary, centroid,
  1062. * area, face, kernel) */
  1063. off_t offset; /* offset of the beginning of this
  1064. * index in cidx file */
  1065. };
  1066. \endcode
  1067. Category index is built with topology, but it is <b>not updated</b> if vector is edited on level 2.
  1068. Category index is stored in 'cidx' file, 'cat' array is written/read by one call of
  1069. dig__fwrite_port_I( (int *)ci->cat, 3 * ci->n_cats, fp) or
  1070. dig__fread_port_I( (int *)ci->cat, 3 * ci->n_cats, fp).
  1071. Stored values can be retrieved either by index in 'cat' array
  1072. (if all features of given field are required) or by category value
  1073. (one or few features), always by Vect_cidx_*() functions.
  1074. To create category index, it will be necessary to rebuild topology for all existing vectors.
  1075. This is an opportunity to make (hopefully) last changes in 'topo', 'cidx' formats.
  1076. \subsection vlibCidxFileFormat Cidx file format specification
  1077. Category index file ('cidx') is read by Vect_cidx_open().
  1078. \subsubsection vlibCidxFileHead Header
  1079. Note: <tt>plus</tt> is instance of <tt>Plus_head</tt> structure.
  1080. <table border="1" style="border-collapse: collapse">
  1081. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  1082. <tr><td>plus->cpidx_Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
  1083. <tr><td>plus->cpidx_Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
  1084. <tr><td>plus->cpidx_Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
  1085. <tr><td>plus->cpidx_Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
  1086. <tr><td>plus->cidx_port->byte_order</td><td>C</td><td>1</td><td>little or big endian
  1087. flag; files are written in machine native order but
  1088. files in both little and big endian order may be
  1089. readl; zero for little endian</td></tr>
  1090. <tr><td>plus->cidx_head_size</td><td>L</td><td>1</td><td>cidx head size</td></tr>
  1091. <tr><td>plus->n_cidx</td><td>I</td><td>1</td><td>number of fields</td></tr>
  1092. <tr><td>field</td><td>I</td><td>n_cidx</td><td>field number</td></tr>
  1093. <tr><td>n_cats</td><td>I</td><td>n_cidx</td><td>number of categories</td></tr>
  1094. <tr><td>n_ucats</td><td>I</td><td>n_cidx</td><td>number of unique categories</td></tr>
  1095. <tr><td>n_types</td><td>I</td><td>n_cidx</td><td>number of feature types</td></tr>
  1096. <tr><td>rtype</td><td>I</td><td>n_cidx * n_types</td><td>Feature type</td></tr>
  1097. <tr><td>type[t]</td><td>I</td><td>n_cidx * n_types</td><td>Number of items</td></tr>
  1098. </table>
  1099. \section vlibTin Vector TINs
  1100. TINs are simply created as 2D/3D vector polygons consisting of
  1101. 3 vertices. See Vect_tin_get_z().
  1102. \section vlibOgrIface OGR interface
  1103. \subsection vLibPseudoTopo Pseudo-topology
  1104. Reduced topology: each boundary is attached to one area only,
  1105. i.e. smoothing, simplification, removing small areas etc. will not
  1106. work properly for adjacent areas or areas within areas.
  1107. Full topology is only available for native GRASS vectors or can only
  1108. be built after all polygons are cleaned as done by <tt>v.in.ogr</tt>.
  1109. \subsection vlibFrmtFileFormat Frmt file format specification
  1110. Frmt is a plain text file which contains basic information about
  1111. external format of linked vector map. Each line contains key, value
  1112. pairs separated by comma.
  1113. OGR specific format is described by:
  1114. - FORMAT - ogr
  1115. - DSN - datasource name
  1116. - LAYER - OGR layer name
  1117. Example:
  1118. \verbatim
  1119. FORMAT: ogr
  1120. DSN: /home/martin/src/grass_trunk
  1121. LAYER: p
  1122. \endverbatim
  1123. OGR layer can be linked via <tt>v.external</tt> command. When linking
  1124. OGR layer pseudo-topology ('topo') is built including spatial index
  1125. file ('sidx') and category index file ('cidx'). Additionally also
  1126. feature index file (see \ref vlibFidxFileFormat) is created.
  1127. \subsection vlibFidxFileFormat Fidx file format specification
  1128. Note: <tt>finfo</tt> is an instance of <tt>Format_info</tt> structure.
  1129. <table border="1" style="border-collapse: collapse">
  1130. <tr><td>Name</td><td>Type</td><td>Number</td><td>Description</td></tr>
  1131. <tr><td>Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
  1132. <tr><td>Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
  1133. <tr><td>Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
  1134. <tr><td>Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
  1135. <tr><td>byte_order</td><td>C</td><td>1</td><td>little or big endian
  1136. flag; files are written in machine native order but
  1137. files in both little and big endian order may be
  1138. readl; zero for little endian</td></tr>
  1139. <tr><td>length</td><td>L</td><td>1</td><td>header size</td></tr>
  1140. <tr><td>fInfo.ogr.offset_num</td><td>I</td><td>1</td><td>number of records</td></tr>
  1141. <tr><td>fInfo.ogr.offset</td><td>I</td><td>offset_num</td><td>offsets</td></tr>
  1142. </table>
  1143. \section vlibDglib DGLib (Directed Graph Library)
  1144. <b>The Directed Graph Library</b> or DGLib (Micarelli 2002, \ref dglib ,
  1145. http://grass.osgeo.org/dglib/) provides functionality for vector network
  1146. analysis. This library released under GPL is hosted by the GRASS
  1147. project (within the GRASS source code). As a stand-alone library it
  1148. may also be used by other software projects.
  1149. The Directed Graph Library library provides functionality to assign costs to
  1150. lines and/or nodes. That means that costs can be accumulated while traveling
  1151. along polylines. The user can assign individual costs to all lines and/or
  1152. nodes of a vector map and later calculate shortest path connections based on
  1153. the accumulated costs. Applications are transport analysis, connectivity and
  1154. more. Implemented applications cover shortest path, traveling salesman (round trip),
  1155. allocation of sources (creation of subnetworks), minimum Steiner trees
  1156. (star-like connections), and iso-distances (from centers).
  1157. For details, please read Blazek et al. 2002 (see below).
  1158. Related vector functions are:
  1159. Vect_graph_add_edge(),
  1160. Vect_graph_init(),
  1161. Vect_graph_set_node_costs(),
  1162. Vect_graph_shortest_path(),
  1163. Vect_net_build_graph(),
  1164. Vect_net_nearest_nodes(),
  1165. Vect_net_shortest_path(), and
  1166. Vect_net_shortest_path_coor().
  1167. \section vlibAscii Vector ASCII Format Specifications
  1168. The GRASS ASCII vector map format may contain a mix of primitives
  1169. including points, lines, boundaries, centroids, faces, and
  1170. kernels. The format may also contain a header with various metadata
  1171. (see example below).
  1172. Vector map can be converted to the ASCII representation at user level
  1173. by <tt>v.out.ascii format=standard</tt> command.
  1174. See \ref vlibAsciiFn for list of related functions.
  1175. The header is similar as the head file of vector binary format (see
  1176. \ref vlibHeadFileFormat) but contains bounding box also. Keywords are:
  1177. \verbatim
  1178. ORGANIZATION
  1179. DIGIT DATE
  1180. DIGIT NAME
  1181. MAP NAME
  1182. MAP DATE
  1183. MAP SCALE
  1184. OTHER INFO
  1185. ZONE
  1186. WEST EDGE
  1187. EAST EDGE
  1188. SOUTH EDGE
  1189. NORTH EDGE
  1190. MAP THRESH
  1191. \endverbatim
  1192. Example:
  1193. \verbatim
  1194. ORGANIZATION: NC OneMap
  1195. DIGIT DATE:
  1196. DIGIT NAME: helena
  1197. MAP NAME: North Carolina selected bridges (points map)
  1198. MAP DATE: Mon Nov 6 15:32:39 2006
  1199. MAP SCALE: 1
  1200. OTHER INFO:
  1201. ZONE: 0
  1202. MAP THRESH: 0.000000
  1203. \endverbatim
  1204. The body begins with the row:
  1205. \verbatim
  1206. VERTI:
  1207. \endverbatim
  1208. followed by records of primitives:
  1209. \verbatim
  1210. TYPE NUMBER_OF_COORDINATES [NUMBER_OF_CATEGORIES]
  1211. X Y [Z]
  1212. ....
  1213. X Y [Z]
  1214. [ LAYER CATEGORY]
  1215. ....
  1216. [ LAYER CATEGORY]
  1217. \endverbatim
  1218. Everything above in <tt>[]</tt> is optional.
  1219. The primitive codes are as follows:
  1220. - 'P': point
  1221. - 'L': line
  1222. - 'B': boundary
  1223. - 'C': centroid
  1224. - 'F': face (3D boundary)
  1225. - 'K': kernel (3D centroid)
  1226. - 'A': area (boundary) - better use 'B'; kept only for backward
  1227. compatibility
  1228. The coordinates are listed following the initial line containing the
  1229. primitive code, the total number of vectors in the series, and (optionally)
  1230. the number of categories (1 for a single layer, higher for multiple layers).
  1231. Below that 1 or several lines follow to indicate the layer number and
  1232. the category number (ID).
  1233. The order of coordinates is
  1234. \verbatim
  1235. X Y [Z]
  1236. \endverbatim
  1237. Note: The points are stored as y, x (i.e., east, north), which is the
  1238. reserve of the way GRASS usually represents geographic coordinates.
  1239. Example:
  1240. \verbatim
  1241. P 1 1
  1242. 375171.4992779 317756.72097616
  1243. 1 1
  1244. B 5
  1245. 637740 219580
  1246. 639530 219580
  1247. 639530 221230
  1248. 637740 221230
  1249. 637740 219580
  1250. C 1 1
  1251. 638635 220405
  1252. 1 2
  1253. \endverbatim
  1254. In this example, the first vector feature is a point with category
  1255. number 1. The second vector feature is a boundary composed by 5
  1256. points. The third feature is a centroid with category number 2. The
  1257. boundary and the centroid form an area with category number 2. All
  1258. vector feature mentioned above are located in layer 1.
  1259. \section vlibFunc List of vector library functions
  1260. The vector library provides the GRASS programmer with routines to
  1261. process vector data. The routines in the vector library are presented
  1262. in functional groupings, rather than in alphabetical order. The order
  1263. of presentation will, it is hoped, provide better understanding of how
  1264. the library is to be used, as well as show the interrelationships
  1265. among the various routines. Note that a good way to understand how to
  1266. use these routines is to look at the source code for GRASS modules
  1267. which use them.
  1268. Note: All routines start with one of following prefixes Vect_, V1_,
  1269. V2_ or dig_. To avoid name conficts, programmers should not create
  1270. variables or routines in their own modules which use this prefix.
  1271. The Vect_*() functions are the programmer's API for GRASS vector
  1272. programming. The programmer should use only routines with this prefix.
  1273. - \subpage vlibArea
  1274. - \subpage vlibArray
  1275. - \subpage vlibBox
  1276. - \subpage vlibBreakLines
  1277. - \subpage vlibBreakPolygons
  1278. - \subpage vlibBridges
  1279. - \subpage vlibBuffer
  1280. - \subpage vlibBuild
  1281. - \subpage vlibBuildNat
  1282. - \subpage vlibBuildOgr
  1283. - \subpage vlibCats
  1284. - \subpage vlibCindex
  1285. - \subpage vlibCleanNodes
  1286. - \subpage vlibClose
  1287. - \subpage vlibConstraint
  1288. - \subpage vlibDangles
  1289. - \subpage vlibDbcolumns
  1290. - \subpage vlibError
  1291. - \subpage vlibField
  1292. - \subpage vlibFind
  1293. - \subpage vlibGraph
  1294. - \subpage vlibHeader
  1295. - \subpage vlibHist
  1296. - \subpage vlibInitHead
  1297. - \subpage vlibIntersect
  1298. - \subpage vlibLegalVname
  1299. - \subpage vlibLevel
  1300. - \subpage vlibLevelTwo
  1301. - \subpage vlibLine
  1302. - \subpage vlibList
  1303. - \subpage vlibMap
  1304. - \subpage vlibNet
  1305. - \subpage vlibOpen
  1306. - \subpage vlibOverlay
  1307. - \subpage vlibVpoly
  1308. - \subpage vlibRead
  1309. - \subpage vlibRemoveAreas
  1310. - \subpage vlibRemoveDuplicates
  1311. - \subpage vlibRewind
  1312. - \subpage vlibSelect
  1313. - \subpage vlibSindex
  1314. - \subpage vlibSnap
  1315. - \subpage vlibTin
  1316. - \subpage vlibType
  1317. - \subpage vlibDelete
  1318. - \subpage vlibWrite
  1319. - \subpage vlibAsciiFn
  1320. - \subpage vlibSFAFn
  1321. - \subpage vlibGeosFn
  1322. \section vlibArea Vector area functions
  1323. - Vect_get_area_area()
  1324. - Vect_get_area_boundaries()
  1325. - Vect_get_area_centroid()
  1326. - Vect_get_area_isle()
  1327. - Vect_get_area_num_isles()
  1328. - Vect_area_perimeter()
  1329. - Vect_get_area_points()
  1330. - Vect_get_isle_area()
  1331. - Vect_get_isle_boundaries()
  1332. - Vect_get_isle_points()
  1333. - Vect_point_in_area()
  1334. \section vlibArray Vector array functions
  1335. - Vect_new_varray()
  1336. - Vect_set_varray_from_cat_list()
  1337. - Vect_set_varray_from_cat_string()
  1338. - Vect_set_varray_from_db()
  1339. \section vlibBox Vector bounding box functions
  1340. - Vect_box_copy()
  1341. - Vect_box_clip()
  1342. - Vect_box_extend()
  1343. - Vect_box_overlap()
  1344. - Vect_get_area_box()
  1345. - Vect_get_isle_box()
  1346. - Vect_get_line_box()
  1347. - Vect_get_map_box()
  1348. - Vect_point_in_box()
  1349. - Vect_region_box()
  1350. \section vlibBreakLines Vector break lines functions
  1351. - Vect_break_lines()
  1352. - Vect_break_lines_list()
  1353. \section vlibBreakPolygons Vector break polygons functions
  1354. - Vect_break_polygons()
  1355. \section vlibBridges Vector bridges functions
  1356. - Vect_chtype_bridges()
  1357. - Vect_remove_bridges()
  1358. \section vlibBuffer Vector buffer functions
  1359. - Vect_line_buffer()
  1360. - Vect_line_parallel()
  1361. \section vlibBuild Vector build functions
  1362. - Vect_build()
  1363. - Vect_build_partial()
  1364. - Vect_get_built()
  1365. - Vect_build_sidx_from_topo()
  1366. - Vect_build_sidx()
  1367. - Vect_save_sidx()
  1368. - Vect_save_topo()
  1369. - Vect_sidx_dump()
  1370. - Vect_topo_dump()
  1371. \subsection vlibBuildNat Vector build (native) functions
  1372. - Vect_attach_centroids()
  1373. - Vect_attach_isle()
  1374. - Vect_attach_isles()
  1375. - Vect_build_line_area()
  1376. - Vect_build_nat()
  1377. - Vect_isle_find_area()
  1378. \subsection vlibBuildOgr Vector build (OGR) functions
  1379. - Vect_build_ogr()
  1380. \section vlibCats Vector categories functions
  1381. - Vect_array_to_cat_list()
  1382. - Vect_cat_del()
  1383. - Vect_cat_get()
  1384. - Vect_cat_in_array()
  1385. - Vect_cat_in_cat_list()
  1386. - Vect_cat_set()
  1387. - Vect_destroy_cat_list()
  1388. - Vect_destroy_cats_struct()
  1389. - Vect_field_cat_del()
  1390. - Vect_get_area_cats()
  1391. - Vect_get_area_cat()
  1392. - Vect_get_line_cat()
  1393. - Vect_new_cat_list()
  1394. - Vect_new_cats_struct()
  1395. - Vect_reset_cats()
  1396. - Vect_str_to_cat_list()
  1397. \section vlibCindex Vector category index functions
  1398. (note: vector layer is historically called "field")
  1399. - Vect_cidx_dump()
  1400. - Vect_cidx_find_next()
  1401. - Vect_cidx_find_all()
  1402. - Vect_cidx_get_cat_by_index()
  1403. - Vect_cidx_get_field_index()
  1404. - Vect_cidx_get_field_number()
  1405. - Vect_cidx_get_num_cats_by_index()
  1406. - Vect_cidx_get_num_fields()
  1407. - Vect_cidx_get_num_types_by_index()
  1408. - Vect_cidx_get_num_unique_cats_by_index()
  1409. - Vect_cidx_get_type_count()
  1410. - Vect_cidx_get_type_count_by_index()
  1411. - Vect_cidx_open()
  1412. - Vect_cidx_save()
  1413. - Vect_set_category_index_update()
  1414. \section vlibCleanNodes Vector clean nodes functions
  1415. - Vect_clean_small_angles_at_nodes()
  1416. \section vlibClose Vector close functions
  1417. - Vect_close()
  1418. \section vlibConstraint Vector constraint functions
  1419. - Vect_get_constraint_box()
  1420. - Vect_remove_constraints()
  1421. - Vect_set_constraint_region()
  1422. - Vect_set_constraint_type()
  1423. \section vlibDangles Vector dangles functions
  1424. - Vect_chtype_dangles()
  1425. - Vect_remove_dangles()
  1426. - Vect_select_dangles()
  1427. \section vlibDbcolumns Vector dbcolumns functions
  1428. - Vect_get_column_names()
  1429. - Vect_get_column_names_types()
  1430. - Vect_get_column_types()
  1431. \section vlibError Vector error functions
  1432. - Vect_get_fatal_error()
  1433. - Vect_set_fatal_error()
  1434. \section vlibField Vector field functions
  1435. (note: vector layer is historically called "field")
  1436. - Vect_add_dblink()
  1437. - Vect_check_dblink()
  1438. - Vect_default_field_info()
  1439. - Vect_get_dblink()
  1440. - Vect_get_field()
  1441. - Vect_get_field_by_name()
  1442. - Vect_map_add_dblink()
  1443. - Vect_map_check_dblink()
  1444. - Vect_map_del_dblink()
  1445. - Vect_new_dblinks_struct()
  1446. - Vect_read_dblinks()
  1447. - Vect_reset_dblinks()
  1448. - Vect_set_db_updated()
  1449. - Vect_subst_var()
  1450. - Vect_write_dblinks()
  1451. \section vlibFind Vector find functions
  1452. - Vect_find_area()
  1453. - Vect_find_island()
  1454. - Vect_find_line()
  1455. - Vect_find_line_list()
  1456. - Vect_find_node()
  1457. \section vlibGraph Vector graph functions
  1458. - Vect_graph_add_edge()
  1459. - Vect_graph_build()
  1460. - Vect_graph_init()
  1461. - Vect_graph_set_node_costs()
  1462. - Vect_graph_shortest_path()
  1463. \section vlibHeader Vector header functions
  1464. - Vect_get_comment()
  1465. - Vect_get_constraint_box()
  1466. - Vect_get_date()
  1467. - Vect_get_full_name()
  1468. - Vect_get_map_date()
  1469. - Vect_get_map_name()
  1470. - Vect_get_mapset()
  1471. - Vect_get_name()
  1472. - Vect_get_organization()
  1473. - Vect_get_person()
  1474. - Vect_get_proj()
  1475. - Vect_get_proj_name()
  1476. - Vect_get_scale()
  1477. - Vect_get_thresh()
  1478. - Vect_get_zone()
  1479. - Vect_is_3d()
  1480. - Vect_print_header()
  1481. - Vect_read_header()
  1482. - Vect_set_comment()
  1483. - Vect_set_date()
  1484. - Vect_set_map_date()
  1485. - Vect_set_map_name()
  1486. - Vect_set_organization()
  1487. - Vect_set_person()
  1488. - Vect_set_scale()
  1489. - Vect_set_thresh()
  1490. - Vect_set_zone()
  1491. - Vect_write_header()
  1492. \section vlibHist Vector history functions
  1493. - Vect_hist_command()
  1494. - Vect_hist_copy()
  1495. - Vect_hist_read()
  1496. - Vect_hist_rewind()
  1497. - Vect_hist_write()
  1498. \section vlibInitHead Vector header functions
  1499. - Vect_copy_head_data()
  1500. \section vlibIntersect Vector intersection functions
  1501. - Vect_line_check_intersection()
  1502. - Vect_line_intersection()
  1503. - Vect_segment_intersection()
  1504. \section vlibLegalVname Vector valid map name functions
  1505. - Vect_check_input_output_name()
  1506. - Vect_legal_filename()
  1507. \section vlibLevel Vector level functions
  1508. - Vect_level()
  1509. \section vlibLevelTwo Vector topological (level 2) functions
  1510. - Vect_get_centroid_area()
  1511. - Vect_get_line_areas()
  1512. - Vect_get_line_nodes()
  1513. - Vect_get_node_coor()
  1514. - Vect_get_node_line()
  1515. - Vect_get_node_line_angle()
  1516. - Vect_get_node_n_lines()
  1517. - Vect_get_num_areas()
  1518. - Vect_get_num_dblinks()
  1519. - Vect_get_num_faces()
  1520. - Vect_get_num_islands()
  1521. - Vect_get_num_lines()
  1522. - Vect_get_num_nodes()
  1523. - Vect_get_num_primitives()
  1524. - Vect_get_num_updated_lines()
  1525. - Vect_get_num_updated_nodes()
  1526. - Vect_get_updated_line()
  1527. - Vect_get_updated_node()
  1528. - Vect_set_release_support()
  1529. \section vlibLine Vector feature functions
  1530. - Vect_append_point()
  1531. - Vect_append_points()
  1532. - Vect_copy_pnts_to_xyz()
  1533. - Vect_copy_xyz_to_pnts()
  1534. - Vect_destroy_line_struct()
  1535. - Vect_get_num_line_points()
  1536. - Vect_line_box()
  1537. - Vect_line_delete_point()
  1538. - Vect_line_distance()
  1539. - Vect_line_geodesic_length()
  1540. - Vect_line_get_point()
  1541. - Vect_line_insert_point()
  1542. - Vect_line_length()
  1543. - Vect_line_prune()
  1544. - Vect_line_prune_thresh()
  1545. - Vect_line_reverse()
  1546. - Vect_line_segment()
  1547. - Vect_new_line_struct()
  1548. - Vect_point_on_line()
  1549. - Vect_points_distance()
  1550. - Vect_reset_line()
  1551. \section vlibList Vector list functions
  1552. - Vect_destroy_list()
  1553. - Vect_list_append()
  1554. - Vect_list_append_list()
  1555. - Vect_list_delete()
  1556. - Vect_list_delete_list()
  1557. - Vect_new_list()
  1558. - Vect_reset_list()
  1559. - Vect_val_in_list()
  1560. \section vlibMap Vector map functions
  1561. - Vect_copy()
  1562. - Vect_copy_map_lines()
  1563. - Vect_copy_table()
  1564. - Vect_copy_table_by_cats()
  1565. - Vect_copy_tables()
  1566. - Vect_delete()
  1567. - Vect_rename()
  1568. \section vlibNet Vector network functions
  1569. - Vect_net_build_graph()
  1570. - Vect_net_get_line_cost()
  1571. - Vect_net_get_node_cost()
  1572. - Vect_net_nearest_nodes()
  1573. - Vect_net_shortest_path()
  1574. - Vect_net_shortest_path_coor()
  1575. \section vlibOpen Vector open functions
  1576. - Vect_coor_info()
  1577. - Vect_maptype_info()
  1578. - Vect_maptype()
  1579. - Vect_open_new()
  1580. - Vect__open_old()
  1581. - Vect_open_old()
  1582. - Vect_open_old_head()
  1583. - Vect_open_sidx()
  1584. - Vect_open_topo()
  1585. - Vect_open_update()
  1586. - Vect_open_update_head()
  1587. - Vect_set_open_level()
  1588. \section vlibOverlay Vector overlay functions
  1589. - Vect_overlay()
  1590. - Vect_overlay_str_to_operator()
  1591. \section vlibVpoly Vector polygon functions
  1592. - Vect_find_poly_centroid()
  1593. - Vect_get_point_in_area()
  1594. - Vect_point_in_area_outer_ring()
  1595. - Vect_point_in_island()
  1596. - Vect_get_point_in_poly()
  1597. - Vect_get_point_in_poly_isl()
  1598. \section vlibRead Vector read functions
  1599. \subsection vlibread1_2 Level 1 and 2
  1600. - Vect_read_next_line()
  1601. \subsection vlibRead2 Level 2 only
  1602. - Vect_area_alive()
  1603. - Vect_isle_alive()
  1604. - Vect_line_alive()
  1605. - Vect_node_alive()
  1606. - Vect_read_line()
  1607. \section vlibRemoveAreas Vector remove areas functions
  1608. - Vect_remove_small_areas()
  1609. \section vlibRemoveDuplicates Vector remove duplicates functions
  1610. - Vect_line_check_duplicate()
  1611. - Vect_remove_duplicates()
  1612. \section vlibRewind Vector rewind functions
  1613. - Vect_rewind()
  1614. \section vlibSelect Vector select functions
  1615. - Vect_select_areas_by_box()
  1616. - Vect_select_areas_by_polygon()
  1617. - Vect_select_isles_by_box()
  1618. - Vect_select_lines_by_box()
  1619. - Vect_select_lines_by_polygon()
  1620. - Vect_select_nodes_by_box()
  1621. \section vlibSindex Vector spatial index functions
  1622. - Vect_spatial_index_add_item()
  1623. - Vect_spatial_index_del_item()
  1624. - Vect_spatial_index_destroy()
  1625. - Vect_spatial_index_init()
  1626. - Vect_spatial_index_select()
  1627. \section vlibSnap Vector snap functions
  1628. - Vect_snap_lines()
  1629. - Vect_snap_lines_list()
  1630. \section vlibTin Vector TIN functions
  1631. - Vect_tin_get_z()
  1632. \section vlibType Vector type option functions
  1633. - Vect_option_to_types()
  1634. \section vlibDelete Vector delete functions
  1635. \subsection vlibDelete2 Level 2 only
  1636. - Vect_delete_line()
  1637. \section vlibWrite Vector write functions
  1638. \subsection vlibWrite1_2 Level 1 and 2
  1639. - Vect_write_line()
  1640. \subsection vlibWrite2 Level 2 only
  1641. - Vect_rewrite_line()
  1642. \subsection vlibAsciiFn Vector ASCII functions
  1643. - Vect_read_ascii()
  1644. - Vect_read_ascii_head()
  1645. - Vect_write_ascii()
  1646. - Vect_write_ascii_head()
  1647. \subsection vlibSFAFn Vector Simple Feature Access API
  1648. Functions from GRASS Simple Feature API (in progress, incomplete).
  1649. - Vect_sfa_get_line_type()
  1650. - Vect_sfa_check_line_type()
  1651. - Vect_sfa_line_dimension()
  1652. - Vect_sfa_line_geometry_type()
  1653. - Vect_sfa_line_astext()
  1654. - Vect_sfa_is_line_simple()
  1655. - Vect_sfa_is_line_closed()
  1656. \section vlibGeosFn Vector GEOS functions
  1657. Note: The functions are available only if GRASS is compiled with
  1658. <tt>--with-geos</tt> switch.
  1659. - Vect_read_line_geos()
  1660. - Vect_read_area_geos()
  1661. - Vect_line_to_geos()
  1662. - Vect_get_area_points_geos()
  1663. - Vect_get_isle_points_geos()
  1664. \section vlibAuthors Authors
  1665. - Radim Blazek (vector architecture) <radim.blazek gmail.com>
  1666. - Roberto Micarelli (DGLib) <mi.ro iol.it>
  1667. Updates for GRASS 7:
  1668. - Markus Metz (file-based spatial index)
  1669. - Martin Landa (GEOS support, direct OGR read access) <landa.martin gmail.com>
  1670. \section vlibReferences References
  1671. Text based on: R. Blazek, M. Neteler, and R. Micarelli. The new GRASS 5.1
  1672. vector architecture. In Open source GIS - GRASS users conference 2002,
  1673. Trento, Italy, 11-13 September 2002. University of Trento, Italy, 2002.
  1674. <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>
  1675. \section vlibSeealso See Also
  1676. - \ref dglib
  1677. - \ref dbmilib
  1678. - \ref veditlib
  1679. Last change: $Date$
  1680. */