56 const char *ncol,
int geo,
int algorithm)
59 int i, j, from, to, line, nlines, nnodes, ret, type, cat, skipped, cfound;
62 double dcost, bdcost, ll;
66 { 360000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
74 int fctype = 0, bctype = 0, nrec, nturns;
76 int ln_cat, nnode_lns, i_line, line_id, i_virt_edge;
85 const char *tcols[] = {
"cat",
"ln_from",
"ln_to",
"cost",
"isec",
NULL 88 int tctype[5] = { 0 };
92 int node_pt_id, turn_cat, tucfound;
96 G_debug(1,
"Vect_net_ttb_build_graph(): " 97 "ltype = %d, afield = %d, nfield = %d, tfield = %d, tucfield = %d ",
98 ltype, afield, nfield, tfield, tucfield);
99 G_debug(1,
" afcol = %s, abcol = %s, ncol = %s", afcol, abcol, ncol);
112 if (afcol ==
NULL && ll && !geo)
124 (
double *)
G_malloc((nlines + 1) *
sizeof(double));
126 (
double *)
G_malloc((nlines + 1) *
sizeof(double));
128 (
double *)
G_malloc((nnodes + 1) *
sizeof(double));
131 for (i = 1; i <= nlines; i++) {
135 for (i = 1; i <= nnodes; i++) {
164 if (ttbdriver ==
NULL)
173 tcols[i], Fi->
table);
178 !strcmp(tcols[i],
"cost")) ;
182 (
"Data type of column <%s> not supported (must be numeric)"),
192 G_debug(1,
"forward costs: nrec = %d", nturns);
198 G_debug(2,
"Set nodes' costs");
223 (
"Data type of column <%s> not supported (must be numeric)"),
231 G_debug(1,
"node costs: nrec = %d", nrec);
242 for (i = 1; i <= nnodes; i++) {
258 for (j = 0; j < List->
n_values; j++) {
260 G_debug(2,
" line (%d) = %d", j, line);
277 (
"Database record for node %d (cat = %d) not found " 278 "(cost set to 0)"), i, cat);
303 if (!tucfound && ret) {
307 for (i_line = 0; i_line < nnode_lns; i_line++) {
323 "Add arc %d for virtual node from %d to %d cost = %d",
324 i_virt_edge, f, t, 0);
332 (
"Cannot add network arc for virtual node connection."));
343 "Add arc %d for virtual node from %d to %d cost = %d",
344 i_virt_edge, f, t, 0);
352 (
"Cannot add network arc for virtual node connection."));
364 (
"There exists more than one point of node <%d> with unique category field <%d>.\n" 365 "The unique categories layer is not valid therefore you will probably get incorrect results."),
368 if (ncol !=
NULL && !cfound)
370 "Category of field %d is not attached to any points in node %d" 371 "(costs set to 0)", nfield, i);
376 for (i = 1; i <= nturns; i++) {
390 (Map, tucfield_idx, isec,
GV_POINT, 0, &type,
391 &node_pt_id) == -1) {
393 (
"Unable to find point representing intersection <%d> in unique categories field <%d>.\n" 394 "Cost for the intersection was set to 0.\n" 395 "The unique categories layer is not valid therefore you will probably get incorrect results."),
405 if (node_pt_id == 0) {
407 (
"Unable to find node for point representing intersection <%d> in unique categories field <%d>.\n" 408 "Cost for the intersection was set to 0.\n" 409 "The unique categories layer is not valid therefore you will probably get incorrect results."),
413 G_debug(2,
" node = %d", node_pt_id);
419 G_debug(2,
"Set node's cost to %f", dcost);
432 (
"Database record for turn with cat = %d in not found. " 433 "(The turn was skipped."), i);
457 G_debug(5,
"Add arc/turn %d for turn from %d to %d cost = %d",
458 turn_cat, f, t, cost);
465 (
"Cannot add network arc representing turn."));
508 (
"Data type of column <%s> not supported (must be numeric)"),
515 G_debug(1,
"forward costs: nrec = %d", nrec);
526 (
"Data type of column <%s> not supported (must be numeric)"),
533 G_debug(1,
"backward costs: nrec = %d", nrec);
541 for (i = 1; i <= nlines; i++) {
558 (
"Line with id <%d> has more unique categories defined in field <%d>.\n" 559 "The unique categories layer is not valid therefore you will probably get incorrect results."),
565 "Category of field %d not attached to the line %d -> cost was set to 0",
579 G_warning(
_(
"Database record for line %d (cat = %d, " 580 "forward/both direction(s)) not found " 581 "(cost was set to 0)"), i, cat);
596 G_warning(
_(
"Database record for line %d (cat = %d, " 597 "backword direction) not found" 598 "(cost was set to 0)"), i, cat);
625 G_debug(5,
"Setinng node %d cost: %d", cat, cost);
635 G_debug(5,
"Setinng node %d cost: %d", cat, cost);
641 if (afcol !=
NULL && skipped > 0)
642 G_debug(2,
"%d lines missing category of field %d skipped", skipped,
701 const char *ncol,
int geo,
int version)
704 int i, j, from, to, line, nlines, nnodes, ret, type, cat, skipped, cfound;
708 double dcost, bdcost, ll;
713 { 360000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
720 int fctype = 0, bctype = 0, nrec;
723 G_debug(1,
"Vect_net_build_graph(): ltype = %d, afield = %d, nfield = %d",
724 ltype, afield, nfield);
725 G_debug(1,
" afcol = %s, abcol = %s, ncol = %s", afcol, abcol, ncol);
738 if (afcol ==
NULL && ll && !geo)
750 (
double *)
G_malloc((nlines + 1) *
sizeof(double));
752 (
double *)
G_malloc((nlines + 1) *
sizeof(double));
754 (
double *)
G_malloc((nnodes + 1) *
sizeof(double));
756 for (i = 1; i <= nlines; i++) {
760 for (i = 1; i <= nnodes; i++) {
764 if (version < 1 || version > 3)
809 (
"Data type of column <%s> not supported (must be numeric)"),
816 G_debug(1,
"forward costs: nrec = %d", nrec);
827 (
"Data type of column <%s> not supported (must be numeric)"),
834 G_debug(1,
"backward costs: nrec = %d", nrec);
842 for (i = 1; i <= nlines; i++) {
854 "Category of field %d not attached to the line %d -> line skipped",
869 G_warning(
_(
"Database record for line %d (cat = %d, " 870 "forward/both direction(s)) not found " 871 "(forward/both direction(s) of line skipped)"),
888 G_warning(
_(
"Database record for line %d (cat = %d, " 889 "backword direction) not found" 890 "(direction of line skipped)"), i, cat);
914 if (dofw && dcost != -1) {
916 G_debug(5,
"Add arc %d from %d to %d cost = %d", i, from, to,
926 G_debug(5,
"bdcost = %f edge_bcosts = %f", bdcost,
928 if (dobw && bdcost != -1) {
930 G_debug(5,
"Add arc %d from %d to %d bcost = %d", -i, to, from,
941 if (afcol !=
NULL && skipped > 0)
942 G_debug(2,
"%d lines missing category of field %d skipped", skipped,
963 G_debug(2,
"Set nodes' costs");
988 (
"Data type of column <%s> not supported (must be numeric)"),
995 G_debug(1,
"node costs: nrec = %d", nrec);
997 for (i = 1; i <= nnodes; i++) {
1012 for (j = 0; j < List->
n_values; j++) {
1014 G_debug(2,
" line (%d) = %d", j, line);
1032 (
"Database record for node %d (cat = %d) not found " 1033 "(cost set to 0)"), i, cat);
1041 "Category of field %d not attached to any points in node %d" 1042 "(costs set to 0)", nfield, i);
1052 G_debug(3,
"Set node's cost to %d", cost);
void Vect_destroy_boxlist(struct boxlist *)
Frees all memory associated with a struct boxlist, including the struct itself.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void db_CatValArray_init(dbCatValArray *)
Initialize dbCatValArray.
int db_CatValArray_get_value_int(dbCatValArray *, int, int *)
Find value (integer) by key.
plus_t Vect_get_num_nodes(const struct Map_info *)
Get number of nodes in vector map.
int Vect_cidx_find_next(const struct Map_info *, int, int, int, int, int *, int *)
Find next line/area id for given category, start_index and type_mask.
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
plus_t Vect_get_num_lines(const struct Map_info *)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
void db_init_string(dbString *)
Initialize dbString.
void dglNodeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode, dglInt32_t *pnAttr)
int G_projection(void)
Query cartographic projection.
char * table
Name of DB table.
double * edge_fcosts
Forward costs used for graph.
int Vect_net_ttb_build_graph(struct Map_info *Map, int ltype, int afield, int nfield, int tfield, int tucfield, const char *afcol, const char *abcol, const char *ncol, int geo, int algorithm)
Build network graph with turntable.
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
double Vect_line_geodesic_length(const struct line_pnts *)
Calculate line length.
int db_get_column(dbDriver *, const char *, const char *, dbColumn **)
Get column structure by table and column name.
double Vect_line_length(const struct line_pnts *)
Calculate line length, 3D-length in case of 3D vector line.
double * edge_bcosts
backward costs used for graph
int n_values
Number of items in the list.
#define GV_POINT
Feature types used in memory on run time (may change)
int Vect_get_node_n_lines(const struct Map_info *, int)
Get number of lines for node.
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
struct field_info * Vect_get_field(const struct Map_info *, int)
Get information about link to database (by layer number)
int dglInitialize(dglGraph_s *pGraph, dglByte_t Version, dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize, dglInt32_t *pOpaqueSet)
int Vect_get_node_coor(const struct Map_info *, int, double *, double *, double *)
Get node coordinates.
Layer (old: field) information.
void G_message(const char *,...) __attribute__((format(printf
struct Graph_info dgraph
Graph info (built for network analysis)
double * x
Array of X coordinates.
int Vect_select_lines_by_box(struct Map_info *, const struct bound_box *, int, struct boxlist *)
Select lines with bounding boxes by box.
Feature geometry info - coordinates.
int db_get_column_sqltype(dbColumn *)
Returns column sqltype for column.
int Vect_get_node_line(const struct Map_info *, int, int)
Get line id for node line index.
dglGraph_s graph_s
Graph structure.
int dglInitializeSPCache(dglGraph_s *pGraph, dglSPCache_s *pCache)
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
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 version)
Build network graph.
int Vect_find_node(struct Map_info *, double, double, double, double, int)
Find the nearest node.
int db_sqltype_to_Ctype(int)
Get C data type based on given SQL data type.
int db_CatValArray_get_value_double(dbCatValArray *, int, double *)
Find value (double) by key.
void db_init_handle(dbHandle *)
Initialize handle (i.e database/schema)
#define WITHOUT_Z
2D/3D vector data
dglSPCache_s spCache
Shortest path cache.
int Vect_get_line_nodes(const struct Map_info *, int, int *, int *)
Get line nodes.
void G_percent(long, long, int)
Print percent complete messages.
double * y
Array of Y coordinates.
char * driver
Name of DB driver ('sqlite', 'dbf', ...)
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
int dglAddEdge(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
void db_CatValArray_free(dbCatValArray *)
Free allocated dbCatValArray.
List of bounding boxes with id.
void G_warning(const char *,...) __attribute__((format(printf
int cost_multip
Edge and node costs multiplicator.
double * z
Array of Z coordinates.
int db_select_CatValArray(dbDriver *, const char *, const char *, const char *, const char *, dbCatValArray *)
Select pairs key/value to array, values are sorted by key (must be integer)
struct boxlist * Vect_new_boxlist(int)
Creates and initializes a struct boxlist.
double * node_costs
Node costs used for graph.
int Vect_cidx_get_field_index(const struct Map_info *, int)
Get layer index for given layer number.
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int dglFlatten(dglGraph_s *pGraph)
int G_debug(int, const char *,...) __attribute__((format(printf
int line_type
Line type used to build the graph.
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
char * key
Name of key column (usually 'cat')