level_two.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*!
  2. \file level_two.c
  3. \brief Vector library - topo level
  4. (C) 2001-2008 by the GRASS Development Team
  5. This program is free software under the
  6. GNU General Public License (>=v2).
  7. Read the file COPYING that comes with GRASS
  8. for details.
  9. \author Original author CERL, probably Dave Gerdes or Mike Higgins.
  10. Update to GRASS 5.7 Radim Blazek and David D. Gray.
  11. \date 2001-2008
  12. */
  13. #include <stdlib.h>
  14. #include <grass/gis.h>
  15. #include <grass/Vect.h>
  16. #include <grass/glocale.h>
  17. /*!
  18. \brief Get number of nodes
  19. \param Map vector map
  20. \return number of nodes
  21. */
  22. int
  23. Vect_get_num_nodes (struct Map_info *map)
  24. {
  25. return (map->plus.n_nodes);
  26. }
  27. /*!
  28. \brief Get number of primitives
  29. \param map vector map
  30. \patam type feature type
  31. \return number of primitives of given type
  32. */
  33. int
  34. Vect_get_num_primitives (struct Map_info *map, int type)
  35. {
  36. int num = 0;
  37. if ( type & GV_POINT ) num += map->plus.n_plines;
  38. if ( type & GV_LINE ) num += map->plus.n_llines;
  39. if ( type & GV_BOUNDARY ) num += map->plus.n_blines;
  40. if ( type & GV_CENTROID ) num += map->plus.n_clines;
  41. if ( type & GV_FACE ) num += map->plus.n_flines;
  42. if ( type & GV_KERNEL ) num += map->plus.n_klines;
  43. return num;
  44. }
  45. /*!
  46. \brief Fetch number of line vectors (points, lines, centroids)
  47. \param map vector map
  48. \return number of line vectors
  49. */
  50. int
  51. Vect_get_num_lines (struct Map_info *map)
  52. {
  53. return (map->plus.n_lines);
  54. }
  55. /*!
  56. \brief Get number of areas
  57. \param map vector map
  58. \return number of areas
  59. */
  60. int
  61. Vect_get_num_areas (struct Map_info *map)
  62. {
  63. return (map->plus.n_areas);
  64. }
  65. /*!
  66. \brief Get number of faces
  67. \param map vector map
  68. \return number of faces
  69. */
  70. int
  71. Vect_get_num_faces (struct Map_info *map)
  72. {
  73. return (map->plus.n_flines);
  74. }
  75. /*!
  76. \brief Get number of islands
  77. \param map vector map
  78. \return number of islands
  79. */
  80. int
  81. Vect_get_num_islands (struct Map_info *map)
  82. {
  83. return (map->plus.n_isles);
  84. }
  85. /*!
  86. \brief Get number of defined dblinks
  87. \param map vector map
  88. \return number of dblinks
  89. */
  90. int
  91. Vect_get_num_dblinks (struct Map_info *map)
  92. {
  93. return (map->dblnk->n_fields);
  94. }
  95. /*!
  96. \brief Get number of updated lines
  97. \param map vector map
  98. \return number of updated lines
  99. */
  100. int
  101. Vect_get_num_updated_lines (struct Map_info *map)
  102. {
  103. return (map->plus.n_uplines);
  104. }
  105. /*!
  106. \brief Get updated line by index
  107. \param map vector map
  108. \param idx index
  109. \return updated line
  110. */
  111. int
  112. Vect_get_updated_line (struct Map_info *map, int idx)
  113. {
  114. return (map->plus.uplines[idx]);
  115. }
  116. /*!
  117. \brief Get number of updated nodes
  118. \param map vector map
  119. \return number of updated nodes
  120. */
  121. int
  122. Vect_get_num_updated_nodes (struct Map_info *map)
  123. {
  124. return (map->plus.n_upnodes);
  125. }
  126. /*!
  127. \brief Get updated node by index
  128. \param map vector map
  129. \param idx index
  130. \return updated node
  131. */
  132. int
  133. Vect_get_updated_node (struct Map_info *map, int idx)
  134. {
  135. return (map->plus.upnodes[idx]);
  136. }
  137. /*!
  138. \brief Get 2D/3D coordinates of node
  139. \param map vector map
  140. \param num
  141. \param x,y,z coordinates values
  142. \return 2D/3D coordinates of node
  143. */
  144. int
  145. Vect_get_node_coor (struct Map_info *map, int num, double *x, double *y, double *z)
  146. {
  147. P_NODE *Node;
  148. Node = map->plus.Node[num];
  149. *x = Node->x;
  150. *y = Node->y;
  151. if ( z != NULL )
  152. *z = Node->z;
  153. return (0);
  154. }
  155. /*!
  156. \brief Get starting and ending node of line
  157. \param Map vector map
  158. \param line line id
  159. \param n1, n2 ids of line nodes
  160. \return numbers of line nodes
  161. */
  162. int
  163. Vect_get_line_nodes ( struct Map_info *Map, int line, int *n1, int *n2)
  164. {
  165. if ( Map->level < 2 )
  166. G_fatal_error (_("Vector map <%s> is not open on level >= 2"), Vect_get_full_name(Map));
  167. if ( n1 != NULL )
  168. *n1 = Map->plus.Line[line]->N1;
  169. if ( n2 != NULL )
  170. *n2 = Map->plus.Line[line]->N2;
  171. return 1;
  172. }
  173. /*!
  174. \brief Get areas/isles on the left and right
  175. \param Map vector map
  176. \param line
  177. \param[out] left,right numbers of areas/isles on the left and right
  178. \return numbers of areas/isles on the left and right
  179. */
  180. int
  181. Vect_get_line_areas ( struct Map_info *Map, int line, int *left, int *right)
  182. {
  183. if ( Map->level < 2 )
  184. G_fatal_error (_("Vector map <%s> is not open on level >= 2"), Vect_get_full_name(Map));
  185. if ( left != NULL )
  186. *left = Map->plus.Line[line]->left;
  187. if ( right != NULL )
  188. *right = Map->plus.Line[line]->right;
  189. return 1;
  190. }
  191. /*!
  192. \brief Returns number of lines for node
  193. \param Map vector map
  194. \param node node id
  195. \return numbers of lines for a node
  196. */
  197. int
  198. Vect_get_node_n_lines ( struct Map_info *Map, int node )
  199. {
  200. if ( Map->level < 2 )
  201. G_fatal_error (_("Vector map <%s> is not open on level >= 2"), Vect_get_full_name(Map));
  202. return ( Map->plus.Node[node]->n_lines );
  203. }
  204. /*!
  205. \brief Returns line number for node line index
  206. \param Map vector map
  207. \param node node number
  208. \param line line index, range : 0 - Vect_get_node_n_lines()
  209. \return line number for node line index
  210. */
  211. int
  212. Vect_get_node_line ( struct Map_info *Map, int node, int line )
  213. {
  214. if ( Map->level < 2 )
  215. G_fatal_error (_("Vector map <%s> is not open on level >= 2"), Vect_get_full_name(Map));
  216. return ( Map->plus.Node[node]->lines[line] );
  217. }
  218. /*!
  219. \brief Angle of segment of the line connected to the node
  220. \param Map vector map
  221. \param node node number
  222. \param line line index, range : 0 - Vect_get_node_n_lines()
  223. \return angle of segment of the line connected to the node
  224. */
  225. float
  226. Vect_get_node_line_angle ( struct Map_info *Map, int node, int line )
  227. {
  228. if ( Map->level < 2 )
  229. G_fatal_error (_("Vector map <%s> is not open on level >= 2"), Vect_get_full_name(Map));
  230. return ( Map->plus.Node[node]->angles[line] );
  231. }
  232. /*!
  233. \brief Returns ID of area the centroid is within
  234. \param Map vector map
  235. \param centroid centroid id
  236. \return ID of area the centroid is within
  237. \return 0 for not in area
  238. \return negative ID if area/centroid (?) is duplicate
  239. */
  240. int
  241. Vect_get_centroid_area ( struct Map_info *Map, int centroid )
  242. {
  243. if ( Map->level < 2 )
  244. G_fatal_error (_("Vector map <%s> is not open on level >= 2"), Vect_get_full_name(Map));
  245. return ( Map->plus.Line[centroid]->left );
  246. }