title: Projection of a point to a line segment Python Shapely
body: <p>I have a LineString defined by two points, so essentially a straight line segment, and I wanted to project a point on to it. I am aware of <code>.project</code> and <code>.interpolate</code>. However when the point is "outside" the segment, I don't want the closest point on the segment, but I want to extend the segment and draw a line going through the point and is orthogonal to the (extended) line segment. I want the coordinate of the projection.</p>
  
  <p><a href="https://i.stack.imgur.com/s8bZ3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/s8bZ3.png" alt="enter image description here"></a></p>
  
  <p>For example if the point is "within" the segment</p>
  
  <pre><code>from shapely.geometry import Point
  from shapely.geometry import LineString
  point = Point(0.2, 0.5)
  dist = LineString([(0, 1), (1, 1)]).project(point)
  list(LineString([(0, 1), (1, 1)]).interpolate(dist).coords)
  </code></pre>
  
  <p>Anyone knows what to do when the point is outside of the segment?</p>