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
|
/*
****************************************************************************
*
* MODULE: Vector library
*
* AUTHOR(S): Original author CERL, probably Dave Gerdes or Mike Higgins.
* Update to GRASS 5.7 Radim Blazek and David D. Gray.
*
* PURPOSE: Higher level functions for reading/writing/manipulating vectors.
*
* COPYRIGHT: (C) 2001 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.
*
*****************************************************************************/
#include "gis.h"
#include "Vect.h"
#include <stdlib.h>
/* INTERFACE LEVEL II */
/*!
\fn int Vect_get_num_nodes (struct Map_info *map)
\brief get number of nodes
\return number of nodes
\param Map_info structure
*/
int
Vect_get_num_nodes (struct Map_info *map)
{
return (map->plus.n_nodes);
}
/*!
\fn int Vect_get_num_primitives (struct Map_info *map, int type)
\brief get number of primitives
\return number of primitives of given type
\param Map_info structure
*/
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;
}
/*!
\fn int Vect_get_num_lines (struct Map_info *map)
\brief get number of lines
\return number of lines
\param Map_info structure
*/
int
Vect_get_num_lines (struct Map_info *map)
{
return (map->plus.n_lines);
}
/*!
\fn int Vect_get_num_areas (struct Map_info *map)
\brief get number of areas
\return number of areas
\param Map_info structure
*/
int
Vect_get_num_areas (struct Map_info *map)
{
return (map->plus.n_areas);
}
/*!
\fn int Vect_get_num_islands (struct Map_info *map)
\brief get number of islands
\return number of islands
\param Map_info structure
*/
int
Vect_get_num_islands (struct Map_info *map)
{
return (map->plus.n_isles);
}
/*!
\fn int Vect_get_num_dblinks (struct Map_info *map)
\brief get number of defined dblinks
\return number of dblinks
\param Map_info structure
*/
int
Vect_get_num_dblinks (struct Map_info *map)
{
return (map->dblnk->n_fields);
}
/*!
\fn int Vect_get_num_updated_lines (struct Map_info *map)
\brief get number of updated lines
\return number of updated lines
\param Map_info structure
*/
int
Vect_get_num_updated_lines (struct Map_info *map)
{
return (map->plus.n_uplines);
}
/*!
\fn int Vect_get_updated_line (struct Map_info *map, int idx)
\brief get updated line by index
\return updated line
\param Map_info structure
*/
int
Vect_get_updated_line (struct Map_info *map, int idx)
{
return (map->plus.uplines[idx]);
}
/*!
\fn int Vect_get_num_updated_nodes (struct Map_info *map)
\brief get number of updated nodes
\return number of updated nodes
\param Map_info structure
*/
int
Vect_get_num_updated_nodes (struct Map_info *map)
{
return (map->plus.n_upnodes);
}
/*!
\fn int Vect_get_updated_node (struct Map_info *map, int idx)
\brief get updated node by index
\return updated node
\param Map_info structure
*/
int
Vect_get_updated_node (struct Map_info *map, int idx)
{
return (map->plus.upnodes[idx]);
}
/*!
\fn int Vect_get_node_coor (struct Map_info *map, int num, double *x, double *y, double *z)
\brief get 2D/3D coordinates of node
\return 2D/3D coordinates of node
\param Map_info structure, node number, xyz coordinates values
*/
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);
}
/*!
\fn int Vect_get_line_nodes ( struct Map_info *Map, int line, int *n1, int *n2)
\brief get starting and ending node of line
\return numbers of line nodes
\param Map_info structure, line number, numbers of line nodes
*/
int
Vect_get_line_nodes ( struct Map_info *Map, int line, int *n1, int *n2)
{
if ( Map->level < 2 )
G_fatal_error ("Map %s@%s is not open on level >= 2\n", Map->name, Map->mapset);
if ( n1 != NULL )
*n1 = Map->plus.Line[line]->N1;
if ( n2 != NULL )
*n2 = Map->plus.Line[line]->N2;
return 1;
}
/*!
\fn int Vect_get_line_areas ( struct Map_info *Map, int line, int *left, int *right)
\brief get areas/isles on the left and right
\return numbers of areas/isles on the left and right
\param Map_info structure, line number, numbers of areas/isles on the left and right
*/
int
Vect_get_line_areas ( struct Map_info *Map, int line, int *left, int *right)
{
if ( Map->level < 2 )
G_fatal_error ("Map %s@%s is not open on level >= 2\n", Map->name, Map->mapset);
if ( left != NULL )
*left = Map->plus.Line[line]->left;
if ( right != NULL )
*right = Map->plus.Line[line]->right;
return 1;
}
/*!
\fn int Vect_get_node_n_lines ( struct Map_info *Map, int node )
\brief returns number of lines for node
\return numbers of line for a node ??
\param Map_info structure, node number
*/
int
Vect_get_node_n_lines ( struct Map_info *Map, int node )
{
if ( Map->level < 2 )
G_fatal_error ("Map %s@%s is not open on level >= 2\n", Map->name, Map->mapset);
return ( Map->plus.Node[node]->n_lines );
}
/*!
\fn int Vect_get_node_line ( struct Map_info *Map, int node, int line )
\brief returns line number for node line index
\return line number for node line index
\param Map vector map
\param node node number
\param line line index, range : 0 - Vect_get_node_n_lines()
*/
int
Vect_get_node_line ( struct Map_info *Map, int node, int line )
{
if ( Map->level < 2 )
G_fatal_error ("Map %s@%s is not open on level >= 2\n", Map->name, Map->mapset);
return ( Map->plus.Node[node]->lines[line] );
}
/*!
\fn int Vect_get_node_line_angle ( struct Map_info *Map, int node, int line )
\brief angle of segment of the line connected to the node
\return 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()
*/
float
Vect_get_node_line_angle ( struct Map_info *Map, int node, int line )
{
if ( Map->level < 2 )
G_fatal_error ("Map %s@%s is not open on level >= 2\n", Map->name, Map->mapset);
return ( Map->plus.Node[node]->angles[line] );
}
/*!
\fn int Vect_get_centroid_area ( struct Map_info *Map, int centroid )
\brief returns number of area the centroid is within
\return number of area the node is within, 0 for not in area, negative number of area if duplicate
\param Map_info structure, centroid number
*/
int
Vect_get_centroid_area ( struct Map_info *Map, int centroid )
{
if ( Map->level < 2 )
G_fatal_error ("Map %s@%s is not open on level >= 2\n", Map->name, Map->mapset);
return ( Map->plus.Line[centroid]->left );
}
|