[GRASS-SVN] r64094 - grass/branches/releasebranch_7_0/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 12 06:04:44 PST 2015


Author: mmetz
Date: 2015-01-12 06:04:44 -0800 (Mon, 12 Jan 2015)
New Revision: 64094

Modified:
   grass/branches/releasebranch_7_0/lib/vector/Vlib/line.c
Log:
Vlib: backport geodesic distance to line calculations

Modified: grass/branches/releasebranch_7_0/lib/vector/Vlib/line.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/vector/Vlib/line.c	2015-01-12 13:59:47 UTC (rev 64093)
+++ grass/branches/releasebranch_7_0/lib/vector/Vlib/line.c	2015-01-12 14:04:44 UTC (rev 64094)
@@ -636,15 +636,15 @@
    - px, py - point on line,
    - dist   - distance to line,
    - spdist - distance to point on line from segment beginning,
-   - sldist - distance to point on line form line beginning along line
+   - lpdist - distance to point on line from line beginning along line
 
   \param points pointer to line_pnts structure
   \param ux,uy,uz point coordinates
   \param with_z flag if to use z coordinate (3D calculation)
   \param[out] px,py,pz point on line
-  \param[out] dist distance to line,
-  \param[out] spdist distance of point from segment beginning
-  \param[out] lpdist distance of point from line
+  \param[out] dist distance to line
+  \param[out] spdist distance to point on line from segment beginning
+  \param[out] lpdist distance to point on line from line beginning along line
 
   \return nearest segment (first is 1)
  */
@@ -770,16 +770,18 @@
   \return nearest segment (first is 1)
  */
 int Vect_line_geodesic_distance(const struct line_pnts *points,
-		       double ux, double uy, double uz,
-		       int with_z,
-		       double *px, double *py, double *pz,
-		       double *dist, double *spdist, double *lpdist)
+		                double ux, double uy, double uz,
+		                int with_z,
+		                double *px, double *py, double *pz,
+		                double *dist, double *spdist,
+				double *lpdist)
 {
     int i;
     double distance;
     double new_dist;
-    double tpx, tpy, tpz, tdist, tspdist, tlpdist = 0, tlpdistseg;
-    double dx, dy, dz;
+    double tpx, tpy, tpz, ttpx, ttpy, ttpz; 
+    double tdist, tspdist, tlpdist = 0, tlpdistseg;
+    double dz;
     int n_points;
     int segment;
 
@@ -824,29 +826,22 @@
 						   points->x[i + 1],
 						   points->y[i + 1],
 						   points->z[i + 1], with_z,
-						   &tpx, &tpy, &tpz,
+						   &ttpx, &ttpy, &ttpz,
 						   NULL, NULL);
-	    new_dist = G_distance(ux, uy, tpx, tpy);
+
+	    new_dist = G_distance(ux, uy, ttpx, ttpy);
 	    if (with_z)
-		new_dist = hypot(new_dist, uz - tpz);
+		new_dist = hypot(new_dist, uz - ttpz);
 
 	    if (new_dist < distance) {
 		distance = new_dist;
 		segment = i + 1;
+		tpx = ttpx;
+		tpy = ttpy;
+		tpz = ttpz;
 	    }
 	}
 
-	/* we have segment and now we can recalculate other values (speed) */
-	new_dist = dig_distance2_point_to_line(ux, uy, uz,
-					       points->x[segment - 1],
-					       points->y[segment - 1],
-					       points->z[segment - 1],
-					       points->x[segment],
-					       points->y[segment],
-					       points->z[segment], with_z,
-					       &tpx, &tpy, &tpz, &tspdist,
-					       NULL);
-
 	/* calculate distance from beginning of segment */
 	tspdist = G_distance(points->x[segment - 1], points->y[segment - 1],
 			     tpx, tpy);



More information about the grass-commit mailing list