[GRASS-SVN] r73044 - grass/branches/releasebranch_7_4/vector/v.distance

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 3 14:48:21 PDT 2018


Author: mmetz
Date: 2018-08-03 14:48:20 -0700 (Fri, 03 Aug 2018)
New Revision: 73044

Modified:
   grass/branches/releasebranch_7_4/vector/v.distance/main.c
Log:
v.distance: use default db connection of current mapset for new vector db connection; do not clear existing records if no nearest feature found (backport trunk r72984,5)

Modified: grass/branches/releasebranch_7_4/vector/v.distance/main.c
===================================================================
--- grass/branches/releasebranch_7_4/vector/v.distance/main.c	2018-08-03 21:43:56 UTC (rev 73043)
+++ grass/branches/releasebranch_7_4/vector/v.distance/main.c	2018-08-03 21:48:20 UTC (rev 73044)
@@ -424,13 +424,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;
@@ -1140,7 +1139,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);
@@ -1599,6 +1598,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,
@@ -1621,9 +1622,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)
@@ -1688,15 +1691,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);
@@ -1750,7 +1755,6 @@
 	if (create_table) {
 	    dbConnection connection;
 
-	    db_set_default_connection();
 	    db_get_connection(&connection);
 	    Vect_map_add_dblink(Outp, 1, NULL, opt.table->answer, "cat",
 				connection.databaseName,



More information about the grass-commit mailing list