[GRASS-SVN] r53701 - grass/trunk/vector/v.overlay

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 6 05:34:35 PST 2012


Author: mmetz
Date: 2012-11-06 05:34:34 -0800 (Tue, 06 Nov 2012)
New Revision: 53701

Modified:
   grass/trunk/vector/v.overlay/area_area.c
   grass/trunk/vector/v.overlay/line_area.c
   grass/trunk/vector/v.overlay/main.c
Log:
v.overlay speed-up

Modified: grass/trunk/vector/v.overlay/area_area.c
===================================================================
--- grass/trunk/vector/v.overlay/area_area.c	2012-11-06 13:32:54 UTC (rev 53700)
+++ grass/trunk/vector/v.overlay/area_area.c	2012-11-06 13:34:34 UTC (rev 53701)
@@ -31,8 +31,11 @@
 
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
+    
+    /* optional snap ? */
 
-    /* Vect_clean_small_angles_at_nodes() can change the geometry so that new intersections
+    /* same procedure like for v.in.ogr
+     * Vect_clean_small_angles_at_nodes() can change the geometry so that new intersections
      * are created. We must call Vect_break_lines(), Vect_remove_duplicates()
      * and Vect_clean_small_angles_at_nodes() until no more small dangles are found */
     do {
@@ -73,6 +76,9 @@
 	Vect_remove_bridges(Out, NULL, NULL, NULL);
     }
 
+    G_message(_("Merging lines..."));
+    Vect_merge_lines(Out, GV_BOUNDARY, NULL, NULL);
+
     /* Attach islands */
     G_message(_("Attaching islands..."));
     Vect_build_partial(Out, GV_BUILD_ATTACH_ISLES);

Modified: grass/trunk/vector/v.overlay/line_area.c
===================================================================
--- grass/trunk/vector/v.overlay/line_area.c	2012-11-06 13:32:54 UTC (rev 53700)
+++ grass/trunk/vector/v.overlay/line_area.c	2012-11-06 13:34:34 UTC (rev 53701)
@@ -22,7 +22,7 @@
 	       struct line_cats *Cats)
 {
     int i, area, centr;
-    struct line_cats *CCats = NULL;
+    static struct line_cats *CCats = NULL;
 
     Vect_reset_cats(Cats);
     area = Vect_find_area(Map, x, y);
@@ -68,9 +68,13 @@
 
     G_message(_("Breaking lines..."));
     Vect_break_lines_list(Out, NULL, BList, GV_LINE | GV_BOUNDARY, NULL);
+    G_message(_("Merging lines..."));
+    Vect_merge_lines(Out, GV_LINE, NULL, NULL);
 
+#if 0
     /* Basic topology needed only */
     Vect_build_partial(Out, GV_BUILD_BASE);
+#endif
 
     nlines = Vect_get_num_lines(Out);
 

Modified: grass/trunk/vector/v.overlay/main.c
===================================================================
--- grass/trunk/vector/v.overlay/main.c	2012-11-06 13:32:54 UTC (rev 53700)
+++ grass/trunk/vector/v.overlay/main.c	2012-11-06 13:34:34 UTC (rev 53701)
@@ -38,7 +38,7 @@
 	*ofield_opt, *operator_opt;
     struct Flag *table_flag;
     struct Map_info In[2], Out;
-    struct line_pnts *Points;
+    struct line_pnts *Points, *Points2;
     struct line_cats *Cats;
     struct ilist *BList;
     char *desc;
@@ -160,6 +160,7 @@
 				 G_FATAL_EXIT);
 
     Points = Vect_new_line_struct();
+    Points2 = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
 
     /* Open output */
@@ -226,9 +227,37 @@
 		    continue;
 	    }
 
-	    newline = Vect_write_line(&Out, ltype, Points, Cats);
-	    if (input == 1)
-		G_ilist_add(BList, newline);
+	    /* TODO: figure out a reasonable threshold */
+	    if (Points->n_points > 100) {
+		int vertices = 100;
+		int start = 0;	/* number of coordinates written */
+		
+		/* split */
+		while (start < Points->n_points - 1) {
+		    int v = 0;
+
+		    Vect_reset_line(Points2);
+		    for (i = 0; i < vertices; i++) {
+			v = start + i;
+			if (v == Points->n_points)
+			    break;
+
+			Vect_append_point(Points2, Points->x[v], Points->y[v],
+					  Points->z[v]);
+		    }
+
+		    newline = Vect_write_line(&Out, ltype, Points2, Cats);
+		    if (input == 1)
+			G_ilist_add(BList, newline);
+
+		    start = v;
+		}
+	    }
+	    else {
+		newline = Vect_write_line(&Out, ltype, Points, Cats);
+		if (input == 1)
+		    G_ilist_add(BList, newline);
+	    }
 	    nlines_out++;
 	}
 	if (nlines_out == 0) {
@@ -484,10 +513,6 @@
 			    Fi->database, Fi->driver);
     }
 
-    G_verbose_message(_("Building partial topology..."));
-    /* do not print output, because befor cleaning it is nonsense */
-    Vect_build_partial(&Out, GV_BUILD_BASE);
-
     /* AREA x AREA */
     if (type[0] == GV_AREA) {
 	area_area(In, field, &Out, Fi, driver, operator, ofield, attr, BList);



More information about the grass-commit mailing list