[GRASS-SVN] r55729 - grass/trunk/vector/v.to.db
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Apr 13 03:04:53 PDT 2013
Author: mmetz
Date: 2013-04-13 03:04:53 -0700 (Sat, 13 Apr 2013)
New Revision: 55729
Modified:
grass/trunk/vector/v.to.db/lines.c
Log:
v.to.db: fix #1928, clean up a bit
Modified: grass/trunk/vector/v.to.db/lines.c
===================================================================
--- grass/trunk/vector/v.to.db/lines.c 2013-04-13 09:58:32 UTC (rev 55728)
+++ grass/trunk/vector/v.to.db/lines.c 2013-04-13 10:04:53 UTC (rev 55729)
@@ -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,24 +163,15 @@
}
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)) {
@@ -198,10 +179,11 @@
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;
+ if (dx == 0.0 && dy == 0.0)
+ azimuth = -1;
else {
- azimuth = atan2(dx,dy);
- if (azimuth < 0) azimuth = azimuth + 2*M_PI;
+ azimuth = atan2(dx,dy);
+ if (azimuth < 0) azimuth = azimuth + 2 * M_PI;
}
Values[idx].d1 = azimuth;
}
@@ -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,37 +227,36 @@
}
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);
- }
- 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;
+ }
}
G_percent(line_num, nlines, 2);
}
More information about the grass-commit
mailing list