[GRASS-SVN] r72985 - grass/trunk/vector/v.distance

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 13 06:31:57 PDT 2018


Author: mmetz
Date: 2018-07-13 06:31:57 -0700 (Fri, 13 Jul 2018)
New Revision: 72985

Modified:
   grass/trunk/vector/v.distance/main.c
Log:
v.distance: do not clear existing records if no nearest feature found

Modified: grass/trunk/vector/v.distance/main.c
===================================================================
--- grass/trunk/vector/v.distance/main.c	2018-07-13 11:45:49 UTC (rev 72984)
+++ grass/trunk/vector/v.distance/main.c	2018-07-13 13:31:57 UTC (rev 72985)
@@ -422,13 +422,12 @@
     n_max_steps = 1;
     max_map = max;
     if (max != 0) {
-	struct bound_box fbox, tbox;
 	double dx, dy, dz;
 
 	Vect_get_map_box(&From, &fbox);
-	Vect_get_map_box(&To, &tbox);
+	Vect_get_map_box(&To, &box);
 
-	Vect_box_extend(&fbox, &tbox);
+	Vect_box_extend(&fbox, &box);
 
 	dx = fbox.E - fbox.W;
 	dy = fbox.N - fbox.S;
@@ -1138,7 +1137,7 @@
 
 		/* For each area in box check the distance */
 		for (i = 0; i < aList->n_values; i++) {
-		    int tmp_tcat, poly;
+		    int poly;
 
 		    tarea = aList->id[i];
 		    G_debug(4, "%d: 'to' area id %d", i, tarea);
@@ -1597,6 +1596,8 @@
 	    }
 	}
 	else if (update_table) {	/* update table */
+	    int do_update = 0;
+
 	    /* check if exists in table */
 	    cex =
 		(int *)bsearch((void *)&(Near[i].from_cat), catexist,
@@ -1619,9 +1620,11 @@
 		db_append_string(&stmt, buf2);
 
 		if (Near[i].count == 0) {	/* no nearest found */
+		    /* really clear existing records if no nearest found ? */
 		    db_append_string(&stmt, " null");
 		}
 		else {
+		    do_update = 1;
 		    switch (Upload[j].upload) {
 		    case CAT:
 			if (Near[i].to_cat > 0)
@@ -1686,15 +1689,17 @@
 		}
 		j++;
 	    }
-	    sprintf(buf2, " where %s = %d", Fi->key, Near[i].from_cat);
-	    db_append_string(&stmt, buf2);
-	    G_debug(2, "SQL: %s", db_get_string(&stmt));
-	    if (db_execute_immediate(driver, &stmt) == DB_OK) {
-		update_ok++;
+	    if (do_update) {
+		sprintf(buf2, " where %s = %d", Fi->key, Near[i].from_cat);
+		db_append_string(&stmt, buf2);
+		G_debug(2, "SQL: %s", db_get_string(&stmt));
+		if (db_execute_immediate(driver, &stmt) == DB_OK) {
+		    update_ok++;
+		}
+		else {
+		    update_err++;
+		}
 	    }
-	    else {
-		update_err++;
-	    }
 	}
     }
     G_percent(count, count, 1);



More information about the grass-commit mailing list