Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MATH - getting rows within a radius
Message
From
26/04/2007 15:32:08
Walter Meester
HoogkarspelNetherlands
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01219992
Message ID:
01220242
Views:
27
>I have a table of warrants with latitude and longitude, and I would like to be able to select all warrants within a given radius. I know I've seen this discussed before. Any of you math professors got a clue?

hhmmmm, this calls for pythagoras...

lets say your on position xPos and Ypos and your the location is at xDest and YDest, and your radius is nRad, I'd go for the following solution
SELECT * FROM Warrants WHERE SQRT((xPos - xDest) ^ 2 + (Ypos - yDest) ^ 2) =< nRad
If its getting to slow you can think of adding additional for the benefit of rushmore like:
AND xdest BETWEEN xPos - nRad AND xPos + Rad AND yDest BETWEEN yPos - nRad AND yPos + nRad
of course you need indexes on xDest and yDest

Walter,
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform