[GRASS-SVN] r55747 - grass/branches/releasebranch_6_4/vector/v.to.db

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 13 06:50:47 PDT 2013


Author: mmetz
Date: 2013-04-13 06:50:47 -0700 (Sat, 13 Apr 2013)
New Revision: 55747

Modified:
   grass/branches/releasebranch_6_4/vector/v.to.db/lines.c
Log:
v.to.db: fix #1928 (backport from trunk)

Modified: grass/branches/releasebranch_6_4/vector/v.to.db/lines.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.to.db/lines.c	2013-04-13 13:50:38 UTC (rev 55746)
+++ grass/branches/releasebranch_6_4/vector/v.to.db/lines.c	2013-04-13 13:50:47 UTC (rev 55747)
@@ -122,12 +122,7 @@
 		}
 		else if (options.option == O_LENGTH && (type & GV_LINES)) {
 		    /* Calculate line length */
-		    if (!Vect_is_3d(Map)) {
-			len = length(Points->n_points, Points->x, Points->y);
-		    }
-		    else {
-			len = Vect_line_length(Points);
-		    }
+		    len = Vect_line_geodesic_length(Points);
 		    Values[idx].d1 += len;
 		}
 		else if (options.option == O_COOR && (type & GV_POINTS)) {
@@ -160,12 +155,7 @@
 		}
 		else if (options.option == O_SLOPE && (type & GV_LINES)) {
 		    /* Calculate line slope */
-		    if (!Vect_is_3d(Map)) {
-			len = length(Points->n_points, Points->x, Points->y);
-		    }
-		    else {
-			len = Vect_line_length(Points);
-		    }
+		    len = length(Points->n_points, Points->x, Points->y);
 		    slope =
 			(Points->z[Points->n_points - 1] -
 			 Points->z[0]) / len;
@@ -173,37 +163,29 @@
 		}
 		else if (options.option == O_SINUOUS && (type & GV_LINES)) {
 		    /* Calculate line length / distance between end points */
+		    Vect_reset_line(EndPoints);
 		    Vect_append_point(EndPoints, Points->x[0], Points->y[0],
 				      Points->z[0]);
 		    Vect_append_point(EndPoints,
 				      Points->x[Points->n_points - 1],
 				      Points->y[Points->n_points - 1],
 				      Points->z[Points->n_points - 1]);
-		    if (!Vect_is_3d(Map)) {
-			len = length(Points->n_points, Points->x, Points->y);
-			dist =
-			    length(EndPoints->n_points, EndPoints->x,
-				   EndPoints->y);
-		    }
-		    else {
-			len = Vect_line_length(Points);
-			dist = Vect_line_length(EndPoints);
-		    }
-		    Vect_destroy_line_struct(EndPoints);
-		    EndPoints = Vect_new_line_struct();
+		    len = Vect_line_geodesic_length(Points);
+		    dist = Vect_line_geodesic_length(EndPoints);
 		    Values[idx].d1 = len / dist;
 		}
 		else if (options.option == O_AZIMUTH && (type & GV_LINES)) {
-			/* Calculate azimuth between line start and end points in degrees */
-			dx = (Points->x[Points->n_points - 1] - Points->x[0]);
-			dy = (Points->y[Points->n_points - 1] - Points->y[0]);
-			/* If line is closed... */
-			if (dx == 0.0 && dy == 0.0) azimuth = -1;
-			else {
-				azimuth = atan2(dx,dy);
-				if (azimuth < 0) azimuth = azimuth + 2*M_PI;
-			}
-			Values[idx].d1 = azimuth;
+		    /* Calculate azimuth between line start and end points in degrees */
+		    dx = (Points->x[Points->n_points - 1] - Points->x[0]);
+		    dy = (Points->y[Points->n_points - 1] - Points->y[0]);
+		    /* If line is closed... */
+		    if (dx == 0.0 && dy == 0.0)
+			azimuth = -1;
+		    else {
+			azimuth = atan2(dx,dy);
+			if (azimuth < 0) azimuth = azimuth + 2 * M_PI;
+		    }
+		    Values[idx].d1 = azimuth;
 		}
 
 		found = 1;
@@ -216,12 +198,7 @@
 		Values[idx].count1++;
 	    }
 	    else if (options.option == O_LENGTH && (type & GV_LINES)) {
-		if (!Vect_is_3d(Map)) {
-		    len = length(Points->n_points, Points->x, Points->y);
-		}
-		else {
-		    len = Vect_line_length(Points);
-		}
+		len = Vect_line_geodesic_length(Points);
 		Values[idx].d1 += len;
 	    }
 	    else if (options.option == O_COOR && (type & GV_POINTS)) {
@@ -250,36 +227,35 @@
 	    }
 	    else if (options.option == O_SLOPE && (type & GV_LINES)) {
 		/* Calculate line slope */
-		if (!Vect_is_3d(Map)) {
-		    len = length(Points->n_points, Points->x, Points->y);
-		}
-		else {
-		    len = Vect_line_length(Points);
-		}
+		len = length(Points->n_points, Points->x, Points->y);
 		slope =
 		    (Points->z[Points->n_points - 1] - Points->z[0]) / len;
 		Values[idx].d1 += slope;
 	    }
 	    else if (options.option == O_SINUOUS && (type & GV_LINES)) {
 		/* Calculate line length / distance between end points */
+		Vect_reset_line(EndPoints);
 		Vect_append_point(EndPoints, Points->x[0], Points->y[0],
 				  Points->z[0]);
 		Vect_append_point(EndPoints, Points->x[Points->n_points - 1],
 				  Points->y[Points->n_points - 1],
 				  Points->z[Points->n_points - 1]);
-		if (!Vect_is_3d(Map)) {
-		    len = length(Points->n_points, Points->x, Points->y);
-		    dist =
-			length(EndPoints->n_points, EndPoints->x,
-			       EndPoints->y);
-		}
+		len = Vect_line_geodesic_length(Points);
+		dist = Vect_line_geodesic_length(EndPoints);
+		Values[idx].d1 = len / dist;
+	    }
+	    else if (options.option == O_AZIMUTH && (type & GV_LINES)) {
+		/* Calculate azimuth between line start and end points in degrees */
+		dx = (Points->x[Points->n_points - 1] - Points->x[0]);
+		dy = (Points->y[Points->n_points - 1] - Points->y[0]);
+		/* If line is closed... */
+		if (dx == 0.0 && dy == 0.0)
+		    azimuth = -1;
 		else {
-		    len = Vect_line_length(Points);
-		    dist = Vect_line_length(EndPoints);
+		    azimuth = atan2(dx,dy);
+		    if (azimuth < 0) azimuth = azimuth + 2 * M_PI;
 		}
-		Vect_destroy_line_struct(EndPoints);
-		EndPoints = Vect_new_line_struct();
-		Values[idx].d1 = len / dist;
+		Values[idx].d1 = azimuth;
 	    }
 	}
 	G_percent(line_num, nlines, 2);



More information about the grass-commit mailing list