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