[R-sig-Geo] calculating shortest distance from a set of SpatialPoints to a polygon

Malcolm Fairbrother m.fairbrother at bristol.ac.uk
Wed Jun 13 14:46:20 CEST 2012


Dear list,

I have a large set of locations scattered over a land area covering about 200,000 km². That area borders the sea, and I'd like to find the shortest distance from each point location to the sea/coast. Point locations are in lat/long.

I've turned the locations into a SpatialPoints object, with a proj4string. And I have a SpatialPolygons object consisting of a single polygon, defining the sea areas (same proj4string as for the SpatialPoints object).

My problem is I'm not clear on the next step. I tried using "gDistance" from the "rgeos" package:

dists <- gDistance(locations, sea)

but got two warnings:

Warning messages:
1: In RGEOSDistanceFunc(spgeom1, spgeom2, byid, "rgeos_distance") :
  Spatial object 1 is not projected; GEOS expects planar coordinates
2: In RGEOSDistanceFunc(spgeom1, spgeom2, byid, "rgeos_distance") :
  Spatial object 2 is not projected; GEOS expects planar coordinates

So should I set the proj4string to NA? And/or is gDistance even the right tool for this job? Maybe it's designed for instances where distances are small, not in the hundreds of kilometres?

Any advice on how to do this appropriately would be much appreciated.

- Malcolm



More information about the R-sig-Geo mailing list