Pārlūkot izejas kodu

v.overlay speed-up

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@53701 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 12 gadi atpakaļ
vecāks
revīzija
ada22d4113
3 mainītis faili ar 45 papildinājumiem un 10 dzēšanām
  1. 7 1
      vector/v.overlay/area_area.c
  2. 5 1
      vector/v.overlay/line_area.c
  3. 33 8
      vector/v.overlay/main.c

+ 7 - 1
vector/v.overlay/area_area.c

@@ -31,8 +31,11 @@ int area_area(struct Map_info *In, int *field, struct Map_info *Out,
 
     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 @@ int area_area(struct Map_info *In, int *field, struct Map_info *Out,
 	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);

+ 5 - 1
vector/v.overlay/line_area.c

@@ -22,7 +22,7 @@ int point_area(struct Map_info *Map, int field, double x, double y,
 	       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 @@ int line_area(struct Map_info *In, int *field, struct Map_info *Out,
 
     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);
 

+ 33 - 8
vector/v.overlay/main.c

@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
 	*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 @@ int main(int argc, char *argv[])
 				 G_FATAL_EXIT);
 
     Points = Vect_new_line_struct();
+    Points2 = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
 
     /* Open output */
@@ -226,9 +227,37 @@ int main(int argc, char *argv[])
 		    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 @@ int main(int argc, char *argv[])
 			    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);