浏览代码

bugfix for Vect_attach_centroids, ticket https://trac.osgeo.org/grass/ticket/397

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@36192 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 16 年之前
父节点
当前提交
d463f2470f
共有 1 个文件被更改,包括 13 次插入8 次删除
  1. 13 8
      lib/vector/Vlib/build_nat.c

+ 13 - 8
lib/vector/Vlib/build_nat.c

@@ -365,6 +365,10 @@ int Vect_attach_centroids(struct Map_info *Map, BOUND_BOX * box)
      * to check if original area exist, unregister centroid from previous area.
      * To simplify code, this is implemented so that centroid is always firs unregistered 
      * and if new area is found, it is registered again.
+     *
+     * This problem can be avoided altogether if properly attached centroids
+     * are skipped
+     * MM 2009
      */
 
     Vect_select_lines_by_box(Map, box, GV_CENTROID, List);
@@ -376,14 +380,15 @@ int Vect_attach_centroids(struct Map_info *Map, BOUND_BOX * box)
 	Line = plus->Line[centr];
 	Node = plus->Node[Line->N1];
 
-	/* Unregister centroid */
+	/* only attach unregistered and duplicate centroids because 
+	 * 1) all properly attached centroids are properly attached, really! Don't touch.
+	 * 2) Vect_find_area() below does not always return the correct area
+	 * 3) it's faster
+	 */
+	if (Line->left > 0)
+	    continue; 
+
 	orig_area = Line->left;
-	if (orig_area > 0) {
-	    if (plus->Area[orig_area] != NULL) {
-		plus->Area[orig_area]->centroid = 0;
-	    }
-	}
-	Line->left = 0;
 
 	sel_area = Vect_find_area(Map, Node->x, Node->y);
 	G_debug(3, "  centroid %d is in area %d", centr, sel_area);
@@ -396,7 +401,7 @@ int Vect_attach_centroids(struct Map_info *Map, BOUND_BOX * box)
 	    }
 	    else if (Area->centroid != centr) {	/* duplicate centroid */
 		/* Note: it cannot happen that Area->centroid == centr, because the centroid
-		 * was previously unregistered */
+		 * was not registered or a duplicate */
 		G_debug(3, "  duplicate centroid -> do not attach to area");
 		Line->left = -sel_area;
 	    }