[GRASS-SVN] r39975 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 11 06:20:28 EST 2009


Author: mmetz
Date: 2009-12-11 06:20:27 -0500 (Fri, 11 Dec 2009)
New Revision: 39975

Modified:
   grass/trunk/lib/vector/Vlib/map.c
Log:
Vect_copy_map_lines_field: also copy boundaries

Modified: grass/trunk/lib/vector/Vlib/map.c
===================================================================
--- grass/trunk/lib/vector/Vlib/map.c	2009-12-11 09:26:55 UTC (rev 39974)
+++ grass/trunk/lib/vector/Vlib/map.c	2009-12-11 11:20:27 UTC (rev 39975)
@@ -58,12 +58,14 @@
  */
 int Vect_copy_map_lines_field(struct Map_info *In, int field, struct Map_info *Out)
 {
-    int i, type, nlines, ret;
-    struct line_pnts *Points;
-    struct line_cats *Cats;
+    int i, type, nlines, ret, left, rite, centroid;
+    struct line_pnts *Points, *CPoints;
+    struct line_cats *Cats, *CCats;
 
     Points = Vect_new_line_struct();
+    CPoints = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
+    CCats = Vect_new_cats_struct();
 
     if (Vect_level(In) < 1)
 	G_fatal_error("Vect_copy_map_lines(): %s",
@@ -88,8 +90,34 @@
 	    if (type == 0)
 		continue;	/* dead line */
 	    
-	    if (field != -1 && Vect_cat_get(Cats, field, NULL) == 0)
-		continue;       /* different layer */
+	    /* don't skips boundaries if field != -1 */
+	    if (field != -1) {
+		if (type & GV_BOUNDARY) {
+		    if (Vect_cat_get(Cats, field, NULL) == 0) {
+			int skip_bndry = 1;
+			
+			Vect_get_line_areas(In, i, &left, &rite);
+			if (left > 0) {
+			    if ((centroid = Vect_get_area_centroid(In, left)) > 0) {
+				Vect_read_line(In, CPoints, CCats, centroid);
+				if (Vect_cat_get(CCats, field, NULL) != 0)
+				    skip_bndry = 0;
+			    }
+			}
+			if (rite > 0 && skip_bndry) {
+			    if ((centroid = Vect_get_area_centroid(In, rite)) > 0) {
+				Vect_read_line(In, CPoints, CCats, centroid);
+				if (Vect_cat_get(CCats, field, NULL) != 0)
+				    skip_bndry = 0;
+			    }
+			}
+			if (skip_bndry)
+			    continue;
+		    }
+		}
+		else if (Vect_cat_get(Cats, field, NULL) == 0)
+		    continue;       /* different layer */
+	    }
 	    
 	    Vect_write_line(Out, type, Points, Cats);
 	}
@@ -110,7 +138,8 @@
 	    else if (type == 0) {	/* dead line */
 		continue;
 	    }
-	    
+
+	    /* NOTE: this skips boundaries if field != -1 */
 	    if (field != -1 && Vect_cat_get(Cats, field, NULL) == 0)
 		continue;       /* different layer */
 	    
@@ -118,7 +147,9 @@
 	}
     }
     Vect_destroy_line_struct(Points);
+    Vect_destroy_line_struct(CPoints);
     Vect_destroy_cats_struct(Cats);
+    Vect_destroy_cats_struct(CCats);
 
     return ret;
 }



More information about the grass-commit mailing list