[GRASS-SVN] r29568 - grass/trunk/vector/v.distance
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jan 5 06:22:14 EST 2008
Author: martinl
Date: 2008-01-05 06:22:13 -0500 (Sat, 05 Jan 2008)
New Revision: 29568
Modified:
grass/trunk/vector/v.distance/description.html
grass/trunk/vector/v.distance/main.c
Log:
Fix bug GForge/378: v.distance: bogus distances for Lat/Lon locations (v.distance in a lat/lon location gives distances in degrees, which is useless in most cases as lat and lon are not equally scaled). For LL locations is used Vect_line_geodesic_length()
Modified: grass/trunk/vector/v.distance/description.html
===================================================================
--- grass/trunk/vector/v.distance/description.html 2008-01-05 10:59:24 UTC (rev 29567)
+++ grass/trunk/vector/v.distance/description.html 2008-01-05 11:22:13 UTC (rev 29568)
@@ -123,6 +123,9 @@
null.
<p>
The upload <B>column</B>(s) must already exist. Create one with <em>v.db.addcol</em>.
+<p>
+In lat-long location <em>v.distance</em> gives distances (<b>dist</b>
+and <b>to_along</b>) in meters not in degrees.
<H2>SEE ALSO</H2>
Modified: grass/trunk/vector/v.distance/main.c
===================================================================
--- grass/trunk/vector/v.distance/main.c 2008-01-05 10:59:24 UTC (rev 29567)
+++ grass/trunk/vector/v.distance/main.c 2008-01-05 11:22:13 UTC (rev 29568)
@@ -68,7 +68,7 @@
int main (int argc, char *argv[])
{
- int i, j;
+ int i, j, k;
int print_as_matrix; /* only for all */
int all; /* calculate from each to each within the threshold */
char *mapset;
@@ -471,6 +471,13 @@
count = 0; /* count of distances in 'all' mode */
/* Find nearest lines */
if ( to_type & (GV_POINTS | GV_LINES) ) {
+ struct line_pnts *LLPoints;
+ if (G_projection() == PROJECTION_LL) {
+ LLPoints = Vect_new_line_struct();
+ }
+ else {
+ LLPoints = NULL;
+ }
for ( fline = 1; fline <= nfrom ; fline++ ) {
int tmp_tcat;
double tmp_tangle, tangle;
@@ -503,7 +510,20 @@
/* TODO: more cats of the same field */
Vect_cat_get(TCats, to_field, &tmp_tcat);
- G_debug (4, " tmp_dist = %f tmp_tcat = %d", tmp_dist, tmp_tcat);
+ if (G_projection() == PROJECTION_LL) {
+ /* calculate distances in meters not degrees (only 2D) */
+ Vect_reset_line(LLPoints);
+ Vect_append_point(LLPoints, FPoints->x[0], FPoints->y[0], FPoints->z[0]);
+ Vect_append_point(LLPoints, tmp_tx, tmp_ty, tmp_tz);
+ tmp_dist = Vect_line_geodesic_length(LLPoints);
+ Vect_reset_line(LLPoints);
+ for (k = 0; k < tseg; k++)
+ Vect_append_point(LLPoints, TPoints->x[k], TPoints->y[k], TPoints->z[k]);
+ Vect_append_point(LLPoints, tmp_tx, tmp_ty, tmp_tz);
+ tmp_talong = Vect_line_geodesic_length(LLPoints);
+ }
+
+ G_debug (4, " tmp_dist = %f tmp_tcat = %d", tmp_dist, tmp_tcat);
if ( all ) {
if ( anear <= count ) {
@@ -562,6 +582,9 @@
near->count++;
}
}
+ if (LLPoints) {
+ Vect_destroy_line_struct(LLPoints);
+ }
}
/* Find nearest areas */
More information about the grass-commit
mailing list