title: postgis distance between two points on a line
body: <p>I have a route (as a LINESTRING) and two vehicles with a position (as a POINT). I need to calculate the distance between the two points <em>over</em> the route.</p>
  
  <p>As an added difficulty I think I also need to measure the distance from the point to the closest point on the line in the case that the vehicle is not on the route at that moment.</p>
  
  <p>I'm using this to find the closest point on the route:</p>
  
  <pre><code>SELECT ST_AsText(ST_ClosestPoint(pt,line)) AS cp_pt_line, 
      ST_AsText(ST_ClosestPoint(line,pt)) As cp_line_pt
  FROM (SELECT 'POINT(100 100)'::geometry As pt, 
      'LINESTRING (20 80, 98 190, 110 180, 50 75 )'::geometry As line
  ) As foo;
  </code></pre>
  
  <p>Is that possible in a query?</p>