|Don't ask to ask, just ask|
Re: Re: Zipcode Proximity scriptby paulbort (Hermit)
|on Mar 31, 2003 at 19:35 UTC||Need Help??|
To add to this: If you don't really care about great circle distance, and you can get away with flat-earth distances, you could start by eliminating all points that are outside the smallest box that fits around your circle. This will eliminate most of the data in two passes. (Outside Lat bounds, and outside Long bounds.) If you store the master data in a SQL database with a couple of indexes, you could just do a query to get the starting set, then trim it with the circle algorighm you already have.
The advantage this has over blokhead's method is that it will work correctly regardless of circle size, and eliminate more points, in exchange for four extra calculations (N, S, E, W bounds). (Ten degrees is a lot of land.)
You might also want to consider storing the points in a database so that a SQL Query on a couple of indexes can do most of the data elimination for you in one pass.
Also, if you multiply the Lat/Longs by 10,000, you can store and manipulate them as longs instead of singles. (This alone might be enough to solve your performance problem.)
Just a quick stab at some SQL for this: (It assumes you've already calculated the bounding box.)
(With luck an optimizer will index seek the first four conditions before crunching the last one.)
This is a neat problem, I wish I had time to bang out some sample code.
Spring: Forces, Coiled Again!