I've been using PostGIS for a long time now but never had to use the
LINESTRING geometry ...! :)
Here's what I would like to do : I have a table of linestrings (representing streets of a given city, SRID 3395) and I would like to find the nearest linestrings to a given point (GPS position, SRID 4326).
The solution I found is to select all the linestrings within my point using the
expand() method and determine the distance between each linestring and my point using the
Here's the SQL :
SELECT myLineId, myLineName, ST_Distance(ST_Transform(GeomFromText('POINT(LON LAT)',4326),3395),myLineGeom) AS myLineDistance FROM myLines WHERE myLineGeom && expand(ST_Transform(GeomFromText('POINT(LON LAT)',4326),3395), 100) ORDER BY myLineDistance;
The results I get look OK but I have the feeling something is wrong in my implementation.
1) Do you guys think the
expand() can get all the concerned linestrings?
2) Do you guys think the
ST_Distance() is the right method to use? I guess I'm doing it wrong since the distance I would like to get is the smallest distance between the point and my line and not the distance between the point and one of the points of the linestring.