GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
net.c File Reference

Vector library - net releated fns. More...

#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
#include <grass/Vect.h>
#include <grass/glocale.h>
Include dependency graph for net.c:

Go to the source code of this file.

Functions

int Vect_net_build_graph (struct Map_info *Map, int ltype, int afield, int nfield, const char *afcol, const char *abcol, const char *ncol, int geo, int algorithm)
 Build network graph. More...
 
int Vect_net_shortest_path (struct Map_info *Map, int from, int to, struct ilist *List, double *cost)
 Find shortest path. More...
 
int Vect_net_get_line_cost (struct Map_info *Map, int line, int direction, double *cost)
 Returns in cost for given direction in *cost. More...
 
int Vect_net_get_node_cost (struct Map_info *Map, int node, double *cost)
 Get cost of node. More...
 
int Vect_net_nearest_nodes (struct Map_info *Map, double x, double y, double z, int direction, double maxdist, int *node1, int *node2, int *ln, double *costs1, double *costs2, struct line_pnts *Points1, struct line_pnts *Points2, double *distance)
 Find nearest node(s) on network. More...
 
int Vect_net_shortest_path_coor (struct Map_info *Map, double fx, double fy, double fz, double tx, double ty, double tz, double fmax, double tmax, double *costs, struct line_pnts *Points, struct ilist *List, struct line_pnts *FPoints, struct line_pnts *TPoints, double *fdist, double *tdist)
 Find shortest path on network between 2 points given by coordinates. More...
 
int Vect_net_shortest_path_coor2 (struct Map_info *Map, double fx, double fy, double fz, double tx, double ty, double tz, double fmax, double tmax, double *costs, struct line_pnts *Points, struct ilist *List, struct ilist *NodesList, struct line_pnts *FPoints, struct line_pnts *TPoints, double *fdist, double *tdist)
 Find shortest path on network between 2 points given by coordinates. More...
 

Detailed Description

Vector library - net releated fns.

Higher level functions for reading/writing/manipulating vectors.

(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
Radim Blazek
Date
2001-2008

Definition in file net.c.

Function Documentation

int Vect_net_build_graph ( struct Map_info *  Map,
int  ltype,
int  afield,
int  nfield,
const char *  afcol,
const char *  abcol,
const char *  ncol,
int  geo,
int  algorithm 
)

Build network graph.

Internal format for edge costs is integer, costs are multiplied before conversion to int by 1000 and for lenghts LL without geo flag by 1000000. The same multiplication factor is used for nodes. Costs in database column may be 'integer' or 'double precision' number >= 0 or -1 for infinity i.e. arc or node is closed and cannot be traversed If record in table is not found for arcs, arc is skip. If record in table is not found for node, costs for node are set to 0.

Parameters
Mapvector map
ltypeline type for arcs
afieldarc costs field (if 0, use length)
nfieldnode costs field (if 0, do not use node costs)
afcolcolumn with forward costs for arc
abcolcolumn with backward costs for arc (if NULL, back costs = forward costs),
ncolcolumn with costs for nodes (if NULL, do not use node costs),
geouse geodesic calculation for length (LL),
algorithmnot used (in future code for algorithm)
Returns
0 on success, 1 on error

Definition at line 91 of file net.c.

References cat, db_CatValArray_free(), db_CatValArray_get_value_double(), db_CatValArray_get_value_int(), db_CatValArray_init(), db_close_database_shutdown_driver(), db_get_column(), db_get_column_sqltype(), db_init_handle(), db_init_string(), db_select_CatValArray(), db_sqltype_to_Ctype(), db_start_driver_open_database(), dglAddEdge(), dglFlatten(), dglGetNode(), dglInitialize(), dglInitializeSPCache(), dglNodeSet_Attr(), G_debug(), G_fatal_error(), G_message(), G_percent(), G_projection(), G_warning(), NULL, dialogs::type, Vect_cat_get(), Vect_get_field(), Vect_get_line_nodes(), Vect_get_node_line(), Vect_get_node_n_lines(), Vect_get_num_lines(), Vect_get_num_nodes(), Vect_line_geodesic_length(), Vect_line_length(), Vect_new_cats_struct(), Vect_new_line_struct(), and Vect_read_line().

int Vect_net_get_line_cost ( struct Map_info *  Map,
int  line,
int  direction,
double *  cost 
)

Returns in cost for given direction in *cost.

cost is set to -1 if closed.

Parameters
Mapvector map
lineline id
directiondirection (GV_FORWARD, GV_BACKWARD)
Returns
1 OK
0 does not exist (was not inserted)

Definition at line 565 of file net.c.

References G_debug(), and G_fatal_error().

Referenced by Vect_net_nearest_nodes(), and Vect_net_shortest_path_coor2().

int Vect_net_get_node_cost ( struct Map_info *  Map,
int  node,
double *  cost 
)

Get cost of node.

Parameters
Mapvector map
nodenode id
[out]costcosts value
Returns
1

Definition at line 618 of file net.c.

References G_debug().

int Vect_net_nearest_nodes ( struct Map_info *  Map,
double  x,
double  y,
double  z,
int  direction,
double  maxdist,
int node1,
int node2,
int ln,
double *  costs1,
double *  costs2,
struct line_pnts *  Points1,
struct line_pnts *  Points2,
double *  distance 
)

Find nearest node(s) on network.

Parameters
Mapvetor map
x,y,zpoint coordinates (z coordinate NOT USED !)
direction(GV_FORWARD - from point to net, GV_BACKWARD - from net to point)
maxdistmaximum distance to the network
node1pointer where to store the node number (or NULL)
node2pointer where to store the node number (or NULL)
lnpointer where to store the nearest line number (or NULL)
costs1pointer where to store costs on nearest line to node1 (not costs from x,y,z to the line) (or NULL)
costs2pointer where to store costs on nearest line to node2 (not costs from x,y,z to the line) (or NULL)
Points1pointer to structure where to store vertices on nearest line to node1 (or NULL)
Points2pointer to structure where to store vertices on nearest line to node2 (or NULL)
pointerwhere to distance to the line (or NULL)
Returns
number of nodes found (0,1,2)

Definition at line 647 of file net.c.

References G_debug(), NULL, Vect_append_point(), Vect_find_line(), Vect_get_line_nodes(), Vect_line_distance(), Vect_line_length(), Vect_net_get_line_cost(), Vect_new_line_struct(), Vect_read_line(), and Vect_reset_line().

Referenced by Vect_net_shortest_path_coor2().

int Vect_net_shortest_path ( struct Map_info *  Map,
int  from,
int  to,
struct ilist *  List,
double *  cost 
)

Find shortest path.

Costs for 'from' and 'to' nodes are not considered (SP found even if 'from' or 'to' are 'closed' (costs = -1) and costs of these nodes are not added to SP costs result.

Parameters
Mapvector map
fromfrom node
toto node
[out]Listlist of line ids (path)
[out]costcosts value
Returns
number of segments
0 is correct for from = to, or List == NULL ) ? sum of costs is better return value,
-1 : destination unreachable

Definition at line 464 of file net.c.

References _dglSPReport::cArc, dglEdgeGet_Cost(), dglEdgeGet_Id(), dglFreeSPReport(), dglShortestDistance(), dglShortestPath(), dglStrerror(), G_debug(), G_warning(), _dglSPArc::nDistance, _dglSPReport::nDistance, _dglSPArc::nFrom, _dglSPArc::nTo, NULL, _dglSPReport::pArc, _dglSPArc::pnEdge, Vect_list_append(), and Vect_reset_list().

Referenced by Vect_net_shortest_path_coor2().

int Vect_net_shortest_path_coor ( struct Map_info *  Map,
double  fx,
double  fy,
double  fz,
double  tx,
double  ty,
double  tz,
double  fmax,
double  tmax,
double *  costs,
struct line_pnts *  Points,
struct ilist *  List,
struct line_pnts *  FPoints,
struct line_pnts *  TPoints,
double *  fdist,
double *  tdist 
)

Find shortest path on network between 2 points given by coordinates.

Parameters
Mapvector map
fx,fy,fzfrom point x coordinate (z ignored)
tx,ty,tzto point x coordinate (z ignored)
fmaxmaximum distance to the network from 'from'
tmaxmaximum distance to the network from 'to'
costspointer where to store costs on the network (or NULL)
Pointspointer to the structure where to store vertices of shortest path (or NULL)
Listpointer to the structure where list of lines on the network is stored (or NULL)
FPointspointer to the structure where to store line from 'from' to first network node (or NULL)
TPointspointer to the structure where to store line from last network node to 'to' (or NULL)
fdistdistance from 'from' to the net (or NULL)
tdistdistance from 'to' to the net (or NULL)
Returns
1 OK, 0 not reachable

Definition at line 866 of file net.c.

References NULL, and Vect_net_shortest_path_coor2().

int Vect_net_shortest_path_coor2 ( struct Map_info *  Map,
double  fx,
double  fy,
double  fz,
double  tx,
double  ty,
double  tz,
double  fmax,
double  tmax,
double *  costs,
struct line_pnts *  Points,
struct ilist *  List,
struct ilist *  NodesList,
struct line_pnts *  FPoints,
struct line_pnts *  TPoints,
double *  fdist,
double *  tdist 
)

Find shortest path on network between 2 points given by coordinates.

Parameters
Mapvector map
fx,fy,fzfrom point x coordinate (z ignored)
tx,ty,tzto point x coordinate (z ignored)
fmaxmaximum distance to the network from 'from'
tmaxmaximum distance to the network from 'to'
costspointer where to store costs on the network (or NULL)
Pointspointer to the structure where to store vertices of shortest path (or NULL)
Listpointer to the structure where list of lines on the network is stored (or NULL)
Listpointer to the structure where list of nodes on the network is stored (or NULL)
FPointspointer to the structure where to store line from 'from' to first network node (or NULL)
TPointspointer to the structure where to store line from last network node to 'to' (or NULL)
fdistdistance from 'from' to the net (or NULL)
tdistdistance from 'to' to the net (or NULL)
Returns
1 OK, 0 not reachable

Definition at line 898 of file net.c.

References first, frame::fn, G_debug(), NULL, Vect_append_point(), Vect_append_points(), Vect_get_line_nodes(), Vect_line_distance(), Vect_line_length(), Vect_list_append(), Vect_net_get_line_cost(), Vect_net_nearest_nodes(), Vect_net_shortest_path(), Vect_new_line_struct(), Vect_new_list(), Vect_read_line(), Vect_reset_line(), and Vect_reset_list().

Referenced by Vect_net_shortest_path_coor().