[postgis-users] Nearest line from a point

Charles Galpin cgalpin at lhsw.com
Sat Aug 20 05:36:58 PDT 2011


I assume you mean it takes a long time? The key is to create a buffer around the point that is as big as you feel necessary to make a match, and then in your where clause only match lines that intersect this. That way the index is used to limit the number of candidates to get the distance for.  Something like

where line && st_expand(myPoint, bufferSizeInYourProjectionUnits)

hth
charles

On Aug 20, 2011, at 4:56 AM, Aurélien FILEZ wrote:

> Hi,
> 
> I have two tables, one which define lines (ST_LineString) and a point (St_Points).
> 
> I'm searching to get the nearest line from this point.
> 
> My first solution was to use this type of query :
> SELECT
>    id,
>    St_Distance(line, myPoint) d
> FROM
>    my_lines_tables
> ORDER BY d ASC LIMIT 1
> 
> But it's very long. Is there is another way to make this ?
> 
> Thank you all,
> Kin
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list