[GRASS-SVN] r37804 - grass/trunk/vector/v.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 10 09:26:22 EDT 2009


Author: mmetz
Date: 2009-06-10 09:26:21 -0400 (Wed, 10 Jun 2009)
New Revision: 37804

Modified:
   grass/trunk/vector/v.in.ogr/geom.c
   grass/trunk/vector/v.in.ogr/main.c
Log:
minor bugfix and cosmetics

Modified: grass/trunk/vector/v.in.ogr/geom.c
===================================================================
--- grass/trunk/vector/v.in.ogr/geom.c	2009-06-09 22:13:53 UTC (rev 37803)
+++ grass/trunk/vector/v.in.ogr/geom.c	2009-06-10 13:26:21 UTC (rev 37804)
@@ -384,22 +384,38 @@
 int split_line(struct Map_info *Map, int otype, struct line_pnts *Points, struct line_cats *Cats)
 {
     int i;
-    double dist = 0., dx, dy;
+    double dist = 0., seg_dist, dx, dy;
     struct line_pnts *OutPoints;
 
+    /* don't write zero length boundaries */
+    Vect_line_prune(Points);
+    if (Points->n_points < 2)
+    	return 0;
+
+    /* can't split boundaries with only 2 vertices */
+    if (Points->n_points == 2) {
+	Vect_write_line(Map, otype, Points, Cats);
+    	return 0;
+    }
+
     OutPoints = Vect_new_line_struct();
-    Vect_reset_line(OutPoints);
-    i = 0;
-    Vect_append_point(OutPoints, Points->x[i], Points->y[i], Points->z[i]);
+    Vect_append_point(OutPoints, Points->x[0], Points->y[0], Points->z[0]);
+    Vect_append_point(OutPoints, Points->x[1], Points->y[1], Points->z[1]);
+    dx = Points->x[1] - Points->x[0];
+    dy = Points->y[1] - Points->y[0];
+    dist = sqrt(dx * dx + dy * dy);
 
-    for (i = 1; i < Points->n_points; i++) {
+    /* trying to keep line length smaller than split_distance
+     * alternative, less code: write line as soon as split_distance is exceeded */
+    for (i = 2; i < Points->n_points; i++) {
 	dx = Points->x[i] - Points->x[i - 1];
 	dy = Points->y[i] - Points->y[i - 1];
-	dist += sqrt(dx * dx + dy * dy);
+	seg_dist = sqrt(dx * dx + dy * dy);
+	dist += seg_dist;
 	if (dist > split_distance) {
 	    Vect_write_line(Map, otype, OutPoints, Cats);
 	    Vect_reset_line(OutPoints);
-	    dist = sqrt(dx * dx + dy * dy);
+	    dist = seg_dist;
 	    Vect_append_point(OutPoints, Points->x[i - 1], Points->y[i - 1], Points->z[i - 1]);
 	}
 	Vect_append_point(OutPoints, Points->x[i], Points->y[i], Points->z[i]);
@@ -407,7 +423,6 @@
     Vect_write_line(Map, otype, OutPoints, Cats);
 
     Vect_destroy_line_struct(OutPoints);
-    /* G_free(OutPoints); */
 
     return 0;
 }

Modified: grass/trunk/vector/v.in.ogr/main.c
===================================================================
--- grass/trunk/vector/v.in.ogr/main.c	2009-06-09 22:13:53 UTC (rev 37803)
+++ grass/trunk/vector/v.in.ogr/main.c	2009-06-10 13:26:21 UTC (rev 37804)
@@ -1112,6 +1112,8 @@
 		      n_overlaps, nlayers + 1);
 	}
 
+	G_message("%s", separator);
+
 	Vect_hist_write(&Map, separator);
 	Vect_hist_write(&Map, "\n");
 	sprintf(buf, _("%d input polygons\n"), n_polygons);
@@ -1133,6 +1135,7 @@
 	G_message(_("Area without category: %G (%d areas)"), nocat_area,
 		  n_nocat);
 	Vect_hist_write(&Map, buf);
+	G_message("%s", separator);
     }
 
     /* needed?



More information about the grass-commit mailing list