re: Dealer/zip locator constipated
| From: | David P. Schwartz | Date: | Thu, 30 Nov 2000 04:32:44 +0000 |
| Subject: | re: Dealer/zip locator constipated | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-27967@lists.php.net to get a copy of this message | ||
This is a computationally intense problem if you approach it using a
least-squares-mean approach to find the distance between two arbitrary 2-D
points on a sphere as large as the Earth.
Several years ago, I wrote some code for a client that computed
shortest-distance routes between FBOs for general aviation (small aircraft)
travelling cross-country. Using this approach took tens-of-seconds per pair of
locations, and that was in C code running on 486-class machines. The problem is
that you've got an x-y grid and you have no localization cues. If you used a
sparse matrix and "spaced" things out in ten-second (of arc) increments, you
might be able to narrow down your search, but your database would become
terribly bloated. You MUST put some pre-filtering criteria in your database to
localize your searches in order to reduce the search time in a 2-D space.
Fundamentally, it's the wrong approach to this kind of a problem.
As that project was completing, another client came to me who wanted a
moving-map display that updates itself in real-time. He proposed the
least-squares-mean approach on a database with 10**3 more data points and a
requirement that the granularity vary from city blocks to hundreds of miles. A
couple of test cases showed this approach wasn't going to work at all.
About that time, I found this article article in DDJ's 12/92 issue:
SPATIAL DATA AND THE VORONOI TESSELLATION
by Hrvoje Lukatela and John Russell
http://www.ddj.com/articles/1992/9212/9212toc.htm
I just did a search on Yahoo! for "voronoi" and came up with lots of hits. The
the guys who wrote the article and have the libraries available are still around
at: http://www.geodyssey.com/
They put out C libraries. I worked with their code on the latter project, and
it's a TERRIFIC model to use!
I haven't looked around, but I suspect you could get you hands on some code that
would be helpful. The DDJ article had simplified presentations of the Voronoi
algorithms in C that I played with and you wouldn't believe how much FASTER this
approach is than the approach you're trying! Back then, Lukatela and Russell
were just about the only folks who were doing anything with Voronoi nets, but
judging from the results of the Yahoo! search, it's really blossomed.
The code in the original DDJ article would probably be sufficient for your needs
-- you'd get some distance variations of a few miles for coast-to-coast
distances, which might be tolerable. Depending on how much detail you want to
provide to your voronoi nets, you could reduce the errors by several orders of
magnitude.
Good luck!
-David Schwartz