I have table with lines(linestring).For a point wich i give it , I want to find out nearest line in point. I almost developed a query, but it is return the same line every point i give.

the query

   SELECT "NAME_LABEL", ST_Distance(ST_Transform(ST_GeomFromText('POINT(40.587840 22.951521)',4326),2100),geom) AS distance FROM geom ORDER BY distance ASC LIMIT 1;
  • What is your table called that contains the column geom. Do you want to find the nearest point on each line to the given point? – John Powell Dec 28 '14 at 9:42

Your query looks fine to me - are you certain of your point coordinates? The geometry produced by "ST_GeomFromText('POINT(40.587840 22.951521)',4326)" is in Saudi Arabia. Is this what you expect?

  • TThank you the coordinates is 22.9151521 40.587840 is the correct i put it upside down – vagelis Dec 28 '14 at 10:56
  • For not open a new threed i have a problem with this query to express in php '$sqlSta ="SELECT *,ST_Distance(ST_Transform(ST_GeomFromText('POINT("$lgnSta"' '"$latSta")',4326),2100),geom) AS distance FROM roads ORDER BY distance ASC LIMIT 1;";' But is not work – vagelis Dec 28 '14 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.