[GRASS-SVN] r67755 - grass/trunk/vector/v.net

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 7 03:59:16 PST 2016


Author: turek
Date: 2016-02-07 03:59:16 -0800 (Sun, 07 Feb 2016)
New Revision: 67755

Modified:
   grass/trunk/vector/v.net/main.c
   grass/trunk/vector/v.net/turntable.c
Log:
v.net operation=turntable: use directly functions for GRASS vector native format

Modified: grass/trunk/vector/v.net/main.c
===================================================================
--- grass/trunk/vector/v.net/main.c	2016-02-07 11:13:14 UTC (rev 67754)
+++ grass/trunk/vector/v.net/main.c	2016-02-07 11:59:16 UTC (rev 67755)
@@ -10,7 +10,7 @@
  *               
  * PURPOSE:      Network maintenance
  *               
- * COPYRIGHT:    (C) 2001-2009,2014 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2001-2009,2014,2016 by the GRASS Development Team
  *
  *               This program is free software under the 
  *               GNU General Public License (>=v2). 

Modified: grass/trunk/vector/v.net/turntable.c
===================================================================
--- grass/trunk/vector/v.net/turntable.c	2016-02-07 11:13:14 UTC (rev 67754)
+++ grass/trunk/vector/v.net/turntable.c	2016-02-07 11:59:16 UTC (rev 67755)
@@ -248,8 +248,7 @@
 
     int *features_id;
 
-    int n_node_lns, n_features, i_line, j_line, next_ttb_cat, i_ucat,
-	i_rew_lines, n_lines;
+    int n_node_lns, n_features, i_line, j_line, next_ttb_cat, i_ucat, n_lines;
     int n_nodes, pivot_node, outside_node, isec_start_ucat, isec_end_ucat,
 	node1, node2, found_pt_id;
     int ln_i_id, ln_j_id, ln_i_ucat, ln_j_ucat;
@@ -302,11 +301,6 @@
     /* Stores number of category which will be assigned to a next feature added into tucfield. */
     i_ucat = 1;
 
-    /* Stores number of rewritten features. If feature is rewritten, it can be sought by sum of
-       i_ucat + i_rew_lines variables values (id), when was rewritten. 
-       The value is saved into features_id array. */
-    i_rew_lines = 0;
-
     list = G_new_ilist();
 
     /* Every node represents one intersection. */
@@ -329,6 +323,7 @@
 	    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 (ltype_i <= 0) {G_fatal_error(_("Unable to read line from <%s>."), Vect_get_full_name(InMap));}
 
 		/* If line does not belong into arc layer, skip it. */
 		if (Vect_field_cat_get(cats_i, a_field, list) < 0 ||
@@ -346,8 +341,10 @@
 	    else {
 		ln_i_id = Vect_get_node_line(InMap, pivot_node, i_line);
 
-		ltype_i = Vect_read_line(OutMap, line_pnts_i, cats_i,
+		ltype_i = V1_read_line_nat(OutMap, line_pnts_i, cats_i,
 					 features_id[abs(ln_i_id) - 1]);
+		 if (ltype_i <= 0) {G_fatal_error(_("Unable to read line from <%s>."), Vect_get_full_name(OutMap));}
+
 		Vect_cat_get(cats_i, tucfield, &ln_i_ucat);
 
 		/* add line direction information to ucat */
@@ -366,6 +363,7 @@
 		    ltype_j =
 			Vect_read_line(InMap, line_pnts_j, cats_j,
 				       abs(ln_j_id));
+			if (ltype_j <= 0) {G_fatal_error(_("Unable to read line from <%s>."), Vect_get_full_name(InMap));}
 
 		    /* If line does not belong into arc layer, skip it. */
 		    if (Vect_field_cat_get(cats_j, a_field, list) < 0 ||
@@ -446,14 +444,6 @@
 			(driver, ttb_name, &next_ttb_cat, abs(ln_j_ucat),
 			 isec_start_ucat, isec_end_ucat) < 0) {
 
-			G_free_ilist(list);
-			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."));
 		    }
@@ -473,7 +463,7 @@
 		    /* 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);
+			V1_write_line_nat(OutMap, ltype_j, line_pnts_j, cats_j);
 
 		    /* 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 
@@ -492,8 +482,9 @@
 		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,
+		    ltype_j = V1_read_line_nat(OutMap, line_pnts_j, cats_j,
 					     features_id[abs(ln_j_id) - 1]);
+			if (ltype_j <= 0) {G_fatal_error(_("Unable to read line from <%s>."), Vect_get_full_name(OutMap));}
 
 		    /* set category in turntable for new turn, which will be written */
 		    Vect_cat_set(cats_j, tfield, next_ttb_cat);
@@ -508,15 +499,9 @@
 			ln_j_ucat *= -1;
 
 		    /* rewrite j line with the added new category for the turn */
-		    Vect_rewrite_line(OutMap, features_id[abs(ln_j_id) - 1],
+		    features_id[abs(ln_j_id) - 1] = V1_rewrite_line_nat(OutMap, features_id[abs(ln_j_id) - 1],
 				      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;
-
-		    /* increment number of rewritten elements, for more see initialization of the variable */
-		    ++i_rew_lines;
 		}
 
 		/* We have to decide which nodes will be connected, which depends on lines directions.
@@ -535,26 +520,18 @@
 			      ln_i_ucat, line_pnts_i, ln_j_ucat, line_pnts_j,
 			      isec_start_ucat) < 0) {
 
-		    G_free_ilist(list);
-		    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],
+	    features_id[abs(ln_i_id) - 1] = V1_rewrite_line_nat(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;
+		    
 	}
+
     }
 
     box_List = Vect_new_boxlist(0);
@@ -574,6 +551,7 @@
 	for (i_line = 0; i_line < box_List->n_values; i_line++) {
 	    ln_i_id = box_List->id[i_line];
 	    ltype_i = Vect_read_line(InMap, line_pnts_i, cats_i, ln_i_id);
+	    if (ltype_i <= 0) {G_fatal_error(_("Unable to read line from <%s>."), Vect_get_full_name(InMap));}
 
 	    if (ltype_i & GV_POINT) {
 		found_pt_id = ln_i_id;



More information about the grass-commit mailing list