34 G_debug(3,
" Edge = %d NodeFrom = %d NodeTo = %d edge cost = %d",
39 if (from != From_node) {
49 G_debug(3,
" EdgeCost += %d (node)", (
int)cost);
55 G_debug(3,
" don't clip first node");
65 static int convert_dgl_shortest_path_result(
struct Map_info *Map,
73 for (i = 0; i < pSPReport->
cArc; i++) {
76 2,
"From %ld to %ld - cost %ld user %d distance %ld",
91 static int ttb_convert_dgl_shortest_path_result(
struct Map_info *Map,
96 int i, line_id, type, tucfield_idx;
103 for (i = 0; i < pSPReport->
cArc; i++) {
112 if (line_ucat % 2 == 1)
113 line_ucat = ((line_ucat - 1) / -2);
115 line_ucat = (line_ucat) / 2;
119 &type, &line_id) == -1)
126 2,
"From %ld to %ld - cost %ld user %d distance %ld",
149 static int find_shortest_path(
struct Map_info *Map,
int from,
int to,
150 struct ilist *List,
double *cost,
int UseTtb,
153 int *pclip, cArc, nRet;
158 G_debug(3,
"find_shortest_path(): from = %d, to = %d", from, to);
197 clipper, pclip,
NULL);
216 ttb_convert_dgl_shortest_path_result(Map, pSPReport, tucfield,
219 convert_dgl_shortest_path_result(Map, pSPReport, List);
230 cArc = pSPReport->
cArc;
261 int to,
int to_type,
int tucfield,
262 struct ilist *List,
double *cost)
269 int i_line, line, type, cfound;
285 for (i_line = 0; i_line < box_List->
n_values; i_line++) {
286 line = box_List->
id[i_line];
297 G_fatal_error(
_(
"Unable to find point with defined unique category "
301 G_warning(
_(
"There exists more than one point on node <%d> with "
302 "unique category in field <%d>.\n"
303 "The unique category layer may not be valid."),
306 G_debug(2,
"from node = %d, unique cat = %d ", from, f);
314 G_debug(2,
"from edge unique cat = %d", from);
327 for (i_line = 0; i_line < box_List->
n_values; i_line++) {
328 line = box_List->
id[i_line];
338 G_fatal_error(
_(
"Unable to find point with defined unique category "
342 G_warning(
_(
"There exists more than one point on node <%d> with "
343 "unique category in field <%d>.\n"
344 "The unique category layer may not be valid."),
347 G_debug(2,
"to node = %d, unique cat = %d ", to,
t);
355 G_debug(2,
"to edge unique cat = %d", to);
361 return find_shortest_path(Map, f,
t, List, cost, 1, tucfield);
381 struct ilist *List,
double *cost)
383 return find_shortest_path(Map, from, to, List, cost, 0, -1);
419 G_debug(5,
"Vect_net_get_line_cost(): line = %d, dir = %d", line,
450 G_debug(5,
"Vect_net_get_line_cost(): edge_bcosts = %f",
454 G_fatal_error(
_(
"Wrong line direction in Vect_net_get_line_cost()"));
470 G_debug(3,
"Vect_net_get_node_cost(): node = %d", node);
474 G_debug(3,
" -> cost = %f", *cost);
500 int direction,
double maxdist,
int *node1,
501 int *node2,
int *ln,
double *costs1,
double *costs2,
505 int line, n1, n2, nnodes;
509 double cx, cy, cz, c1, c2;
513 G_debug(3,
"Vect_net_nearest_nodes() x = %f y = %f",
x,
y);
549 G_debug(4,
"line = %d n1 = %d n2 = %d segment = %d", line, n1, n2, segment);
552 G_debug(4,
"cx = %f cy = %f first = %f %f last = %f %f", cx, cy,
553 Points->
x[0], Points->
y[0], Points->
x[npoints - 1],
554 Points->
y[npoints - 1]);
556 if (Points->
x[0] == cx && Points->
y[0] == cy) {
567 G_debug(3,
"first node nearest");
570 if (Points->
x[npoints - 1] == cx && Points->
y[npoints - 1] == cy) {
581 G_debug(3,
"last node nearest");
616 *costs1 = c2 * (length - along) / length;
625 for (i = segment; i < npoints; i++)
630 for (i = npoints - 1; i >= segment; i--)
646 *costs1 = c1 * along / length;
650 *costs2 = c2 * (length - along) / length;
659 for (i = segment - 1; i >= 0; i--)
664 for (i = 0; i < segment; i++)
679 for (i = segment; i < npoints; i++)
684 for (i = npoints - 1; i >= segment; i--)
720 find_shortest_path_coor(
struct Map_info *Map,
double fx,
double fy,
double fz,
721 double tx,
double ty,
double tz,
double fmax,
722 double tmax,
int UseTtb,
int tucfield,
double *costs,
725 struct line_pnts *TPoints,
double *fdist,
double *tdist)
729 double fcosts[2], tcosts[2],
731 int nfnodes, ntnodes, fline, tline;
732 static struct line_pnts *APoints, *SPoints, *fPoints[2], *tPoints[2];
733 static struct ilist *LList;
734 static int first = 1;
735 int reachable, shortcut;
736 int i, j, fn = 0, tn = 0;
740 int from_point_node = 0;
741 int to_point_node = 0;
743 G_debug(3,
"Vect_net_shortest_path_coor()");
771 if (NodesList !=
NULL)
775 fnode[0] = fnode[1] = tnode[0] = tnode[1] = 0;
778 Map, fx, fy, fz,
GV_FORWARD, fmax, &(fnode[0]), &(fnode[1]), &fline,
779 &(fcosts[0]), &(fcosts[1]), fPoints[0], fPoints[1], fdist);
783 if (nfnodes == 1 && fPoints[0]->n_points < 3) {
784 from_point_node = fnode[0];
788 Map, tx, ty, tz,
GV_BACKWARD, tmax, &(tnode[0]), &(tnode[1]), &tline,
789 &(tcosts[0]), &(tcosts[1]), tPoints[0], tPoints[1], tdist);
793 if (ntnodes == 1 && tPoints[0]->n_points < 3) {
794 to_point_node = tnode[0];
797 G_debug(3,
"fline = %d tline = %d", fline, tline);
799 reachable = shortcut = 0;
807 if (fline == tline && (nfnodes > 1 || ntnodes > 1)) {
808 double len, flen, tlen, c, fseg, tseg;
809 double fcx, fcy, fcz, tcx, tcy, tcz;
828 reachable = shortcut = 1;
830 else if (flen < tlen) {
833 cur_cst = c * (tlen - flen) / len;
837 for (i = fseg; i < tseg; i++)
844 reachable = shortcut = 1;
850 cur_cst = c * (flen - tlen) / len;
854 for (i = fseg - 1; i >= tseg; i--)
861 reachable = shortcut = 1;
867 for (i = 0; i < nfnodes; i++) {
868 for (j = 0; j < ntnodes; j++) {
872 G_debug(3,
"i = %d fnode = %d j = %d tnode = %d", i, fnode[i], j,
877 tucfield,
NULL, &ncst);
884 cst = fcosts[i] + ncst + tcosts[j];
885 if (reachable == 0 || cst < cur_cst) {
895 G_debug(3,
"reachable = %d shortcut = %d cur_cst = %f", reachable, shortcut,
904 if (from_point_node > 0)
907 if (to_point_node > 0)
916 if (from_point_node > 0 && from_point_node != fnode[fn]) {
926 tucfield, LList,
NULL);
938 for (i = 0; i < LList->
n_values; i++) {
941 line = LList->
value[i];
942 G_debug(3,
"i = %d line = %d", i, line);
954 int node, node1, node2;
981 if (to_point_node > 0 && to_point_node != tnode[tn]) {
1017 double fz,
double tx,
double ty,
double tz,
1018 double fmax,
double tmax,
double *costs,
1020 struct ilist *NodesList,
1022 struct line_pnts *TPoints,
double *fdist,
1025 return find_shortest_path_coor(Map, fx, fy, fz, tx, ty, tz, fmax, tmax, 0,
1026 0, costs, Points, List, NodesList, FPoints,
1027 TPoints, fdist, tdist);
1053 double fz,
double tx,
double ty,
double tz,
1054 double fmax,
double tmax,
int tucfield,
1055 double *costs,
struct line_pnts *Points,
1058 struct line_pnts *TPoints,
double *fdist,
1061 return find_shortest_path_coor(Map, fx, fy, fz, tx, ty, tz, fmax, tmax, 1,
1062 tucfield, costs, Points, List, NodesList,
1063 FPoints, TPoints, fdist, tdist);
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
int Vect_get_line_nodes(struct Map_info *, int, int *, int *)
Get line nodes.
int Vect_get_node_coor(struct Map_info *, int, double *, double *, double *)
Get node coordinates.
double Vect_line_length(const struct line_pnts *)
Calculate line length, 3D-length in case of 3D vector line.
int Vect_cidx_get_field_index(struct Map_info *, int)
Get layer index for given layer number.
int Vect_cidx_find_next(struct Map_info *, int, int, int, int, int *, int *)
Find next line/area id for given category, start_index and type_mask.
struct boxlist * Vect_new_boxlist(int)
Creates and initializes a struct boxlist.
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
void Vect_destroy_boxlist(struct boxlist *)
Frees all memory associated with a struct boxlist, including the struct itself.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_line_distance(const struct line_pnts *, double, double, double, int, double *, double *, double *, double *, double *, double *)
Calculate distance of point to line.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_find_line(struct Map_info *, double, double, double, int, double, int, int)
Find the nearest line.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
int Vect_select_lines_by_box(struct Map_info *, const struct bound_box *, int, struct boxlist *)
Select lines with bounding boxes by box.
void Vect_reset_line(struct line_pnts *)
Reset line.
int Vect_line_prune(struct line_pnts *)
Remove duplicate points, i.e. zero length segments.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int Vect_reset_list(struct ilist *)
Reset ilist structure.
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
int Vect_append_points(struct line_pnts *, const struct line_pnts *, int)
Appends points to the end of a line.
#define GV_POINT
Feature types used in memory on run time (may change)
#define PORT_DOUBLE_MAX
Limits for portable types.
#define GV_FORWARD
Line direction indicator forward/backward.
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
int Vect_net_shortest_path(struct Map_info *Map, int from, int to, struct ilist *List, double *cost)
Find shortest path.
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.
dglGraph_s * Vect_net_get_graph(struct Map_info *Map)
Get graph structure.
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.
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_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.
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_get_node_cost(struct Map_info *Map, int node, double *cost)
Get cost of node.
dglSPCache_s spCache
Shortest path cache.
int line_type
Line type used to build the graph.
int cost_multip
Edge and node costs multiplicator.
double * edge_fcosts
Forward costs used for graph.
double * node_costs
Node costs used for graph.
dglGraph_s graph_s
Graph structure.
double * edge_bcosts
backward costs used for graph
struct Graph_info dgraph
Graph info (built for network analysis)
List of bounding boxes with id.
int n_values
Number of items in the list.
int n_values
Number of values in the list.
int * value
Array of values.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.
double * z
Array of Z coordinates.
int dglGet_NodeAttrSize(dglGraph_s *pgraph)
int dglShortestPath(dglGraph_s *pGraph, dglSPReport_s **ppReport, dglInt32_t nStart, dglInt32_t nDestination, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
char * dglStrerror(dglGraph_s *pgraph)
dglInt32_t dglEdgeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdgeGet_Head(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglNodeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode)
void dglFreeSPReport(dglGraph_s *pgraph UNUSED, dglSPReport_s *pSPReport)
int dglShortestDistance(dglGraph_s *pGraph, dglInt32_t *pnDistance, dglInt32_t nStart, dglInt32_t nDestination, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)