<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=777255215-12042005><FONT face=Arial color=#0000ff size=2>Have a
look at JTS - it has code to do this (in the DistanceOp
class).</FONT></SPAN></DIV>
<DIV><SPAN class=777255215-12042005><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=777255215-12042005><FONT face=Arial color=#0000ff size=2><A
href="http://www.vividsolutions.com/jts/jtshome.htm">http://www.vividsolutions.com/jts/jtshome.htm</A></FONT></SPAN></DIV>
<DIV><SPAN class=777255215-12042005><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV> </DIV>
<DIV align=center><FONT face=Arial size=2><STRONG>Martin Davis, Senior Technical
Architect</STRONG><BR><STRONG><FONT color=#0000ff>Vivid Solutions
Inc.
<I>www.vividsolutions.com</I></FONT></STRONG><BR></FONT><EM><FONT face=Arial
size=2>Suite #1A-2328 Government Street Victoria, B.C. V8T 5G5<BR>Phone: (250)
385 6040 - Local 308 Fax: (250) 385 6046</FONT></EM></DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Derek C. Figg
[mailto:derek@cxtsoftware.com] <BR><B>Sent:</B> April 11, 2005 1:39
PM<BR><B>To:</B> postgis-users@postgis.refractions.net<BR><B>Subject:</B>
[postgis-users] Nearest point on line<BR><BR></FONT></DIV>
<DIV><SPAN class=713152720-11042005><FONT face=Arial size=2>Hello
all,</FONT></SPAN></DIV>
<DIV><SPAN class=713152720-11042005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=713152720-11042005><FONT face=Arial size=2>Please excuse this
question if it is very basic or has been answered recently. I have
searched online for hours to no avail looking for an
answer.</FONT></SPAN></DIV>
<DIV><SPAN class=713152720-11042005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=713152720-11042005><FONT face=Arial size=2>I have a database
full of linestrings (StreetLine). I am searching this database to find
the line string that is closest to a specified point. I am successfully
able to do this with this code:</FONT></SPAN></DIV>
<DIV><SPAN class=713152720-11042005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=713152720-11042005><FONT face=Arial size=2>CREATE FUNCTION rg
(decimal (9,6), decimal (9,6)) RETURNS SET OF tblImportData AS $$<BR>SELECT
*<BR> FROM tblImportData<BR> WHERE "StreetLine" &&
Expand(GeomFromText('POINT(' || $1 || ' ' || $2 ||
')',-1),.0004)<BR> AND Distance(GeomFromText('POINT(' || $1 || ' '
|| $2 || ')',-1),"StreetLine") < .0004<BR> ORDER BY
Distance(GeomFromText('POINT(' || $1 || ' ' || $2 ||
')',-1),"StreetLine")<BR> LIMIT 1;<BR>$$ LANGUAGE
SQL;<BR></FONT></SPAN></DIV>
<DIV><SPAN class=713152720-11042005><FONT face=Arial size=2>I want to go a
step further though, and determine what exact point on the linestring is
closest to the point I have specified. Basically, I want to know the
intersecting point on the linestring where the distance from the specified
point to the line is smallest. Thanks in advance for any info that you
can provide me.</FONT></SPAN></DIV>
<DIV align=left><FONT face=Arial size=2></FONT> </DIV>
<DIV align=left><FONT face=Arial size=2>Derek Figg</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BLOCKQUOTE></BODY></HTML>