level_two.c 6.8 KB

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