[postgis-users] Nearest point between a given point and a multilinestring

Paul Ramsey pramsey at refractions.net
Tue Jan 30 08:48:06 PST 2007


There is not such a function right now, add it to the 
http://postgis.refractions.net/support/wiki/index.php?WishList or submit 
an implementation.

As an aside, you will not be getting the true distance between the 
features, just an approximation, since the nearest point in the 2D 
cartesian interpretation of lat/lon is not the actual nearest point. 
And since you're getting an approximation anyways, you could roll your 
own approximation, by taking the "distance" in degrees and multiplying 
it by a meters per degree measurement you synthetically construct in the 
local area. (Take the distance between the centroids of your objects, 
for example.)

Something like:

distance(a,b) * distance_sphere(centroid(a), centroid(b)) / 
distance(centroid(a), centroid(b))

Eric FRANCOIS wrote:

> 
> I'm able to find the nearest multiline string from a given point with this
> query:
> 
> select  distance(s.the_geom, SetSRID(MakePoint(3.23,48.2), 4326)) as dist
> from streets_db as s
>  WHERE s.the_geom &&  expand(SetSRID(MakePoint(3.23,48.2), 4326),0.01)  AND
> distance(s.the_geom, SetSRID(MakePoint(3.23,48.2), 4326)) <= 0.01
>  order by  dist asc  limit 1
> But how can I find the X-Y coordinate of the nearest point on this
> MULTILINESTRING to perform a
> distance_sphere(the_given_point,the_finding_nearest_point_on_the_multilinest
> ring)?
>


-- 

   Paul Ramsey
   Refractions Research
   http://www.refractions.net
   pramsey at refractions.net
   Phone: 250-383-3022
   Cell: 250-885-0632



More information about the postgis-users mailing list