Wednesday 6 June 2018

How to show PostGIS distance in Meter



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

ORDER BY Dist

Limit 1

Its returning the following result


0.000501079237817185

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.


Thanks



Answer



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
ORDER BY Dist
Limit 1;

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...