[GRASS-SVN] r52168 - in grass/trunk/vector: v.net.allpairs v.net.centrality v.net.connectivity v.net.distance v.net.flow

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 20 07:47:15 PDT 2012


Author: mmetz
Date: 2012-06-20 07:47:15 -0700 (Wed, 20 Jun 2012)
New Revision: 52168

Modified:
   grass/trunk/vector/v.net.allpairs/main.c
   grass/trunk/vector/v.net.centrality/main.c
   grass/trunk/vector/v.net.connectivity/main.c
   grass/trunk/vector/v.net.distance/main.c
   grass/trunk/vector/v.net.flow/main.c
Log:
v.net modules: add safety checks

Modified: grass/trunk/vector/v.net.allpairs/main.c
===================================================================
--- grass/trunk/vector/v.net.allpairs/main.c	2012-06-20 14:35:14 UTC (rev 52167)
+++ grass/trunk/vector/v.net.allpairs/main.c	2012-06-20 14:47:15 UTC (rev 52168)
@@ -145,10 +145,13 @@
     afield = Vect_get_field_number(&In, afield_opt->answer);
     nfield = Vect_get_field_number(&In, nfield_opt->answer);
 
-    chcat =
-	(NetA_initialise_varray
-	 (&In, nfield, GV_POINT, where_opt->answer, cat_opt->answer,
-	  &varray) == 1);
+    if (where_opt->answer || cat_opt->answer) {
+	chcat = (NetA_initialise_varray(&In, nfield, GV_POINT,
+	                                where_opt->answer,
+					cat_opt->answer, &varray) > 0);
+    }
+    else
+	chcat = 0;
 
     /* Create table */
     Fi = Vect_default_field_info(&Out, 1, NULL, GV_1TABLE);

Modified: grass/trunk/vector/v.net.centrality/main.c
===================================================================
--- grass/trunk/vector/v.net.centrality/main.c	2012-06-20 14:35:14 UTC (rev 52167)
+++ grass/trunk/vector/v.net.centrality/main.c	2012-06-20 14:47:15 UTC (rev 52168)
@@ -228,10 +228,13 @@
     afield = Vect_get_field_number(&In, afield_opt->answer);
     nfield = Vect_get_field_number(&In, nfield_opt->answer);
 
-    chcat =
-	(NetA_initialise_varray
-	 (&In, afield, mask_type, where_opt->answer, cat_opt->answer,
-	  &varray) == 1);
+    if (where_opt->answer || cat_opt->answer) {
+	chcat = (NetA_initialise_varray(&In, afield, GV_POINT,
+	                                where_opt->answer,
+					cat_opt->answer, &varray) > 0);
+    }
+    else
+	chcat = 0;
 
     /* Create table */
     Fi = Vect_default_field_info(&Out, 1, NULL, GV_1TABLE);
@@ -340,11 +343,10 @@
 	if (type == GV_POINT && (!chcat || varray->c[i])) {
 	    int cat, node;
 
-	    if (!Vect_cat_get(Cats, afield, &cat))
+	    if (!Vect_cat_get(Cats, nfield, &cat))
 		continue;
 	    Vect_write_line(&Out, type, Points, Cats);
 	    node = Vect_find_node(&In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
-	    /* Vect_get_line_nodes(&In, i, &node, NULL); */
 	    process_node(node, cat);
 	    covered[node] = 1;
 	}

Modified: grass/trunk/vector/v.net.connectivity/main.c
===================================================================
--- grass/trunk/vector/v.net.connectivity/main.c	2012-06-20 14:35:14 UTC (rev 52167)
+++ grass/trunk/vector/v.net.connectivity/main.c	2012-06-20 14:47:15 UTC (rev 52168)
@@ -144,14 +144,18 @@
 
     if (NetA_initialise_varray
 	(&In, nfield, GV_POINT, whereset1_opt->answer,
-	 catset1_opt->answer, &varray_set1) == 2)
-	G_fatal_error(_("Neither %s nor %s was given"), catset1_opt->key,
-		      whereset1_opt->key);
+	 catset1_opt->answer, &varray_set1) <= 0) {
+	G_fatal_error(_("No features for %s selected. "
+			"Please check options '%s', '%s'."),
+			"set1", catset1_opt->key, whereset1_opt->key);
+    }
     if (NetA_initialise_varray
 	(&In, nfield, GV_POINT, whereset2_opt->answer,
-	 catset2_opt->answer, &varray_set2) == 2)
-	G_fatal_error(_("Neither %s nor %s was given"), catset2_opt->key,
-		      whereset2_opt->key);
+	 catset2_opt->answer, &varray_set2) <= 0) {
+	G_fatal_error(_("No features for %s selected. "
+			"Please check options '%s', '%s'."),
+			"set2", catset2_opt->key, whereset2_opt->key);
+    }
 
     set1_list = Vect_new_list();
     set2_list = Vect_new_list();

Modified: grass/trunk/vector/v.net.distance/main.c
===================================================================
--- grass/trunk/vector/v.net.distance/main.c	2012-06-20 14:35:14 UTC (rev 52167)
+++ grass/trunk/vector/v.net.distance/main.c	2012-06-20 14:47:15 UTC (rev 52168)
@@ -230,6 +230,9 @@
     nodest = Vect_new_list();
     NetA_varray_to_nodes(&In, varrayt, nodest, nodes_to_features);
 
+    if (nodest->n_values == 0)
+	G_fatal_error(_("No 'to' features"));
+
     Vect_net_build_graph(&In, atype, afield, nfield, afcol->answer, abcol->answer,
 			 ncol->answer, geo, 0);
 

Modified: grass/trunk/vector/v.net.flow/main.c
===================================================================
--- grass/trunk/vector/v.net.flow/main.c	2012-06-20 14:35:14 UTC (rev 52167)
+++ grass/trunk/vector/v.net.flow/main.c	2012-06-20 14:47:15 UTC (rev 52168)
@@ -194,16 +194,19 @@
 
     if (NetA_initialise_varray
 	(&In, nfield, GV_POINT,
-	 wheresource_opt->answer, catsource_opt->answer, &varray_source) == 2)
-	G_fatal_error(_("Neither %s nor %s was given"), catsource_opt->key,
-		      wheresource_opt->key);
+	 wheresource_opt->answer, catsource_opt->answer, &varray_source) <= 0) {
+	G_fatal_error(_("No source features selected. "
+			"Please check options '%s', '%s'."),
+			catsource_opt->key, wheresource_opt->key);
+    }
     if (NetA_initialise_varray
 	(&In, nfield, GV_POINT, wheresink_opt->answer,
-	 catsink_opt->answer, &varray_sink) == 2)
-	G_fatal_error(_("Neither %s nor %s was given"), catsink_opt->key,
-		      wheresink_opt->key);
+	 catsink_opt->answer, &varray_sink) <= 0) {
+	G_fatal_error(_("No sink features selected. "
+			"Please check options '%s', '%s'."),
+			catsink_opt->key, wheresink_opt->key);
+    }
 
-
     NetA_varray_to_nodes(&In, varray_source, source_list, NULL);
     NetA_varray_to_nodes(&In, varray_sink, sink_list, NULL);
 



More information about the grass-commit mailing list