grass  7.8.6
About: GRASS (Geographic Resources Analysis Support System) is a raster- and vector-based GIS, image processing system, graphics production system and spatial modeling system.
  Fossies Dox: grass-7.8.6.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

net_analyze.c File Reference

Vector library - related fns for vector network analyses. More...

#include <grass/dbmi.h>
#include <grass/vector.h>
#include <grass/glocale.h>
Include dependency graph for net_analyze.c:

Go to the source code of this file.

Functions

static int clipper (dglGraph_s *pgraph, dglSPClipInput_s *pargIn, dglSPClipOutput_s *pargOut, void *pvarg)
 
static int convert_dgl_shortest_path_result (struct Map_info *Map, dglSPReport_s *pSPReport, struct ilist *List)
 Converts shortest path result, which is calculated by DGLib on newtwork without turntable, into output format. More...
 
static int ttb_convert_dgl_shortest_path_result (struct Map_info *Map, dglSPReport_s *pSPReport, int tucfield, struct ilist *List)
 Converts shortest path result, which is calculated by DGLib on newtwork with turntable, into output format. More...
 
static int find_shortest_path (struct Map_info *Map, int from, int to, struct ilist *List, double *cost, int UseTtb, int tucfield)
 Finds shortest path on network using DGLib. More...
 
int Vect_net_ttb_shortest_path (struct Map_info *Map, int from, int from_type, int to, int to_type, int tucfield, struct ilist *List, double *cost)
 Find shortest path on network. More...
 
int Vect_net_shortest_path (struct Map_info *Map, int from, int to, struct ilist *List, double *cost)
 Find shortest path. More...
 
dglGraph_sVect_net_get_graph (struct Map_info *Map)
 Get graph structure. More...
 
int Vect_net_get_line_cost (const 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 (const 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...
 
static int find_shortest_path_coor (struct Map_info *Map, double fx, double fy, double fz, double tx, double ty, double tz, double fmax, double tmax, int UseTtb, int tucfield, 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...
 
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 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...
 
int Vect_net_ttb_shortest_path_coor (struct Map_info *Map, double fx, double fy, double fz, double tx, double ty, double tz, double fmax, double tmax, int tucfield, 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 with turntable between 2 points given by coordinates. More...
 

Variables

static int From_node
 

Detailed Description

Vector library - related fns for vector network analyses.

Higher level functions for reading/writing/manipulating vectors.

(C) 2001-2009, 2014 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
Stepan Turek stepan.turek seznam.cz (turns support)

Definition in file net_analyze.c.

Function Documentation

◆ clipper()

◆ convert_dgl_shortest_path_result()

static int convert_dgl_shortest_path_result ( struct Map_info Map,
dglSPReport_s pSPReport,
struct ilist List 
)
static

Converts shortest path result, which is calculated by DGLib on newtwork without turntable, into output format.

Definition at line 63 of file net_analyze.c.

References _dglSPReport::cArc, Graph_info::cost_multip, dglEdgeGet_Cost(), dglEdgeGet_Id(), Map_info::dgraph, G_debug(), Graph_info::graph_s, line(), _dglSPArc::nDistance, _dglSPArc::nFrom, _dglSPArc::nTo, _dglSPReport::pArc, _dglSPArc::pnEdge, Vect_list_append(), and Vect_reset_list().

Referenced by find_shortest_path().

◆ find_shortest_path()

static int find_shortest_path ( struct Map_info Map,
int  from,
int  to,
struct ilist List,
double *  cost,
int  UseTtb,
int  tucfield 
)
static

Finds shortest path on network using DGLib.

Parameters
Mapvector map with build DGLib graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
fromfrom node id in build the network
toto node in build the network
UseTtbthe graph is build with/without turntable
tucfieldlayer with unique cats for turntable (relevant only when UseTtb = 1)

Definition at line 139 of file net_analyze.c.

References _, _dglSPReport::cArc, clipper(), convert_dgl_shortest_path_result(), Graph_info::cost_multip, dglFreeSPReport(), dglShortestDistance(), dglShortestPath(), dglStrerror(), Map_info::dgraph, From_node, G_debug(), G_warning(), Graph_info::graph_s, _dglSPReport::nDistance, NULL, PORT_DOUBLE_MAX, Graph_info::spCache, ttb_convert_dgl_shortest_path_result(), and Vect_reset_list().

Referenced by Vect_net_shortest_path(), and Vect_net_ttb_shortest_path().

◆ find_shortest_path_coor()

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

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

Parameters
Mapvector map with build graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
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'
UseTtbthe graph is build with/without turntable
tucfieldfield with unique categories used in the turntable
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)
NodesListpointer 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 719 of file net_analyze.c.

References c, first, G_debug(), GV_BACKWARD, GV_FORWARD, line(), line_pnts::n_points, ilist::n_values, NULL, Points, PORT_DOUBLE_MAX, ilist::value, Vect_append_point(), Vect_append_points(), Vect_get_line_nodes(), Vect_line_distance(), Vect_line_length(), Vect_line_prune(), Vect_list_append(), Vect_net_get_line_cost(), Vect_net_nearest_nodes(), Vect_net_shortest_path(), Vect_net_ttb_shortest_path(), Vect_new_line_struct(), Vect_new_list(), Vect_read_line(), Vect_reset_line(), Vect_reset_list(), line_pnts::x, line_pnts::y, and line_pnts::z.

Referenced by Vect_net_shortest_path_coor(), and Vect_net_ttb_shortest_path_coor().

◆ ttb_convert_dgl_shortest_path_result()

static int ttb_convert_dgl_shortest_path_result ( struct Map_info Map,
dglSPReport_s pSPReport,
int  tucfield,
struct ilist List 
)
static

◆ Vect_net_get_graph()

dglGraph_s * Vect_net_get_graph ( struct Map_info Map)

Get graph structure.

Graph is built by Vect_net_build_graph().

Returns NULL when graph is not built.

Parameters
Mappointer to Map_info struct
Returns
pointer to dglGraph_s struct or NULL

Definition at line 393 of file net_analyze.c.

References Map_info::dgraph, and Graph_info::graph_s.

◆ Vect_net_get_line_cost()

int Vect_net_get_line_cost ( const 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 with build graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
lineline id
directiondirection (GV_FORWARD, GV_BACKWARD)
[out]cost
Returns
1 OK
0 does not exist (was not inserted)

Definition at line 412 of file net_analyze.c.

References _, Map_info::dgraph, Graph_info::edge_bcosts, Graph_info::edge_fcosts, G_debug(), G_fatal_error(), GV_BACKWARD, GV_FORWARD, and line().

Referenced by find_shortest_path_coor(), and Vect_net_nearest_nodes().

◆ Vect_net_get_node_cost()

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

Get cost of node.

Parameters
Mapvector map with build graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
nodenode id
[out]costcosts value
Returns
1

Definition at line 467 of file net_analyze.c.

References Map_info::dgraph, G_debug(), and Graph_info::node_costs.

◆ Vect_net_nearest_nodes()

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
Mapvector map with build graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
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
[out]node1pointer where to store the node number (or NULL)
[out]node2pointer where to store the node number (or NULL)
[out]lnpointer where to store the nearest line number (or NULL)
[out]costs1pointer where to store costs on nearest line to node1 (not costs from x,y,z to the line) (or NULL)
[out]costs2pointer where to store costs on nearest line to node2 (not costs from x,y,z to the line) (or NULL)
[out]Points1pointer to structure where to store vertices on nearest line to node1 (or NULL)
[out]Points2pointer to structure where to store vertices on nearest line to node2 (or NULL)
[out]pointerwhere to distance to the line (or NULL)
[out]distance
Returns
number of nodes found (0,1,2)

Definition at line 497 of file net_analyze.c.

References Map_info::dgraph, G_debug(), GV_BACKWARD, GV_FORWARD, line(), Graph_info::line_type, line_pnts::n_points, NULL, Points, PORT_DOUBLE_MAX, 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(), Vect_reset_line(), line_pnts::x, x, line_pnts::y, and line_pnts::z.

Referenced by find_shortest_path_coor().

◆ Vect_net_shortest_path()

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 with build graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
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 376 of file net_analyze.c.

References find_shortest_path().

Referenced by find_shortest_path_coor().

◆ 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 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 with build graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
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)
NodesListpointer 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 1023 of file net_analyze.c.

References find_shortest_path_coor(), and Points.

◆ Vect_net_ttb_shortest_path()

int Vect_net_ttb_shortest_path ( struct Map_info Map,
int  from,
int  from_type,
int  to,
int  to_type,
int  tucfield,
struct ilist List,
double *  cost 
)

Find shortest path on network.

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 with build graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
fromstart of the path
from_typeif 0 - node id (intersection), if 1 - line unique cat
toend of the path
to_typeif 0 - node id (intersection), if 1 - line unique cat
tucfieldfield with unique categories used in the turntable
[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 254 of file net_analyze.c.

References _, bound_box::B, bound_box::E, find_shortest_path(), G_debug(), G_fatal_error(), G_warning(), GV_POINT, boxlist::id, line(), bound_box::N, boxlist::n_values, NULL, bound_box::S, bound_box::T, t, type, Vect_cat_get(), Vect_destroy_boxlist(), Vect_destroy_cats_struct(), Vect_get_node_coor(), Vect_new_boxlist(), Vect_new_cats_struct(), Vect_read_line(), Vect_select_lines_by_box(), bound_box::W, and x.

Referenced by find_shortest_path_coor().

◆ Vect_net_ttb_shortest_path_coor()

int Vect_net_ttb_shortest_path_coor ( struct Map_info Map,
double  fx,
double  fy,
double  fz,
double  tx,
double  ty,
double  tz,
double  fmax,
double  tmax,
int  tucfield,
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 with turntable between 2 points given by coordinates.

Parameters
Mapvector map with build graph (see Vect_net_ttb_build_graph and Vect_net_build_graph)
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'
tucfieldfield with unique categories used in the turntable
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)
NodesListpointer 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 1058 of file net_analyze.c.

References find_shortest_path_coor(), and Points.

Variable Documentation

◆ From_node

int From_node
static

Definition at line 21 of file net_analyze.c.

Referenced by clipper(), and find_shortest_path().