49 int nfield,
int tfield,
int tucfield,
50 const char *afcol,
const char *abcol,
51 const char *ncol,
int geo,
int algorithm
UNUSED)
54 int i, j, from, to, line, nlines, nnodes, ret, type, cat, skipped, cfound;
57 double dcost, bdcost, ll;
60 dglInt32_t opaqueset[16] = {360000, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 0, 0, 0, 0, 0, 0};
69 int fctype = 0, bctype = 0, nrec, nturns;
71 int ln_cat, nnode_lns, i_line, line_id, i_virt_edge;
80 const char *tcols[] = {
"cat",
"ln_from",
"ln_to",
"cost",
"isec",
NULL};
86 int node_pt_id, turn_cat, tucfound;
91 "Vect_net_ttb_build_graph(): "
92 "ltype = %d, afield = %d, nfield = %d, tfield = %d, tucfield = %d ",
93 ltype, afield, nfield, tfield, tucfield);
94 G_debug(1,
" afcol = %s, abcol = %s, ncol = %s", afcol, abcol, ncol);
107 if (afcol ==
NULL && ll && !geo)
124 for (i = 1; i <= nlines; i++) {
128 for (i = 1; i <= nnodes; i++) {
157 if (ttbdriver ==
NULL)
166 tcols[i], Fi->
table);
172 !strcmp(tcols[i],
"cost"))
178 _(
"Data type of column <%s> not supported (must be numeric)"),
189 G_debug(1,
"forward costs: nrec = %d", nturns);
195 G_debug(2,
"Set nodes' costs");
221 _(
"Data type of column <%s> not supported (must be numeric)"),
228 G_debug(1,
"node costs: nrec = %d", nrec);
240 for (i = 1; i <= nnodes; i++) {
256 for (j = 0; j < List->
n_values; j++) {
258 G_debug(2,
" line (%d) = %d", j, line);
263 if (ncol !=
NULL && !cfound &&
276 _(
"Database record for node %d (cat = %d) not found "
303 if (!tucfound && ret) {
307 for (i_line = 0; i_line < nnode_lns; i_line++) {
324 "Add arc %d for virtual node from %d to %d cost = %d",
325 i_virt_edge, f,
t, 0);
332 "node connection."));
344 "Add arc %d for virtual node from %d to %d cost = %d",
345 i_virt_edge, f,
t, 0);
352 "node connection."));
363 G_warning(
_(
"There exists more than one point of node <%d> with "
364 "unique category field <%d>.\n"
365 "The unique categories layer is not valid therefore "
366 "you will probably get incorrect results."),
369 if (ncol !=
NULL && !cfound)
372 "Category of field %d is not attached to any points in node %d"
379 for (i = 1; i <= nturns; i++) {
394 &node_pt_id) == -1) {
396 _(
"Unable to find point representing intersection <%d> in "
397 "unique categories field <%d>.\n"
398 "Cost for the intersection was set to 0.\n"
399 "The unique categories layer is not valid therefore you "
400 "will probably get incorrect results."),
409 if (node_pt_id == 0) {
411 _(
"Unable to find node for point representing "
412 "intersection <%d> in unique categories field <%d>.\n"
413 "Cost for the intersection was set to 0.\n"
414 "The unique categories layer is not valid therefore "
415 "you will probably get incorrect results."),
419 G_debug(2,
" node = %d", node_pt_id);
425 G_debug(2,
"Set node's cost to %f", dcost);
438 _(
"Database record for turn with cat = %d is not found. "
439 "(The turn was skipped."),
463 G_debug(5,
"Add arc/turn %d for turn from %d to %d cost = %d",
464 turn_cat, f,
t, cost);
471 _(
"Cannot add network arc representing turn."));
515 _(
"Data type of column <%s> not supported (must be numeric)"),
521 G_debug(1,
"forward costs: nrec = %d", nrec);
539 G_debug(1,
"backward costs: nrec = %d", nrec);
548 for (i = 1; i <= nlines; i++) {
564 G_warning(
_(
"Line with id <%d> has more unique categories defined "
566 "The unique categories layer is not valid therefore "
567 "you will probably get incorrect results."),
573 "Category of field %d not attached to the line %d -> "
587 G_warning(
_(
"Database record for line %d (cat = %d, "
588 "forward/both direction(s)) not found "
589 "(cost was set to 0)"),
603 G_warning(
_(
"Database record for line %d (cat = %d, "
604 "backward direction) not found"
605 "(cost was set to 0)"),
633 G_debug(5,
"Setinng node %d cost: %d", cat, cost);
643 G_debug(5,
"Setinng node %d cost: %d", cat, cost);
649 if (afcol !=
NULL && skipped > 0)
650 G_debug(2,
"%d lines missing category of field %d skipped", skipped,
704 int nfield,
const char *afcol,
const char *abcol,
705 const char *ncol,
int geo,
int version)
708 int i, j, from, to, line, nlines, nnodes, ret, type, cat, skipped, cfound;
712 double dcost, bdcost, ll;
716 dglInt32_t opaqueset[16] = {360000, 0, 0, 0, 0, 0, 0, 0,
717 0, 0, 0, 0, 0, 0, 0, 0};
724 int fctype = 0, bctype = 0, nrec;
727 G_debug(1,
"Vect_net_build_graph(): ltype = %d, afield = %d, nfield = %d",
728 ltype, afield, nfield);
729 G_debug(1,
" afcol = %s, abcol = %s, ncol = %s", afcol, abcol, ncol);
742 if (afcol ==
NULL && ll && !geo)
758 for (i = 1; i <= nlines; i++) {
762 for (i = 1; i <= nnodes; i++) {
766 if (version < 1 || version > 3)
812 _(
"Data type of column <%s> not supported (must be numeric)"),
818 G_debug(1,
"forward costs: nrec = %d", nrec);
836 G_debug(1,
"backward costs: nrec = %d", nrec);
845 for (i = 1; i <= nlines; i++) {
857 "Category of field %d not attached to the line %d -> "
872 G_warning(
_(
"Database record for line %d (cat = %d, "
873 "forward/both direction(s)) not found "
874 "(forward/both direction(s) of line skipped)"),
889 G_warning(
_(
"Database record for line %d (cat = %d, "
890 "backward direction) not found"
891 "(direction of line skipped)"),
916 if (dofw && dcost != -1) {
918 G_debug(5,
"Add arc %d from %d to %d cost = %d", i, from, to, cost);
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,
940 if (afcol !=
NULL && skipped > 0)
941 G_debug(2,
"%d lines missing category of field %d skipped", skipped,
962 G_debug(2,
"Set nodes' costs");
988 _(
"Data type of column <%s> not supported (must be numeric)"),
994 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);
1031 G_warning(
_(
"Database record for node %d (cat = %d) "
1043 "Category of field %d not attached to any points in node %d"
1055 G_debug(3,
"Set node's cost to %d", cost);
Main header of GRASS DataBase Management Interface.
void db_CatValArray_free(dbCatValArray *)
Free allocated dbCatValArray.
int db_CatValArray_get_value_int(dbCatValArray *, int, int *)
Find value (integer) by key.
void db_CatValArray_init(dbCatValArray *)
Initialize dbCatValArray.
int db_get_column(dbDriver *, const char *, const char *, dbColumn **)
Get column structure by table and column name.
int db_sqltype_to_Ctype(int)
Get C data type based on given SQL data type.
int db_get_column_sqltype(dbColumn *)
Returns column sqltype for column.
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
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)
void db_free_column(dbColumn *)
Frees column structure.
void db_init_handle(dbHandle *)
Initialize handle (i.e database/schema)
void db_init_string(dbString *)
Initialize dbString.
int db_CatValArray_get_value_double(dbCatValArray *, int, double *)
Find value (double) by key.
void G_percent(long, long, int)
Print percent complete messages.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void G_message(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
int G_projection(void)
Query cartographic projection.
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
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.
plus_t Vect_get_num_lines(struct Map_info *)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
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.
double Vect_line_geodesic_length(const struct line_pnts *)
Calculate line length.
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_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
struct field_info * Vect_get_field(struct Map_info *, int)
Get information about link to database (by layer number)
void Vect_destroy_field_info(struct field_info *)
Free a struct field_info and all memory associated with it.
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.
int Vect_get_node_n_lines(struct Map_info *, int)
Get number of lines for node.
plus_t Vect_get_num_nodes(struct Map_info *)
Get number of nodes in vector map.
int Vect_find_node(struct Map_info *, double, double, double, double, int)
Find the nearest node.
int Vect_get_node_line(struct Map_info *, int, int)
Get line id for node line index.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
#define GV_POINT
Feature types used in memory on run time (may change)
#define WITHOUT_Z
2D/3D vector data
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
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_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.
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.
struct bound_box * box
Array of bounding boxes.
int n_values
Number of items in the list.
Layer (old: field) information.
char * table
Name of DB table.
char * driver
Name of DB driver ('sqlite', 'dbf', ...)
char * key
Name of key column (usually 'cat')
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
double * z
Array of Z coordinates.
int dglAddEdge(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
void dglNodeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode, dglInt32_t *pnAttr)
int dglInitialize(dglGraph_s *pGraph, dglByte_t Version, dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize, dglInt32_t *pOpaqueSet)
int dglInitializeSPCache(dglGraph_s *pGraph, dglSPCache_s *pCache)
int dglFlatten(dglGraph_s *pGraph)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)