 
Torleif
 
Thanks for replying to my post and for the code. I have been getting a  
number of useful suggestions
and am attempting to modify your code to address  my particular problem.  I 
will be letting everyone know
how this comes  out.    
 
Have a great week.
 
Joe 





In a message dated 5/22/2009 5:07:36 A.M. Mountain Daylight Time,  
torleif.lunde@cih.uib.no writes:

Hi  Joe

Like Roger says you should first look at the possible datum  problem. The 
example below shows one method to find the closest polygon,  and to add 
that 
to the overlay. Notice however that if you change the  projection and/or 
ellipsoid the closest points (end of lines) are  different. Closest line in 
this case is calculated  by:
abs((x2-x1)*(y1-y0)-(x1-x0)*(y2-y1))/sqrt(((x2-x1)^2+(y2-y1)^2))^2)

where  x0, and y0 is the point, while x1, y1, and x2, y2 are the line ends.

To  find the two closest points, spDistsN1 is used. 

Try to play with  un-commenting polys <- spTransform(polys, CRS("+proj=moll 
 
+ellps=WGS84"))
and changing ll.logical=FALSE/TRUE (FALSE = Euclidean,  TRUE = Great Circle 
distance)

One of the things you will see is  that the closest points are different 
when 
you calculate the distance in  km (ll.logical=TRUE) combined with 
proj4string=CRS("+proj=moll  +ellps=WGS84")

I hope this gives some insight in the problem.  

The code can also be downloaded from  http://open.uib.no/R/mindist.R

I do not guarantee the code is bug  free.

You could try to replace polys with your polygon, and ssample  with your 
points, and see if it makes sense.

Best  wishes
Torleif





**************A strong credit score is 700 or above. See Yours in Just 2 
Easy Steps! 
(http://pr.atwola.com/promoclk/100126575x1222585033x1201462753/aol?redir=http://www.freecreditreport.com/pm/default.aspx?sc=668072&hmpgID=115&b
cd=Maystrongfooter52309NO115)

	[[alternative HTML version deleted]]

