Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have calculate distance from one point to a linestring. I have used the following query

WITH data AS (
SELECT geom::geometry AS road_network from linestring)

SELECT  ST_Distance(ST_Line_Interpolate_Point(road_network, ST_Line_Locate_Point(road_network,ST_GeomFromText('POINT(90.402 23.753)'))), ST_GeomFromText('POINT(90.402 23.753)'))  as Dist 

FROM data

Limit 1

Its returning the following result


I want to get the result in Meter. How can I convert it? I am using WGS84 projection system. I know the ST_Transform function but I need a perfect query where I use this function.


share|improve this question
For length in meters use "ST_Length_Spheroid" function.… – HasT Mar 14 '13 at 10:11
Thanks but I am newbie. If you can answer with codes it will help me too much. – Devils Dream Mar 14 '13 at 10:28
Doing is learning. replace ST_DISTANCE with ST_Length_Spheroid and add 'SPHEROID["WGS 84",6378137,298.257223563]' to second argument – simplexio Mar 14 '13 at 10:45
up vote 3 down vote accepted

Why are you locating and interpolating those points to get the distance?

About your question: Easiest is to convert to geogrphy type on the fly:

SELECT  ST_Distance(geom::geography,ST_GeographyFromText('POINT(90.402 23.753)')) as Dist 
FROM linestring
Limit 1;
share|improve this answer
I am trying to query closest roads from a point. This is why I used locate and interpolate. Could you please make my code to convert into Meter? It will be a great help. Thanks for reply – Devils Dream Mar 14 '13 at 10:33
@DevilsDream Have you tried the above. It will give you the distance to the closest road in the table linestring (which from your query seems to be the name of your linestring table). You can yourself cast geometry to geograpy like I did (::geography) if you absolutely want to make it complicated. distance calculations on geography type returns in meter. – Nicklas Avén Mar 14 '13 at 11:13
Thats like a boss. Thanks a lot Nicklas Aven. Could you please check this issue… – Devils Dream Mar 14 '13 at 11:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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