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.
int Vect_net_shortest_path (struct Map_info *Map, int from, int to, struct ilist *List, double *cost)
 Find shortest path.
int Vect_net_get_line_cost (struct Map_info *Map, int line, int direction, double *cost)
 Returns in cost for given direction in *cost.
int Vect_net_get_node_cost (struct Map_info *Map, int node, double *cost)
 Get cost of node.
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.
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.


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:
Map vector map
ltype line type for arcs
afield arc costs field (if 0, use length)
nfield node costs field (if 0, do not use node costs)
afcol column with forward costs for arc
abcol column with backward costs for arc (if NULL, back costs = forward costs),
ncol column with costs for nodes (if NULL, do not use node costs),
geo use geodesic calculation for length (LL),
algorithm not used (in future code for algorithm)
Returns:
0 on success, 1 on error

Definition at line 91 of file net.c.

References dglAddEdge(), dglFlatten(), dglGetNode(), dglInitialize(), dglNodeSet_Attr(), 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:
Map vector map
line line id
direction direction (GV_FORWARD, GV_BACKWARD)
Returns:
1 OK

0 does not exist (was not inserted)

Definition at line 552 of file net.c.

Referenced by Vect_net_nearest_nodes(), and Vect_net_shortest_path_coor().

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

Get cost of node.

Parameters:
Map vector map
node node id
[out] cost costs value
Returns:
1

Definition at line 605 of file net.c.

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:
Map vetor map
x,y,z point coordinates (z coordinate NOT USED !)
direction (GV_FORWARD - from point to net, GV_BACKWARD - from net to point)
maxdist maximum distance to the network
node1 pointer where to store the node number (or NULL)
node2 pointer where to store the node number (or NULL)
ln pointer where to store the nearest line number (or NULL)
costs1 pointer where to store costs on nearest line to node1 (not costs from x,y,z to the line) (or NULL)
costs2 pointer where to store costs on nearest line to node2 (not costs from x,y,z to the line) (or NULL)
Points1 pointer to structure where to store vertices on nearest line to node1 (or NULL)
Points2 pointer to structure where to store vertices on nearest line to node2 (or NULL)
pointer where to distance to the line (or NULL)
Returns:
number of nodes found (0,1,2)

Definition at line 634 of file net.c.

References 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_coor().

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:
Map vector map
from from node
to to node
[out] List list of line ids (path)
[out] cost costs 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(), _dglSPReport::nDistance, _dglSPArc::nDistance, _dglSPArc::nFrom, _dglSPArc::nTo, _dglSPReport::pArc, _dglSPArc::pnEdge, Vect_list_append(), and Vect_reset_list().

Referenced by Vect_net_shortest_path_coor().

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:
Map vector map
fx,fy,fz from point x coordinate (z ignored)
tx,ty,tz to point x coordinate (z ignored)
fmax maximum distance to the network from 'from'
tmax maximum distance to the network from 'to'
costs pointer where to store costs on the network (or NULL)
Points pointer to the structure where to store vertices of shortest path (or NULL)
List pointer to the structure where list of lines on the network is stored (or NULL)
FPoints pointer to the structure where to store line from 'from' to first network node (or NULL)
TPoints pointer to the structure where to store line from last network node to 'to' (or NULL)
fdist distance from 'from' to the net (or NULL)
tdist distance from 'to' to the net (or NULL)
Returns:
1 OK, 0 not reachable

Definition at line 853 of file net.c.

References Vect_append_point(), Vect_append_points(), 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(), and Vect_reset_line().


Generated on Thu Jul 16 13:21:26 2009 for GRASS Programmer's Manual by  doxygen 1.5.6