level_two.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. plus_t 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. plus_t Vect_get_num_primitives(const struct Map_info *map, int type)
  31. {
  32. plus_t 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. plus_t 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. plus_t Vect_get_num_areas(const struct Map_info *map)
  62. {
  63. return (map->plus.n_areas);
  64. }
  65. /*!
  66. \brief Fetch number of kernels in vector map
  67. \param map vector map
  68. \return number of kernels
  69. */
  70. plus_t Vect_get_num_kernels(const struct Map_info *map)
  71. {
  72. return (map->plus.n_klines);
  73. }
  74. /*!
  75. \brief Get number of faces in vector map
  76. \param map vector map
  77. \return number of faces
  78. */
  79. plus_t Vect_get_num_faces(const struct Map_info *map)
  80. {
  81. return (map->plus.n_flines);
  82. }
  83. /*!
  84. \brief Fetch number of volumes in vector map
  85. \param map vector map
  86. \return number of volumes
  87. */
  88. plus_t Vect_get_num_volumes(const struct Map_info *map)
  89. {
  90. return (map->plus.n_volumes);
  91. }
  92. /*!
  93. \brief Get number of islands in vector map
  94. \param map vector map
  95. \return number of islands
  96. */
  97. plus_t Vect_get_num_islands(const struct Map_info *map)
  98. {
  99. return (map->plus.n_isles);
  100. }
  101. /*!
  102. \brief Fetch number of holes in vector map
  103. \param map vector map
  104. \return number of holes
  105. */
  106. plus_t Vect_get_num_holes(const struct Map_info *map)
  107. {
  108. return (map->plus.n_holes);
  109. }
  110. /*!
  111. \brief Get number of defined dblinks
  112. \param map vector map
  113. \return number of dblinks
  114. */
  115. int Vect_get_num_dblinks(const struct Map_info *map)
  116. {
  117. return (map->dblnk->n_fields);
  118. }
  119. /*!
  120. \brief Get number of updated features
  121. \param map vector map
  122. \return number of updated features
  123. */
  124. int Vect_get_num_updated_lines(const struct Map_info *map)
  125. {
  126. return (map->plus.n_uplines);
  127. }
  128. /*!
  129. \brief Get updated line by index
  130. \param map vector map
  131. \param idx index
  132. \return updated line
  133. */
  134. int Vect_get_updated_line(const struct Map_info *map, int idx)
  135. {
  136. return (map->plus.uplines[idx]);
  137. }
  138. /*!
  139. \brief Get number of updated nodes
  140. \param map vector map
  141. \return number of updated nodes
  142. */
  143. int Vect_get_num_updated_nodes(const struct Map_info *map)
  144. {
  145. return (map->plus.n_upnodes);
  146. }
  147. /*!
  148. \brief Get updated node by index
  149. \param map vector map
  150. \param idx index
  151. \return updated node
  152. */
  153. int Vect_get_updated_node(const struct Map_info *map, int idx)
  154. {
  155. return (map->plus.upnodes[idx]);
  156. }
  157. /*!
  158. \brief Get node coordinates
  159. \param map vector map
  160. \param num node id
  161. \param x,y,z coordinates values (for 2D coordinates z is NULL)
  162. \return 0
  163. */
  164. int
  165. Vect_get_node_coor(const struct Map_info *map, int num, double *x, double *y,
  166. double *z)
  167. {
  168. struct P_node *Node;
  169. Node = map->plus.Node[num];
  170. *x = Node->x;
  171. *y = Node->y;
  172. if (z != NULL)
  173. *z = Node->z;
  174. return (0);
  175. }
  176. /*!
  177. \brief Get line nodes
  178. \param Map vector map
  179. \param line line id
  180. \param n1, n2 ids of line nodes (or NULL)
  181. \return 1
  182. */
  183. int Vect_get_line_nodes(const struct Map_info *Map, int line, int *n1, int *n2)
  184. {
  185. if (Map->level < 2)
  186. G_fatal_error(_("Vector map <%s> is not open on level >= 2"),
  187. Vect_get_full_name(Map));
  188. if (n1 != NULL)
  189. *n1 = Map->plus.Line[line]->N1;
  190. if (n2 != NULL)
  191. *n2 = Map->plus.Line[line]->N2;
  192. return 1;
  193. }
  194. /*!
  195. \brief Get area/isle ids on the left and right
  196. \param Map vector map
  197. \param line line id
  198. \param[out] left,right area/isle id on the left and right
  199. \return 1
  200. */
  201. int Vect_get_line_areas(const struct Map_info *Map, int line, int *left, int *right)
  202. {
  203. if (Map->level < 2)
  204. G_fatal_error(_("Vector map <%s> is not open on level >= 2"),
  205. Vect_get_full_name(Map));
  206. if (left != NULL)
  207. *left = Map->plus.Line[line]->left;
  208. if (right != NULL)
  209. *right = Map->plus.Line[line]->right;
  210. return 1;
  211. }
  212. /*!
  213. \brief Get number of lines for node
  214. \param Map vector map
  215. \param node node id
  216. \return numbers of lines
  217. */
  218. int Vect_get_node_n_lines(const struct Map_info *Map, int node)
  219. {
  220. if (Map->level < 2)
  221. G_fatal_error(_("Vector map <%s> is not open on level >= 2"),
  222. Vect_get_full_name(Map));
  223. return (Map->plus.Node[node]->n_lines);
  224. }
  225. /*!
  226. \brief Get line id for node line index
  227. \param Map vector map
  228. \param node node id
  229. \param line line index (range: 0 - Vect_get_node_n_lines())
  230. \return line id
  231. */
  232. int Vect_get_node_line(const struct Map_info *Map, int node, int line)
  233. {
  234. if (Map->level < 2)
  235. G_fatal_error(_("Vector map <%s> is not open on level >= 2"),
  236. Vect_get_full_name(Map));
  237. return (Map->plus.Node[node]->lines[line]);
  238. }
  239. /*!
  240. \brief Angle of segment of the line connected to the node
  241. \param Map vector map
  242. \param node node number
  243. \param line line index (range: 0 - Vect_get_node_n_lines())
  244. \return angle of segment of the line connected to the node
  245. */
  246. float Vect_get_node_line_angle(const struct Map_info *Map, int node, int line)
  247. {
  248. if (Map->level < 2)
  249. G_fatal_error(_("Vector map <%s> is not open on level >= 2"),
  250. Vect_get_full_name(Map));
  251. return (Map->plus.Node[node]->angles[line]);
  252. }
  253. /*!
  254. \brief Get area id the centroid is within
  255. \param Map vector map
  256. \param centroid centroid id
  257. \return area id the centroid is within
  258. \return 0 for not in area
  259. \return negative id if area/centroid (?) is duplicate
  260. */
  261. int Vect_get_centroid_area(const struct Map_info *Map, int centroid)
  262. {
  263. if (Map->level < 2)
  264. G_fatal_error(_("Vector map <%s> is not open on level >= 2"),
  265. Vect_get_full_name(Map));
  266. return (Map->plus.Line[centroid]->left);
  267. }