[postgis-users] project a point onto a line and get x, y, offset of the point of projection
Stephen Woodbridge
woodbri at swoodbridge.com
Fri Jul 1 19:58:36 PDT 2005
Hi all,
Someone on the list asked if they could get the point location of where
on a line object the shortest distance to that line was from a point.
The distance(line, point) will tell you the shortest distance, but it
does not project the point onto the line at the point where the shortest
distance is located.
Then I needed the same thing for a project at Where2GetIt.com and it
seemed like this functionality should be a part of PostGIS. So attached
is the code I wrote for our needs. There are some examples of its use.
It has an assumption that you are working in decimal degrees, but it
could be modified easily to work in any space. I will leave that up to
others.
The algorithm is very straight forward. Given a linestring and a point,
project the point onto each segment of the linestring and save the
projection of the closest point. Then compute the distance from the
start of the linestring to the projection point and return an array of
pointx, pointy, distance.
Paul, please feel free to add this or something like it to PostGIS.
Enjoy, I would be open to any feedback or improvements any might suggest.
-Steve
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: x_y_offset_from_line_pnt.sql
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20050701/cc067d66/attachment.ksh>
More information about the postgis-users
mailing list