|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Find Coords within X RadiusHi All,
I need to run through a recordset with Lat Lon coordinates and find out if they are within X radius from a certain coord. The coords are build up like this: 321600 (degrees, minutes and seconds). The centergrid could be for example: 321600, 063312 and the radius 15 km. Is there a formula to do this? Regards Marco <Zai***@gmail.com> wrote
> I need to run through a recordset with Lat Lon coordinates and find The formula to use is Pythagoras' theorem.> out if they are within X radius from a certain coord. > > The coords are build up like this: 321600 (degrees, minutes and > seconds). > The centergrid could be for example: 321600, 063312 and the radius 15 > km. > > Is there a formula to do this? Convert all measurements to a single scale (such as Seconds) and find the difference in Lon and Lat (or X and Y) then use Pythagoras' theorem to see if it falls within the desired radius. Of course that says nothing about the complexity added when also considering the curvature of the earth. In short, such a solution would be next to useless at or near the poles.... If the earth's curvature is not taken into account, the solution is simple as the short demo below shows. For details on the more accurate formula pertaining to a sphere, check out this link: http://www.reference.com/browse/wiki/Great-circle_distance LFS Option Explicit Dim CX As Single Dim CY As Single Dim Radius As Single Private Sub Form_Load() AutoRedraw = True ScaleMode = vbPixels CX = 100 CY = 100 Radius = 50 Circle (CX, CX), Radius End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim DX As Single Dim DY As Single DX = Abs(X - CX) DY = Abs(Y - CY) If Sqr(DX * DX + DY * DY) < Radius Then Caption = "Inside" Else Caption = "Outside" End If End Sub
Show quote
Hide quote
On 24 feb, 17:48, "Larry Serflaten" <serfla***@usinternet.com> wrote: I do need to use the earth's curvature. What kind of formula do I need> <Zai***@gmail.com> wrote > > > I need to run through a recordset with Lat Lon coordinates and find > > out if they are within X radius from a certain coord. > > > The coords are build up like this: 321600 (degrees, minutes and > > seconds). > > The centergrid could be for example: 321600, 063312 and the radius 15 > > km. > > > Is there a formula to do this? > > The formula to use is Pythagoras' theorem. > > Convert all measurements to a single scale (such as Seconds) and find the > difference in Lon and Lat (or X and Y) then use Pythagoras' theorem to see > if it falls within the desired radius. Of course that says nothing about the > complexity added when also considering the curvature of the earth. In short, > such a solution would be next to useless at or near the poles.... > > If the earth's curvature is not taken into account, the solution is simple as the > short demo below shows. For details on the more accurate formula pertaining > to a sphere, check out this link:http://www.reference.com/browse/wiki/Great-circle_distance > > LFS > > Option Explicit > Dim CX As Single > Dim CY As Single > Dim Radius As Single > > Private Sub Form_Load() > AutoRedraw = True > ScaleMode = vbPixels > CX = 100 > CY = 100 > Radius = 50 > Circle (CX, CX), Radius > End Sub > > Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) > Dim DX As Single > Dim DY As Single > > DX = Abs(X - CX) > DY = Abs(Y - CY) > If Sqr(DX * DX + DY * DY) < Radius Then > Caption = "Inside" > Else > Caption = "Outside" > End If > End Sub for that. Marco <Zai***@gmail.com> wrote
> > > I need to run through a recordset with Lat Lon coordinates and find Check out what others have used. Search the archives....> > > out if they are within X radius from a certain coord. <...> > > > Is there a formula to do this? > > The formula to use is Pythagoras' theorem. > > > > If the earth's curvature is not taken into account, the solution is simple as the > > short demo below shows. For details on the more accurate formula pertaining > > to a sphere, check out this link: http://www.reference.com/browse/wiki/Great-circle_distance > I do need to use the earth's curvature. What kind of formula do I need > for that. Here is one place to start: http://groups.google.com/groups?as_q=+%22Great+Circle%22+Distance&num=50&scoring=r&hl=en&as_ugroup=*.vb.*&safe=off LFS Zai***@gmail.com wrote:
> I need to run through a recordset with Lat Lon coordinates and find You're looking for a "Great Circle" algorithm. Here's one that uses decimal > out if they are within X radius from a certain coord. > > The coords are build up like this: 321600 (degrees, minutes and > seconds). > The centergrid could be for example: 321600, 063312 and the radius 15 > km. > > Is there a formula to do this? degrees: Public Function Distance() As Double Dim L1 As Double ' Start Point Latitude in radians Dim L2 As Double ' End Point Latitude in radians Dim N1 As Double ' Start Point Longitude in radians Dim N2 As Double ' End Point Longitude in radians Dim C As Double ' Cosine of the angle subtended by the ' segment of the great circle path ' between the two points Dim A As Double ' Angle derived from C Dim R As Double ' Radius of the Earth ' Set radius to user's choice Select Case m_Units Case Kilometers R = 6378 Case NauticalMiles R = 3444 Case StatuteMiles R = 3963 End Select ' Convert start/end points to radians L1 = m_Pt(Start).Latitude.Decimal * (Pi / 180) N1 = m_Pt(Start).Longitude.Decimal * (Pi / 180) L2 = m_Pt(Finish).Latitude.Decimal * (Pi / 180) N2 = m_Pt(Finish).Longitude.Decimal * (Pi / 180) ' Calculate C and A C = (Sin(L1) * Sin(L2)) + (Cos(L1) * Cos(L2) * Cos(N2 - N1)) A = Atn(Sqr(1 - (C * C)) / C) + Pi * (C - Abs(C)) / (2 * C) ' Return A multiplied by the radius of the Earth Distance = A * R End Function Just substitute your own radius, and convert your DMS strings to decimal degrees.
There seems to be a bug in Vista's file sharing that causes the ADO Database open command to hang if
Localized Error Messages Need to pull HARD DRIVE serial number in DOS!!!!! End If without block If Shell on Vista MS Winsock Control ports don't free up Compairson to a fixed length string Shell syntax VB6 - Saving query results as XML RegAsm.exe on Vista |
|||||||||||||||||||||||