[GRASS-SVN] r64039 - grass/branches/releasebranch_7_0/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 9 12:42:11 PST 2015


Author: mmetz
Date: 2015-01-09 12:42:11 -0800 (Fri, 09 Jan 2015)
New Revision: 64039

Modified:
   grass/branches/releasebranch_7_0/lib/vector/Vlib/remove_areas.c
Log:
Vlib: sync Vect_remove_small_areas() to trunk

Modified: grass/branches/releasebranch_7_0/lib/vector/Vlib/remove_areas.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/vector/Vlib/remove_areas.c	2015-01-09 20:25:35 UTC (rev 64038)
+++ grass/branches/releasebranch_7_0/lib/vector/Vlib/remove_areas.c	2015-01-09 20:42:11 UTC (rev 64039)
@@ -10,15 +10,13 @@
    This program is free software under the GNU General Public License
    (>=v2).  Read the file COPYING that comes with GRASS for details.
 
-   \author Radim Blazek
+   \author Radim Blazek, Markus Metz
  */
 
 #include <stdlib.h>
 #include <grass/vector.h>
 #include <grass/glocale.h>
 
-#define DEGUG_RMAREA
-
 int Vect_remove_small_areas_nat(struct Map_info *, double,
                                 struct Map_info *, double *);
 
@@ -43,14 +41,11 @@
 Vect_remove_small_areas(struct Map_info *Map, double thresh,
 			struct Map_info *Err, double *removed_area)
 {
-    return Vect_remove_small_areas_ext(Map, thresh, Err, removed_area);
 
-#if 0
     if (Map->format == GV_FORMAT_NATIVE)
 	return Vect_remove_small_areas_nat(Map, thresh, Err, removed_area);
     else
 	return Vect_remove_small_areas_ext(Map, thresh, Err, removed_area);
-#endif
 }
 
 int
@@ -213,9 +208,7 @@
     struct ilist *List;
     struct ilist *AList;
     struct ilist *BList;
-#ifdef DEGUG_RMAREA
     struct ilist *NList;
-#endif
     struct ilist *IList;
     struct line_pnts *Points;
     struct line_cats *Cats;
@@ -227,9 +220,7 @@
     List = Vect_new_list();
     AList = Vect_new_list();
     BList = Vect_new_list();
-#ifdef DEGUG_RMAREA
     NList = Vect_new_list();
-#endif
     IList = Vect_new_list();
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
@@ -418,10 +409,10 @@
 		    Vect_list_append(IList, Vect_get_area_isle(Map, dissolve_neighbour, i));
 		}
 	    }
-#ifdef DEGUG_RMAREA
+
 	    /* get neighbour boundaries */
 	    Vect_get_area_boundaries(Map, dissolve_neighbour, NList);
-#endif
+
 	    /* delete area from topo */
 	    dig_del_area(&(Map->plus), area);
 	    /* delete neighbour area from topo */
@@ -436,17 +427,19 @@
 		Node = Map->plus.Node[topo->N1];
 		dig_del_line(&(Map->plus), line, Node->x, Node->y, Node->z);
 	    }
-	    /* rebuild neighbour area from leftover boundaries */
+	    /* build new area from leftover boundaries of deleted area */
 	    for (i = 0; i < BList->n_values; i++) {
 		struct P_topo_b *topo;
+		int new_isle;
 
 		line = BList->value[i];
 		topo = Map->plus.Line[abs(line)]->topo;
+
 		if (topo->left == 0 || topo->right == 0) {
-		    int new_isle;
-
 		    new_isle = Vect_build_line_area(Map, abs(line), (line > 0 ? GV_RIGHT : GV_LEFT));
 		    if (new_isle > 0) {
+			if (outer_area > 0)
+			    G_fatal_error("dissolve_neighbour > 0, new area has already been created");
 			outer_area = new_isle;
 			/* reattach centroid */
 			Map->plus.Area[outer_area]->centroid = centroid;
@@ -456,16 +449,20 @@
 			    ctopo->area = outer_area;
 			}
 		    }
+		    else if (new_isle < 0) {
+			/* leftover boundary creates a new isle */
+			Vect_list_append(IList, -new_isle);
+		    }
 		    else {
-			/* should not happen */
-			G_warning(_("Failed to build new area"));
+			/* neither area nor isle, should not happen */
+			G_fatal_error(_("dissolve_neighbour > 0, failed to build new area"));
 		    }
 		}
 		/* check */
 		if (topo->left == 0 || topo->right == 0)
-		    G_warning(_("Dissolve with neighbour area: corrupt topology"));
+		    G_fatal_error(_("Dissolve with neighbour area: corrupt topology"));
 	    }
-#ifdef DEGUG_RMAREA
+	    /* build new area from neighbour's boundaries */
 	    for (i = 0; i < NList->n_values; i++) {
 		struct P_topo_b *topo;
 
@@ -474,13 +471,14 @@
 		    continue;
 
 		topo = Map->plus.Line[abs(line)]->topo;
+
 		if (topo->left == 0 || topo->right == 0) {
 		    int new_isle;
 
-		    G_warning(_("Neighbor boundaries should be complete"));
-
 		    new_isle = Vect_build_line_area(Map, abs(line), (line > 0 ? GV_RIGHT : GV_LEFT));
 		    if (new_isle > 0) {
+			if (outer_area > 0)
+			    G_fatal_error("dissolve_neighbour > 0, new area has already been created");
 			outer_area = new_isle;
 			/* reattach centroid */
 			Map->plus.Area[outer_area]->centroid = centroid;
@@ -490,15 +488,18 @@
 			    ctopo->area = outer_area;
 			}
 		    }
+		    else if (new_isle < 0) {
+			/* Neigbour's boundary creates a new isle */
+			Vect_list_append(IList, -new_isle);
+		    }
 		    else {
-			/* should not happen */
-			G_warning(_("Failed to build new area"));
+			/* neither area nor isle, should not happen */
+			G_fatal_error(_("Failed to build new area"));
 		    }
 		}
 		if (topo->left == 0 || topo->right == 0)
-		    G_warning(_("Dissolve with neighbour area: corrupt topology"));
+		    G_fatal_error(_("Dissolve with neighbour area: corrupt topology"));
 	    }
-#endif
 	}
 	/* dissolve with outer isle */
 	else if (dissolve_neighbour < 0) {
@@ -510,7 +511,7 @@
 #ifdef DEGUG_RMAREA
 	    /* get isle boundaries */
 	    Vect_get_isle_boundaries(Map, -dissolve_neighbour, NList);
-#endif
+
 	    /* delete area from topo */
 	    dig_del_area(&(Map->plus), area);
 	    /* delete isle from topo */
@@ -525,7 +526,7 @@
 		Node = Map->plus.Node[topo->N1];
 		dig_del_line(&(Map->plus), line, Node->x, Node->y, Node->z);
 	    }
-	    /* rebuild isles from leftover boundaries */
+	    /* build new isle(s) from leftover boundaries */
 	    for (i = 0; i < BList->n_values; i++) {
 		struct P_topo_b *topo;
 
@@ -540,15 +541,16 @@
 			Vect_list_append(IList, -new_isle);
 		    }
 		    else {
-			/* should not happen */
-			G_warning(_("Failed to build new isle"));
+			/* area or nothing should not happen */
+			G_fatal_error(_("Failed to build new isle"));
 		    }
 		}
 		/* check */
 		if (topo->left == 0 || topo->right == 0)
-		    G_warning(_("Dissolve with outer isle: corrupt topology"));
+		    G_fatal_error(_("Dissolve with outer isle: corrupt topology"));
 	    }
-#ifdef DEGUG_RMAREA
+
+	    /* build new isle(s) from old isle's boundaries */
 	    for (i = 0; i < NList->n_values; i++) {
 		struct P_topo_b *topo;
 
@@ -557,25 +559,23 @@
 		    continue;
 
 		topo = Map->plus.Line[abs(line)]->topo;
+
 		if (topo->left == 0 || topo->right == 0) {
 		    int new_isle;
 
-		    G_warning(_("Neighbor boundaries should be complete"));
-
 		    new_isle = Vect_build_line_area(Map, abs(line), (line > 0 ? GV_RIGHT : GV_LEFT));
 		    if (new_isle < 0) {
 			Vect_list_append(IList, -new_isle);
 		    }
 		    else {
-			/* should not happen */
-			G_warning(_("Failed to build new isle"));
+			/* area or nothing should not happen */
+			G_fatal_error(_("Failed to build new isle"));
 		    }
 		}
 		/* check */
 		if (topo->left == 0 || topo->right == 0)
-		    G_warning(_("Dissolve with outer isle: corrupt topology"));
+		    G_fatal_error(_("Dissolve with outer isle: corrupt topology"));
 	    }
-#endif
 	}
 
 	if (dissolve_neighbour > 0 && outer_area <= 0) {
@@ -585,6 +585,8 @@
 	/* attach all isles to outer or new area */
 	if (outer_area >= 0) {
 	    for (i = 0; i < IList->n_values; i++) {
+		if (!Map->plus.Isle[IList->value[i]])
+		    continue;
 		Map->plus.Isle[IList->value[i]]->area = outer_area;
 		if (outer_area > 0)
 		    dig_area_add_isle(&(Map->plus), outer_area, IList->value[i]);
@@ -604,9 +606,7 @@
     Vect_destroy_list(List);
     Vect_destroy_list(AList);
     Vect_destroy_list(BList);
-#ifdef DEGUG_RMAREA
     Vect_destroy_list(NList);
-#endif
     Vect_destroy_list(IList);
     Vect_destroy_line_struct(Points);
     Vect_destroy_cats_struct(Cats);



More information about the grass-commit mailing list