Skip to content
Prev 15311 / 29559 Next

calculating shortest distance from a set of SpatialPoints to a polygon

On Wed, 13 Jun 2012, Malcolm Fairbrother wrote:

            
Wait a moment! The warnings are there for a purpose (and would also affect 
the use of functions in spatstat, which also assumes planar coordinates). 
Never delete important data (in this case the metadata of your points, 
saying which spatial reference system they possess).

If your data are in geographical coordinates, you need to state that 
specifically, and look for suitable functions. One such is perhaps 
dist2Line() in geosphere.

The alternative (and I advise doing both) is to project your points and 
coastine, and use gDistance(locations, sea, byid=TRUE), which will return 
distances in the metric of the projection (probably metres).
Never set proj4string to NA if it is known (NA means not available, it 
doesn't mean ignore). The function works on planar geometries, and 
projection distortions for well-chosed projections at that scale are not 
large. Usually, wrongly defined datum metadata are more of a problem.

Roger