[GRASS-SVN] r56564 - grass-addons/grass7/vector/v.net.turntable
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 2 11:59:11 PDT 2013
Author: turek
Date: 2013-06-02 11:59:10 -0700 (Sun, 02 Jun 2013)
New Revision: 56564
Modified:
grass-addons/grass7/vector/v.net.turntable/main.c
grass-addons/grass7/vector/v.net.turntable/ttb.c
Log:
v.net.turntable: indent
Modified: grass-addons/grass7/vector/v.net.turntable/main.c
===================================================================
--- grass-addons/grass7/vector/v.net.turntable/main.c 2013-06-02 17:14:10 UTC (rev 56563)
+++ grass-addons/grass7/vector/v.net.turntable/main.c 2013-06-02 18:59:10 UTC (rev 56564)
@@ -26,9 +26,9 @@
#include <grass/glocale.h>
/*
-IDEA: This module could be included into v.net module
- (both modules do service for vector network analyses)???
-*/
+ IDEA: This module could be included into v.net module
+ (both modules do service for vector network analyses)???
+ */
void close_db(void *p)
@@ -46,7 +46,8 @@
struct field_info *fi;
struct Option *opt_in_map, *opt_out_map;
- struct Option *opt_ttb_name, *opt_afield, *opt_tfield, *opt_tucfield, *opt_type;
+ struct Option *opt_ttb_name, *opt_afield, *opt_tfield, *opt_tucfield,
+ *opt_type;
char *database_name, *driver_name;
int i_field_num, field_num, i_field, type;
@@ -121,29 +122,32 @@
type = Vect_option_to_types(opt_type);
- afield = Vect_get_field_number(&InMap, opt_afield->answer);
- tfield = Vect_get_field_number(&InMap, opt_tfield->answer);
+ afield = Vect_get_field_number(&InMap, opt_afield->answer);
+ tfield = Vect_get_field_number(&InMap, opt_tfield->answer);
tucfield = Vect_get_field_number(&InMap, opt_tucfield->answer);
- if(!Vect_get_field (&InMap, afield))
- G_fatal_error(_("Arc layer <%s> does not exists in map <%s>."),
- opt_afield->answer, opt_out_map->answer);
+ if (!Vect_get_field(&InMap, afield))
+ G_fatal_error(_("Arc layer <%s> does not exists in map <%s>."),
+ opt_afield->answer, opt_out_map->answer);
- if(Vect_get_field (&InMap, tfield))
- G_warning(_("Layer <%s> already exists in map <%s>.\nIt will be overwritten by tlayer data."),
- opt_tfield->answer, opt_out_map->answer);
+ if (Vect_get_field(&InMap, tfield))
+ G_warning(_
+ ("Layer <%s> already exists in map <%s>.\nIt will be overwritten by tlayer data."),
+ opt_tfield->answer, opt_out_map->answer);
- if(Vect_get_field (&InMap, tucfield))
- G_warning(_("Layer <%s> already exists in map <%s>.\nIt will be overwritten by tuclayer data."),
- opt_tucfield->answer, opt_out_map->answer);
+ if (Vect_get_field(&InMap, tucfield))
+ G_warning(_
+ ("Layer <%s> already exists in map <%s>.\nIt will be overwritten by tuclayer data."),
+ opt_tucfield->answer, opt_out_map->answer);
ttb_name = NULL;
if (!opt_ttb_name->answer) {
- G_asprintf(&ttb_name, "%s_%s_turntable_%s",
- opt_out_map->answer, opt_tfield->answer, opt_afield->answer);
+ G_asprintf(&ttb_name, "%s_%s_turntable_%s",
+ opt_out_map->answer, opt_tfield->answer,
+ opt_afield->answer);
}
else {
- ttb_name = G_store(opt_out_map->answer);
+ ttb_name = G_store(opt_out_map->answer);
}
if (Vect_open_new(&OutMap, opt_out_map->answer, WITHOUT_Z) < 1) {
@@ -159,11 +163,11 @@
if (Vect_map_check_dblink(&InMap, i_field_num, NULL) == 0)
continue;
- if(field_num == -1)
- field_num = i_field_num;
+ if (field_num == -1)
+ field_num = i_field_num;
- if(field_num != tfield && field_num != tucfield)
- Vect_copy_tables(&InMap, &OutMap, field_num);
+ if (field_num != tfield && field_num != tucfield)
+ Vect_copy_tables(&InMap, &OutMap, field_num);
}
if (field_num < 0) {
@@ -218,7 +222,7 @@
Vect_close(&OutMap);
- /*TODO why must be closed and opened again?*/
+ /*TODO why must be closed and opened again? */
Vect_open_old(&OutMap, opt_out_map->answer, G_mapset());
Vect_build(&OutMap);
Modified: grass-addons/grass7/vector/v.net.turntable/ttb.c
===================================================================
--- grass-addons/grass7/vector/v.net.turntable/ttb.c 2013-06-02 17:14:10 UTC (rev 56563)
+++ grass-addons/grass7/vector/v.net.turntable/ttb.c 2013-06-02 18:59:10 UTC (rev 56564)
@@ -14,7 +14,7 @@
int n_points = Vect_get_num_line_points(points);
if (n_points < 2)
- return (-9.0);
+ return (-9.0);
Vect_line_get_point(points, 0, &x_start, &y_start, &z);
Vect_line_get_point(points, n_points - 1, &x_end, &y_end, &z);
@@ -23,9 +23,9 @@
y = y_end - y_start;
if (y == 0.0 && x == 0.0)
- return (0.0);
+ return (0.0);
else
- return (atan2(y, x));
+ return (atan2(y, x));
}
/*\brief Compute angle of two lines, which is defined by start and end point of the lines.
@@ -40,8 +40,8 @@
\return -9.0 if line is defined by one point or has same start and end point
*/
-double compute_lines_angle(struct line_pnts *line_pnts_from, int from_dir,
- struct line_pnts *line_pnts_to, int to_dir)
+double compute_lines_angle(struct line_pnts *line_pnts_from, int from_dir,
+ struct line_pnts *line_pnts_to, int to_dir)
{
double angle_from, angle_to;
double angle;
@@ -55,78 +55,82 @@
Vect_line_get_point(line_pnts_from, n_points_from - 1, &x2, &y2, &z);
if (x1 == x2 && y1 == y2)
- return -9.0;
+ return -9.0;
Vect_line_get_point(line_pnts_to, 0, &x1, &y1, &z);
Vect_line_get_point(line_pnts_to, n_points_to - 1, &x2, &y2, &z);
- if (x1== x2 && y1 == y2)
- return -9.0;
+ if (x1 == x2 && y1 == y2)
+ return -9.0;
if (from_dir > 0)
- Vect_line_reverse(line_pnts_from);
+ Vect_line_reverse(line_pnts_from);
if (to_dir < 0)
- Vect_line_reverse(line_pnts_to);
+ Vect_line_reverse(line_pnts_to);
angle_from = compute_line_nodes_angle(line_pnts_from);
angle_to = compute_line_nodes_angle(line_pnts_to);
if (angle_from == -9.0)
- angle = angle_from;
+ angle = angle_from;
else if (angle_to == -9.0)
- angle = angle_to;
+ angle = angle_to;
else {
- angle = angle_from - angle_to;
+ angle = angle_from - angle_to;
- if (angle > M_PI)
- angle = -2 * M_PI + angle;
+ if (angle > M_PI)
+ angle = -2 * M_PI + angle;
- if (angle < -M_PI)
- angle = 2 * M_PI + angle;
+ if (angle < -M_PI)
+ angle = 2 * M_PI + angle;
}
/* reverse it back to original order */
if (from_dir > 0)
- Vect_line_reverse(line_pnts_from);
+ Vect_line_reverse(line_pnts_from);
if (to_dir < 0)
- Vect_line_reverse(line_pnts_to);
+ Vect_line_reverse(line_pnts_to);
return angle;
}
/*\brief Add line uturns into turntable.
-
- Add two records into turntable because every line has two possible U-turns.
-*/
-int add_uturn(dbDriver * driver, char *ttb_name, int * next_ttb_cat, int ln_cat, int isec_start_cat, int isec_end_cat){
+
+ Add two records into turntable because every line has two possible U-turns.
+ */
+int add_uturn(dbDriver * driver, char *ttb_name, int *next_ttb_cat,
+ int ln_cat, int isec_start_cat, int isec_end_cat)
+{
int i, isec;
dbString db_buf;
char buf[DB_SQL_MAX];
+
db_init_string(&db_buf);
ln_cat = abs(ln_cat);
isec = isec_end_cat;
- for(i = 0; i < 2; ++i) {
- if(i == 1) {
- ln_cat = -1 * ln_cat;
- isec = isec_start_cat;
- }
- /* cat, ln_from, ln_to, cost, isec, angle */
- sprintf(buf,
- "INSERT INTO %s values ( %d, %d, %d, %f, %d, %f);",
- ttb_name, (*next_ttb_cat), ln_cat, ln_cat * -1, 0.0,
- isec, M_PI);
- db_set_string(&db_buf, buf);
+ for (i = 0; i < 2; ++i) {
+ if (i == 1) {
+ ln_cat = -1 * ln_cat;
+ isec = isec_start_cat;
+ }
+ /* cat, ln_from, ln_to, cost, isec, angle */
+ sprintf(buf,
+ "INSERT INTO %s values ( %d, %d, %d, %f, %d, %f);",
+ ttb_name, (*next_ttb_cat), ln_cat, ln_cat * -1, 0.0,
+ isec, M_PI);
+ db_set_string(&db_buf, buf);
- G_debug(3, "Adding u-turn into turntable:\n%s", db_get_string(&db_buf));
+ G_debug(3, "Adding u-turn into turntable:\n%s",
+ db_get_string(&db_buf));
- if (db_execute_immediate(driver, &db_buf) != DB_OK){
- db_free_string(&db_buf);
- return -1;
- }
- ++(*next_ttb_cat);
+ if (db_execute_immediate(driver, &db_buf) != DB_OK) {
+ db_free_string(&db_buf);
+ return -1;
+ }
+ ++(*next_ttb_cat);
}
db_free_string(&db_buf);
@@ -135,11 +139,13 @@
/*\brief Add turns for two lines into turntable.
-
- Add two records into turntable because we can take the turn from two opposite directions.
-*/
-int add_turns(dbDriver * driver, char *ttb_name, int * next_ttb_cat,
- int ln_i_cat, struct line_pnts *line_pnts_i, int ln_j_cat, struct line_pnts *line_pnts_j, int isec_cat){
+
+ Add two records into turntable because we can take the turn from two opposite directions.
+ */
+int add_turns(dbDriver * driver, char *ttb_name, int *next_ttb_cat,
+ int ln_i_cat, struct line_pnts *line_pnts_i, int ln_j_cat,
+ struct line_pnts *line_pnts_j, int isec_cat)
+{
int i, combinations;
int ln_f, ln_t;
dbString db_buf;
@@ -156,13 +162,11 @@
/* compute angle if the lines angle is computed from ln_from_cat to ln_to_cat */
if (ln_to_cat == ln_i_cat)
- angle =
- compute_lines_angle(line_pnts_j, ln_j_dir,
- line_pnts_i, ln_i_dir);
+ angle =
+ compute_lines_angle(line_pnts_j, ln_j_dir, line_pnts_i, ln_i_dir);
else
- angle =
- compute_lines_angle(line_pnts_i, ln_i_dir,
- line_pnts_j, ln_j_dir);
+ angle =
+ compute_lines_angle(line_pnts_i, ln_i_dir, line_pnts_j, ln_j_dir);
ln_i_cat = abs(ln_i_cat);
ln_j_cat = abs(ln_j_cat);
@@ -170,55 +174,54 @@
ln_from_cat = ln_i_cat;
ln_to_cat = ln_j_cat;
- /*Find right lines nodes (positive or negative), will be connected by the turn.*/
+ /*Find right lines nodes (positive or negative), will be connected by the turn. */
if (ln_j_dir < 0 && ln_i_dir < 0)
- ln_to_cat *= -1;
+ ln_to_cat *= -1;
else if (ln_j_dir > 0 && ln_i_dir > 0)
- ln_from_cat *= -1;
+ ln_from_cat *= -1;
else if (ln_j_dir < 0) {
- ln_to_cat = ln_i_cat;
- ln_from_cat = ln_j_cat;
+ ln_to_cat = ln_i_cat;
+ ln_from_cat = ln_j_cat;
}
ln_f = ln_from_cat;
ln_t = ln_to_cat;
- /*Create first turn from i to j, then create turn in the opposite direction.*/
- for(i = 0; i < 2; ++i) {
+ /*Create first turn from i to j, then create turn in the opposite direction. */
+ for (i = 0; i < 2; ++i) {
- /* connect right nodes for opposite turn */
- if(i == 1) {
- ln_f = ln_to_cat * -1;
- ln_t = ln_from_cat * -1;
- }
+ /* connect right nodes for opposite turn */
+ if (i == 1) {
+ ln_f = ln_to_cat * -1;
+ ln_t = ln_from_cat * -1;
+ }
- /* cat, ln_from, ln_to, cost, isec, angle */
- sprintf(buf,
- "INSERT INTO %s values ( %d, %d, %d, %f, %d,",
- ttb_name, (*next_ttb_cat), ln_f, ln_t, 0.0,
- isec_cat);
- db_set_string(&db_buf, buf);
+ /* cat, ln_from, ln_to, cost, isec, angle */
+ sprintf(buf,
+ "INSERT INTO %s values ( %d, %d, %d, %f, %d,",
+ ttb_name, (*next_ttb_cat), ln_f, ln_t, 0.0, isec_cat);
+ db_set_string(&db_buf, buf);
- if (angle == -9.0)
- db_append_string(&db_buf, "NULL)");
- else {
- /* the angle is on the other side in opposite turn (e. g. left -> right)*/
- if(i == 1)
- angle *= -1;
+ if (angle == -9.0)
+ db_append_string(&db_buf, "NULL)");
+ else {
+ /* the angle is on the other side in opposite turn (e. g. left -> right) */
+ if (i == 1)
+ angle *= -1;
- sprintf(buf, "%f)", angle);
- db_append_string(&db_buf, buf);
- }
+ sprintf(buf, "%f)", angle);
+ db_append_string(&db_buf, buf);
+ }
- G_debug(3, "Adding turn into turntable:\n%s", db_get_string(&db_buf));
+ G_debug(3, "Adding turn into turntable:\n%s", db_get_string(&db_buf));
- if (db_execute_immediate(driver, &db_buf) != DB_OK){
- db_free_string(&db_buf);
- return -1;
- }
- ++(*next_ttb_cat);
+ if (db_execute_immediate(driver, &db_buf) != DB_OK) {
+ db_free_string(&db_buf);
+ return -1;
+ }
+ ++(*next_ttb_cat);
}
db_free_string(&db_buf);
@@ -228,8 +231,8 @@
void populate_turntable(dbDriver * driver, struct Map_info *InMap,
- struct Map_info *OutMap, char *ttb_name,
- int tfield, int tucfield, int a_field, int arc_type)
+ struct Map_info *OutMap, char *ttb_name,
+ int tfield, int tucfield, int a_field, int arc_type)
{
char buf[DB_SQL_MAX];
struct ilist list;
@@ -237,8 +240,9 @@
int *features_id;
int n_node_lines, n_features, i_line, j_line, next_ttb_cat, i_ucat,
- i_rew_lines, n_lines;
- int n_nodes, pivot_node, outside_node, isec_start_ucat, isec_end_ucat, node1, node2;
+ i_rew_lines, n_lines;
+ int n_nodes, pivot_node, outside_node, isec_start_ucat, isec_end_ucat,
+ node1, node2;
int ln_i_id, ln_j_id, ln_i_ucat, ln_j_ucat;
int ltype_i, ltype_j;
@@ -254,10 +258,10 @@
cats_j = Vect_new_cats_struct();
n_lines = 0;
- if(arc_type & GV_LINE)
- n_lines += Vect_get_num_primitives(InMap, GV_LINE);
- if(arc_type & GV_BOUNDARY)
- n_lines += Vect_get_num_primitives(InMap, GV_BOUNDARY);
+ if (arc_type & GV_LINE)
+ n_lines += Vect_get_num_primitives(InMap, GV_LINE);
+ if (arc_type & GV_BOUNDARY)
+ n_lines += Vect_get_num_primitives(InMap, GV_BOUNDARY);
/*Converts feature input map id into current id in output map.
When the feature is rewritten, it's original state still exists
@@ -270,7 +274,7 @@
n_features = Vect_get_num_lines(InMap);
G_debug(3, "Found %d line features in <%s> vector map", n_features,
- InMap->name);
+ InMap->name);
features_id = G_malloc(sizeof(int) * n_features);
G_zero(features_id, sizeof(int) * n_features);
@@ -295,248 +299,256 @@
/* Every node represents one intersection. */
for (pivot_node = 1; pivot_node <= n_nodes; pivot_node++) {
- n_node_lines = Vect_get_node_n_lines(InMap, pivot_node);
+ n_node_lines = Vect_get_node_n_lines(InMap, pivot_node);
- G_debug(3, "Found %d lines connected to node with id %d",
- n_node_lines, pivot_node);
+ G_debug(3, "Found %d lines connected to node with id %d",
+ n_node_lines, pivot_node);
- /*Creates record in turntable for every possible turn
- in intersection defined by node and lines which meets on the node.
+ /*Creates record in turntable for every possible turn
+ in intersection defined by node and lines which meets on the node.
- It also takes in account U-turns. */
+ It also takes in account U-turns. */
- for (i_line = 0; i_line < n_node_lines; i_line++) {
+ for (i_line = 0; i_line < n_node_lines; i_line++) {
- ln_i_id = Vect_get_node_line(InMap, pivot_node, i_line);
+ ln_i_id = Vect_get_node_line(InMap, pivot_node, i_line);
- /*Line was not written into output map. */
- if (features_id[abs(ln_i_id) - 1] < 1) {
- ltype_i = Vect_read_line(InMap, line_pnts_i, cats_i, abs(ln_i_id));
-
- /* If line does not belong into arc layer, skip it. */
- if (Vect_field_cat_get(cats_i, a_field, &list) < 0 || !(ltype_i & arc_type))
- continue;
+ /*Line was not written into output map. */
+ if (features_id[abs(ln_i_id) - 1] < 1) {
+ ltype_i =
+ Vect_read_line(InMap, line_pnts_i, cats_i, abs(ln_i_id));
- /* Delete categories in tfield and tucfield if they are in input map defined. */
- Vect_field_cat_del(cats_i, tfield, -1);
- Vect_field_cat_del(cats_i, tucfield, -1);
- }
+ /* If line does not belong into arc layer, skip it. */
+ if (Vect_field_cat_get(cats_i, a_field, &list) < 0 ||
+ !(ltype_i & arc_type))
+ continue;
- /*If i line was already written into output map,
- we need to take it's categories from the output map with categories
- for tlayer and tuclayer. */
- else {
- ln_i_id = Vect_get_node_line(InMap, pivot_node, i_line);
+ /* Delete categories in tfield and tucfield if they are in input map defined. */
+ Vect_field_cat_del(cats_i, tfield, -1);
+ Vect_field_cat_del(cats_i, tucfield, -1);
+ }
- ltype_i = Vect_read_line(OutMap, line_pnts_i, cats_i,
- features_id[abs(ln_i_id) - 1]);
- Vect_cat_get(cats_i, tucfield, &ln_i_ucat);
-
- /* add line direction information to ucat */
- if(ln_i_id < 0)
- ln_i_ucat *= -1;
+ /*If i line was already written into output map,
+ we need to take it's categories from the output map with categories
+ for tlayer and tuclayer. */
+ else {
+ ln_i_id = Vect_get_node_line(InMap, pivot_node, i_line);
- }
+ ltype_i = Vect_read_line(OutMap, line_pnts_i, cats_i,
+ features_id[abs(ln_i_id) - 1]);
+ Vect_cat_get(cats_i, tucfield, &ln_i_ucat);
- for (j_line = i_line; j_line < n_node_lines; j_line++) {
+ /* add line direction information to ucat */
+ if (ln_i_id < 0)
+ ln_i_ucat *= -1;
- ln_j_id = Vect_get_node_line(InMap, pivot_node, j_line);
+ }
- /* write line, which have not been written into new map yet. */
- if (features_id[abs(ln_j_id) - 1] < 1) {
- /* Get line from input map. */
- ltype_j = Vect_read_line(InMap, line_pnts_j, cats_j, abs(ln_j_id));
+ for (j_line = i_line; j_line < n_node_lines; j_line++) {
- /* If line does not belong into arc layer, skip it. */
- if (Vect_field_cat_get(cats_j, a_field, &list) < 0 || !(ltype_i & arc_type))
- continue;
+ ln_j_id = Vect_get_node_line(InMap, pivot_node, j_line);
- /* Delete categories in tfield and tucfield if they are in input map defined. */
- Vect_field_cat_del(cats_j, tfield, -1);
- Vect_field_cat_del(cats_j, tucfield, -1);
+ /* write line, which have not been written into new map yet. */
+ if (features_id[abs(ln_j_id) - 1] < 1) {
+ /* Get line from input map. */
+ ltype_j =
+ Vect_read_line(InMap, line_pnts_j, cats_j,
+ abs(ln_j_id));
- /* Write U-turn for every not yet written line. */
+ /* If line does not belong into arc layer, skip it. */
+ if (Vect_field_cat_get(cats_j, a_field, &list) < 0 ||
+ !(ltype_i & arc_type))
+ continue;
- /* Assign unique category (assigned only when feature is written). */
- Vect_cat_set(cats_j, tucfield, i_ucat);
+ /* Delete categories in tfield and tucfield if they are in input map defined. */
+ Vect_field_cat_del(cats_j, tfield, -1);
+ Vect_field_cat_del(cats_j, tucfield, -1);
- /* Assign turn category in turntable for the U-turn. */
- Vect_cat_set(cats_j, tfield, next_ttb_cat);
- Vect_cat_set(cats_j, tfield, next_ttb_cat + 1);
+ /* Write U-turn for every not yet written line. */
- /* If i line and j line are different, we also need to insert a turn which is defined
- by these two edges, therefore we need to add new tfield category to j line, which is corresponding
- to the turn. */
- if (ln_j_id != ln_i_id) {
- Vect_cat_set(cats_j, tfield, next_ttb_cat);
- Vect_cat_set(cats_j, tfield, next_ttb_cat + 1);
- }
+ /* Assign unique category (assigned only when feature is written). */
+ Vect_cat_set(cats_j, tucfield, i_ucat);
- ln_j_ucat = i_ucat;
-
- /* add line direction information to ucat */
- if(ln_j_id < 0)
- ln_j_ucat *= -1;
+ /* Assign turn category in turntable for the U-turn. */
+ Vect_cat_set(cats_j, tfield, next_ttb_cat);
+ Vect_cat_set(cats_j, tfield, next_ttb_cat + 1);
- /* We create two nodes in turntable for every line. These nodes have
- positive and negative values, with their absolute values identical.
+ /* If i line and j line are different, we also need to insert a turn which is defined
+ by these two edges, therefore we need to add new tfield category to j line, which is corresponding
+ to the turn. */
+ if (ln_j_id != ln_i_id) {
+ Vect_cat_set(cats_j, tfield, next_ttb_cat);
+ Vect_cat_set(cats_j, tfield, next_ttb_cat + 1);
+ }
- Every node corresponds to opposite line direction. The positive node
- matches the direction of line. The negative node matches the opposite direction.
+ ln_j_ucat = i_ucat;
- Imagine that you are standing on some road/line before a intersection wanting to cross it.
- If you are going to cross intersection, which is in line direction,
- you are standing on the POSITIVE NODE. If you would cross the intersection from any other line
- to the line, you would come into the NEGATIVE NODE.
+ /* add line direction information to ucat */
+ if (ln_j_id < 0)
+ ln_j_ucat *= -1;
- These two nodes are connected with U-turns, which are two for both direction.
- Every U-turn direction belongs to the another intersection. U-turn from the POSITIVE NODE
- to the NEGATIVE one belongs to the intersection we are going to cross. The other U-turn belongs
- to a intersection in opposite end of the line.
+ /* We create two nodes in turntable for every line. These nodes have
+ positive and negative values, with their absolute values identical.
- Turntable columns:
+ Every node corresponds to opposite line direction. The positive node
+ matches the direction of line. The negative node matches the opposite direction.
- cat - category in tfield (layer with turntable), which are hold by both ln_from and ln_to lines
- ln_from - unique category in tucfield assigned to the line
- ln_to - unique category in tucfield assigned to the line
- cost - cost for turn from ln_from to ln_to
- isec - point category in tucfield, which represents the intersection, where the turn belongs
- angle - in radians, see comments in compute_lines_angle function, it is PI for U-turns
- */
+ Imagine that you are standing on some road/line before a intersection wanting to cross it.
+ If you are going to cross intersection, which is in line direction,
+ you are standing on the POSITIVE NODE. If you would cross the intersection from any other line
+ to the line, you would come into the NEGATIVE NODE.
- /* Find second node (outside_node) of the line. */
- Vect_get_line_nodes(InMap, abs(ln_j_id), &node1, &node2);
+ These two nodes are connected with U-turns, which are two for both direction.
+ Every U-turn direction belongs to the another intersection. U-turn from the POSITIVE NODE
+ to the NEGATIVE one belongs to the intersection we are going to cross. The other U-turn belongs
+ to a intersection in opposite end of the line.
- if (node1 == pivot_node)
- outside_node = node2;
- else
- outside_node = node1;
+ Turntable columns:
- /* Decide intersection where U-turns belongs. */
- if (ln_j_id < 0) {
- isec_start_ucat = outside_node + n_lines;
- isec_end_ucat = pivot_node + n_lines;
- }
- else {
- isec_start_ucat = pivot_node + n_lines;
- isec_end_ucat = outside_node + n_lines;
- }
+ cat - category in tfield (layer with turntable), which are hold by both ln_from and ln_to lines
+ ln_from - unique category in tucfield assigned to the line
+ ln_to - unique category in tucfield assigned to the line
+ cost - cost for turn from ln_from to ln_to
+ isec - point category in tucfield, which represents the intersection, where the turn belongs
+ angle - in radians, see comments in compute_lines_angle function, it is PI for U-turns
+ */
-
- /* If i and j lines are identical, write these categories also into i line,
- otherwise they would be forgotten during rewriting of i line. */
- if (ln_j_id == ln_i_id) {
- Vect_cat_set(cats_i, tfield, next_ttb_cat);
- Vect_cat_set(cats_i, tfield, next_ttb_cat + 1);
- Vect_cat_set(cats_i, tucfield, i_ucat);
- }
+ /* Find second node (outside_node) of the line. */
+ Vect_get_line_nodes(InMap, abs(ln_j_id), &node1, &node2);
- if (add_uturn(driver, ttb_name, &next_ttb_cat, abs(ln_j_ucat), isec_start_ucat, isec_end_ucat) < 0) {
- G_free(features_id);
+ if (node1 == pivot_node)
+ outside_node = node2;
+ else
+ outside_node = node1;
- Vect_destroy_line_struct(line_pnts_i);
- Vect_destroy_line_struct(line_pnts_j);
- Vect_destroy_cats_struct(cats_i);
- Vect_destroy_cats_struct(cats_j);
+ /* Decide intersection where U-turns belongs. */
+ if (ln_j_id < 0) {
+ isec_start_ucat = outside_node + n_lines;
+ isec_end_ucat = pivot_node + n_lines;
+ }
+ else {
+ isec_start_ucat = pivot_node + n_lines;
+ isec_end_ucat = outside_node + n_lines;
+ }
- G_fatal_error(_("Unable to insert data into turntable."));
- }
- /* increment unique category number for next line, which will be written */
- ++i_ucat;
+ /* If i and j lines are identical, write these categories also into i line,
+ otherwise they would be forgotten during rewriting of i line. */
+ if (ln_j_id == ln_i_id) {
+ Vect_cat_set(cats_i, tfield, next_ttb_cat);
+ Vect_cat_set(cats_i, tfield, next_ttb_cat + 1);
+ Vect_cat_set(cats_i, tucfield, i_ucat);
+ }
- /* If i line and j line are different, we also need to insert a turn which is defined
- by these two edges, therefore we need to add new category to j line, which is corresponding
- to the turn.
- */
- if (abs(ln_j_id) != abs(ln_i_id))
- {
- Vect_cat_set(cats_j, tfield, next_ttb_cat);
- Vect_cat_set(cats_j, tfield, next_ttb_cat + 1);
- }
-
- /* Write new line into output map and save it's id to be possible to find it and edit it later
- (when we get to intersection, which is in other end of the line.) */
- features_id[abs(ln_j_id) - 1] =
- Vect_write_line(OutMap, ltype_j, line_pnts_j, cats_j);
+ if (add_uturn
+ (driver, ttb_name, &next_ttb_cat, abs(ln_j_ucat),
+ isec_start_ucat, isec_end_ucat) < 0) {
+ G_free(features_id);
- /* i, j lines are equal, it consists only U-turn
- Absolute values are there because in case of the lines which have same start and end point, we do not want
- to create redundant lines between these points. This combination has been already done by uturn method.
- */
- if (abs(ln_j_id) == abs(ln_i_id)) {
- /* remember unique category also for i line */
- ln_i_ucat = ln_j_ucat;
- continue;
- }
- }
- /* skip if i, j lines are same (U-turn was already written) */
- else if (abs(ln_j_id) == abs(ln_i_id))
- continue;
- /* write new turn combination for already written i, j lines into output map */
- else {
- /* Get modified cats from out map also for j line, which was already written and
- cats differ from the former cats in the line in input map. */
- ltype_j = Vect_read_line(OutMap, line_pnts_j, cats_j,
- features_id[abs(ln_j_id) - 1]);
+ Vect_destroy_line_struct(line_pnts_i);
+ Vect_destroy_line_struct(line_pnts_j);
+ Vect_destroy_cats_struct(cats_i);
+ Vect_destroy_cats_struct(cats_j);
- /* set category in turntable for new turn, which will be written */
- Vect_cat_set(cats_j, tfield, next_ttb_cat);
- Vect_cat_set(cats_j, tfield, next_ttb_cat + 1);
+ G_fatal_error(_
+ ("Unable to insert data into turntable."));
+ }
- /* get already assigned unique category of the j line
- (used for ln_from_cat or ln_to_cat in turntable) */
- Vect_cat_get(cats_j, tucfield, &ln_j_ucat);
+ /* increment unique category number for next line, which will be written */
+ ++i_ucat;
- /* add line direction information to ucat */
- if(ln_j_id < 0)
- ln_j_ucat *= -1;
+ /* If i line and j line are different, we also need to insert a turn which is defined
+ by these two edges, therefore we need to add new category to j line, which is corresponding
+ to the turn.
+ */
+ if (abs(ln_j_id) != abs(ln_i_id)) {
+ Vect_cat_set(cats_j, tfield, next_ttb_cat);
+ Vect_cat_set(cats_j, tfield, next_ttb_cat + 1);
+ }
- /* rewrite j line with added the new category for the turn */
- Vect_rewrite_line(OutMap, features_id[abs(ln_j_id) - 1],
- ltype_j, line_pnts_j, cats_j);
+ /* Write new line into output map and save it's id to be possible to find it and edit it later
+ (when we get to intersection, which is in other end of the line.) */
+ features_id[abs(ln_j_id) - 1] =
+ Vect_write_line(OutMap, ltype_j, line_pnts_j, cats_j);
- /* Because of rewriting, the id of j line was changed,
- therefore we have to update it in features_id. */
- features_id[abs(ln_j_id) - 1] = i_ucat + i_rew_lines;
+ /* i, j lines are equal, it consists only U-turn
+ Absolute values are there because in case of the lines which have same start and end point, we do not want
+ to create redundant lines between these points. This combination has been already done by uturn method.
+ */
+ if (abs(ln_j_id) == abs(ln_i_id)) {
+ /* remember unique category also for i line */
+ ln_i_ucat = ln_j_ucat;
+ continue;
+ }
+ }
+ /* skip if i, j lines are same (U-turn was already written) */
+ else if (abs(ln_j_id) == abs(ln_i_id))
+ continue;
+ /* write new turn combination for already written i, j lines into output map */
+ else {
+ /* Get modified cats from out map also for j line, which was already written and
+ cats differ from the former cats in the line in input map. */
+ ltype_j = Vect_read_line(OutMap, line_pnts_j, cats_j,
+ features_id[abs(ln_j_id) - 1]);
- /* increment number of rewritten elements, for more see initialization of the variable */
- ++i_rew_lines;
- }
+ /* set category in turntable for new turn, which will be written */
+ Vect_cat_set(cats_j, tfield, next_ttb_cat);
+ Vect_cat_set(cats_j, tfield, next_ttb_cat + 1);
- /* We have to decide which nodes will be connected, which depends on lines directions.
- Line direction information is stored in ln_i_id/ln_j_id variables. It the variable is
- negative, the line goes into the intersection. If it is positive the line goes from the
- intersection. */
+ /* get already assigned unique category of the j line
+ (used for ln_from_cat or ln_to_cat in turntable) */
+ Vect_cat_get(cats_j, tucfield, &ln_j_ucat);
+ /* add line direction information to ucat */
+ if (ln_j_id < 0)
+ ln_j_ucat *= -1;
- /* The turn belongs to same intersection regardless the direction. Only exception are the U-turns. */
- isec_start_ucat = isec_end_ucat = pivot_node + n_lines;
+ /* rewrite j line with added the new category for the turn */
+ Vect_rewrite_line(OutMap, features_id[abs(ln_j_id) - 1],
+ ltype_j, line_pnts_j, cats_j);
- Vect_cat_set(cats_i, tfield, next_ttb_cat);
- Vect_cat_set(cats_i, tfield, next_ttb_cat + 1);
+ /* Because of rewriting, the id of j line was changed,
+ therefore we have to update it in features_id. */
+ features_id[abs(ln_j_id) - 1] = i_ucat + i_rew_lines;
- if (add_turns(driver, ttb_name, &next_ttb_cat,
- ln_i_ucat,line_pnts_i, ln_j_ucat, line_pnts_j, isec_start_ucat) < 0) {
- G_free(features_id);
+ /* increment number of rewritten elements, for more see initialization of the variable */
+ ++i_rew_lines;
+ }
- Vect_destroy_line_struct(line_pnts_i);
- Vect_destroy_line_struct(line_pnts_j);
- Vect_destroy_cats_struct(cats_i);
- Vect_destroy_cats_struct(cats_j);
+ /* We have to decide which nodes will be connected, which depends on lines directions.
+ Line direction information is stored in ln_i_id/ln_j_id variables. It the variable is
+ negative, the line goes into the intersection. If it is positive the line goes from the
+ intersection. */
- G_fatal_error(_("Unable to insert data into turntable."));
- }
- }
+ /* The turn belongs to same intersection regardless the direction. Only exception are the U-turns. */
+ isec_start_ucat = isec_end_ucat = pivot_node + n_lines;
- /* rewrite i line */
- Vect_rewrite_line(OutMap, features_id[abs(ln_i_id) - 1],
- ltype_i, line_pnts_i, cats_i);
+ Vect_cat_set(cats_i, tfield, next_ttb_cat);
+ Vect_cat_set(cats_i, tfield, next_ttb_cat + 1);
- features_id[abs(ln_i_id) - 1] = i_ucat + i_rew_lines;
- i_rew_lines += 1;
- }
+ if (add_turns(driver, ttb_name, &next_ttb_cat,
+ ln_i_ucat, line_pnts_i, ln_j_ucat, line_pnts_j,
+ isec_start_ucat) < 0) {
+ G_free(features_id);
+
+ Vect_destroy_line_struct(line_pnts_i);
+ Vect_destroy_line_struct(line_pnts_j);
+ Vect_destroy_cats_struct(cats_i);
+ Vect_destroy_cats_struct(cats_j);
+
+ G_fatal_error(_("Unable to insert data into turntable."));
+ }
+
+ }
+
+ /* rewrite i line */
+ Vect_rewrite_line(OutMap, features_id[abs(ln_i_id) - 1],
+ ltype_i, line_pnts_i, cats_i);
+
+ features_id[abs(ln_i_id) - 1] = i_ucat + i_rew_lines;
+ i_rew_lines += 1;
+ }
}
/* Create point on every node. */
@@ -544,30 +556,31 @@
*/
for (pivot_node = 1; pivot_node <= n_nodes; pivot_node++) {
- Vect_get_node_coor(InMap, pivot_node, &x, &y, &z);
+ Vect_get_node_coor(InMap, pivot_node, &x, &y, &z);
- Vect_reset_line(line_pnts_i);
- Vect_append_point(line_pnts_i, x, y, z);
+ Vect_reset_line(line_pnts_i);
+ Vect_append_point(line_pnts_i, x, y, z);
- Vect_reset_cats(cats_i);
- Vect_cat_set(cats_i, tucfield, i_ucat);
+ Vect_reset_cats(cats_i);
+ Vect_cat_set(cats_i, tucfield, i_ucat);
- Vect_write_line(OutMap, GV_POINT, line_pnts_i, cats_i);
- i_ucat++;
+ Vect_write_line(OutMap, GV_POINT, line_pnts_i, cats_i);
+ i_ucat++;
}
/* copy rest of features, to output map */
while ((ltype_i = Vect_read_next_line(InMap, line_pnts_i, cats_i)) > 0) {
- /* line features in alayer are already in output map*/
- if (ltype_i == arc_type && Vect_field_cat_get(cats_i, a_field, &list) != -1)
- continue;
+ /* line features in alayer are already in output map */
+ if (ltype_i == arc_type &&
+ Vect_field_cat_get(cats_i, a_field, &list) != -1)
+ continue;
- /* Delete categories in tfield and tucfield if they are in input map defined. */
- Vect_field_cat_del(cats_i, tucfield, -1);
- Vect_field_cat_del(cats_i, tfield, -1);
+ /* Delete categories in tfield and tucfield if they are in input map defined. */
+ Vect_field_cat_del(cats_i, tucfield, -1);
+ Vect_field_cat_del(cats_i, tfield, -1);
- Vect_write_line(OutMap, GV_POINT, line_pnts_i, cats_i);
+ Vect_write_line(OutMap, GV_POINT, line_pnts_i, cats_i);
}
@@ -580,4 +593,4 @@
db_commit_transaction(driver);
return;
-}
\ No newline at end of file
+}
More information about the grass-commit
mailing list