I have two points with srid 4326 and linestring with srid 4326. I want to calculate the distance between two points on a line string with GeoDjango.
The SQL query to calculate the distance is as show below:
WITH line AS (SELECT ST_GeomFromText(%s) AS line),point1 AS (SELECT ST_GeomFromText(%s) AS p1),point2 AS (SELECT ST_GeomFromText(%s) AS p2)SELECT ST_Length(ST_Transform(ST_SetSRID(ST_LineSubstring(line,LEAST(ST_LineLocatePoint(line, pp1), ST_LineLocatePoint(line, pp2)),GREATEST(ST_LineLocatePoint(line, pp1), ST_LineLocatePoint(line, pp2))),4326),900913))FROM (SELECT ST_Snap(p1, ST_ClosestPoint(line, p1), 0.0005) AS pp1, ST_Snap(p2, ST_ClosestPoint(line, p2), 0.005) AS pp2,lineFROM line, point1, point2) AS foo
How would I achieve the same with tools in GeoDjango?