|
Cellular forums Home > Archive > GPS > May 2007 > Locate nearst Point GPS Coordinate
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Locate nearst Point GPS Coordinate
|
|
| nitn28@gmail.com 2007-05-15, 3:33 pm |
| hello every one
i m working with GPS Coordinates [cartesian coordinates]
i want to locate nearest point at present m using this formula to
locate nearrest point
Sub sortdistance()
LastRowA = Cells(Rows.Count, "A").End(xlUp).Row
LastRowE = Cells(Rows.Count, "E").End(xlUp).Row
For i = 1 To LastRowA
X = Cells(i, "A")
Y = Cells(i, "B")
For j = 1 To LastRowE
distance = Sqr((X - Cells(j, "E")) ^ 2 + (Y - Cells(j, "F")) ^
2)
If j = 1 Then
shortX = Cells(j, "E")
shortY = Cells(j, "F")
shortdistance = distance
Else
If distance < shortdistance Then
shortX = Cells(j, "E")
shortY = Cells(j, "F")
shortdistance = distance
End If
End If
Next j
Cells(i, "C") = shortX
Cells(i, "D") = shortY
Next i
End Sub
but i want to knw is there anyother way "more presice n accurate" to
locate nearest point
hope sumbody wud find time to help me out
many thanx in advance
| |
| Simon Slavin 2007-05-18, 10:33 pm |
| On 15/05/2007, nitn28@gmail.com wrote in message
<1179254943.526288.311100@n59g2000hsh.googlegroups.com>:
> but i want to knw is there anyother way "more presice n accurate" to
> locate nearest point
There are other ways to sort the points that may or may not be faster
depending on how many points you have and how sorted they are before your
routine is run. But you're probably not going to speed that up much by
using a different sorting routine.
I have one comment on your code: there's no point in doing the 'Sqr'.
Simon.
--
http://www.hearsay.demon.co.uk
| |
|
| Hello,
Are you sure you post in the right newsgroup ?
I am not a specialist in programming languages, I am not sure I correctly
interpret your code (you have not indicate with language or environnement
you are using ! ) It looks to me as it's a macro for Microsoft Excel ??
But I have some comments :
- you don't need a macro to find out the nearest point for each entry. It
is possible to only use matrix functions, min function and lookfor function
of Excel sheet to achieve this result.
- if your data sets are large, you can spare macro running time by first
sorting point before running the macro which may stop the look-for loops as
soon a calculated distance is greater than the previous one.
- your formula for distance is only valid for cartesian coordinates which
are coordinates on a plan. Generaly, GPS coordinates are latitude and
longitude which are angular coordonates on a sphere (not cartesian). Your
formula based on euclidian distance is not rigorous for lat/lon GPS
coordinates. Distance between lat/lon GPS position greatly depends of
latitude (and in a minor scale depends of the exact shape of the geoide). Is
is not a problem to find out the nearest point if all points are close
enougth to be in the same latitude range. Otherwise, importance of longitude
changes are mis-estimated.
As a more precise formula for lat/lon to estimate distance, I may suggest
the following formulae (deduce from distance of points on a spherical
geodide). Accurate results are only expected for points far from pole and
shortest distance line not crossing pole or day change line. Is is not a
problem to find out the nearest point if all points are close enougth to be
in the same latitude range. Otherwise, importance of longitude changes are
mis-estimated.
sub distance(lat1,lon1,l
at2,lon2)
' dst = DISTANCE(lat1,lon1,l
at2,lon2) computes the great circle
' distance in meters between the two points (lat1,lon1) and (lat2,lon2) on
the globe.
'
' Angle unit conversion from dd.ddddddd to radian
rlat1 = pi*lat1/180; rlon1 = pi*lon1/180
rlat2 = pi*lat2/180; rlon2 = pi*lon2/180
'
' Geoid paramters (WGS 84 edition 1994)
a = 6378137.0000; ' Earth Major semi-axis (m)
b = 6356752.3142; ' Earth Minor semi-axis (m)
e2 = (a*a-b*b)/(a*a); ' square of prime excentricity
e = sqrt(e2); ' prime excentricity
'
' Compute spherical cord
t = sin(rlat1)*sin(rlat2
) + cos(rlat1)*cos(rlat2
)*cos(rlon2-rlon1)
'
' Avoid out-of-range error from acos function
if t > 1 then t = 1 end
if t < -1 then t = -1 end
'
' Compute spherical great circle distance from cord and earth major
semi-axis
distance = acos( t ) * a
sub end
Application: distance estimated by this formula between the Obélisque at
Place de la Concorde (N48.86545 E2.231109) and the Tour Eiffel (N48.85831
E2.29410) in Paris is about 2130 m. Not so bad.
This formula only takes account of latitude to correct distance. More
sophisticate formulae exist taking account of real shape of the geoide and
effect of longitude (i.e. the Elliptical geoid distance computation) .
<nitn28@gmail.com> wrote in
news:1179254943.526288.311100@n59g2000hsh.googlegroups.com...
> hello every one
>
> i m working with GPS Coordinates [cartesian coordinates]
>
> i want to locate nearest point at present m using this formula to
> locate nearrest point
>
> Sub sortdistance()
>
> LastRowA = Cells(Rows.Count, "A").End(xlUp).Row
> LastRowE = Cells(Rows.Count, "E").End(xlUp).Row
>
> For i = 1 To LastRowA
> X = Cells(i, "A")
> Y = Cells(i, "B")
>
> For j = 1 To LastRowE
> distance = Sqr((X - Cells(j, "E")) ^ 2 + (Y - Cells(j, "F")) ^
> 2)
> If j = 1 Then
> shortX = Cells(j, "E")
> shortY = Cells(j, "F")
> shortdistance = distance
> Else
> If distance < shortdistance Then
> shortX = Cells(j, "E")
> shortY = Cells(j, "F")
> shortdistance = distance
> End If
> End If
> Next j
>
> Cells(i, "C") = shortX
> Cells(i, "D") = shortY
> Next i
>
> End Sub
>
>
> but i want to knw is there anyother way "more presice n accurate" to
> locate nearest point
>
> hope sumbody wud find time to help me out
> many thanx in advance
>
|
|
|
|
|