[postgis-users] Closest point problem(s)
Thurber, Fred
Fred.Thurber at gdit.com
Thu Jul 30 08:04:54 PDT 2009
I think I need to clarify my previous post. It is really two-part. Here is the first part:
Closest point problem:
-------------------------------------------------------------------------------------------------------------------------
Given a point, find the closest point in our data to it. I was thinking of a query such as this from an old posting (http://postgis.refractions.net/pipermail/postgis-users/2005-June/008262.html):
SELECT the_point
FROM foo
ORDER BY distance(the_point, GeomFromText('POINT(-80 45)', -1))
LIMIT 1;
But this must doia full table scan The post had a way to first get a bounding box and then do the distance query to cut down the search size (http://postgis.refractions.net/pipermail/postgis-users/2005-June/008262.html):
SELECT the_point
FROM foo
WHERE the_point && 'BOX3D(-180 -55, 20 145)'::box3d
ORDER BY distance(the_point, GeomFromText('POINT(-80 45)', -1))
LIMIT 1;
Is there a better way to do this?
A lot of closest point problems:
---------------------------------------------------------------------------------------------------------------------------------
My second question is this: I will be running this query 100-200 times, once for each item in my query. We are modeling a ship steaming in a straight line, every 5 miles we will want to find the closest point in our data to the ship. Is there a way to do this query in one step instead of solving 100-200 closest point problems?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20090730/c0424589/attachment.html>
More information about the postgis-users
mailing list