level_two.c 6.2 KB

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