title: How to calculate geo-distance from a polygon?
body: <p>I have a shapefile with 50+ different polygonal shapes (representing 50+ different regions) and 10,000+ data points that are supposed to be present in one of the regions. The thing is, the 10,000+ points are already coded with a region they are supposed to be in, and I want to figure out how far they are from this coded region in geo-spatial distance.</p>
  
  <p>My current approach (code below), which involves converting shapefiles to <code>owin</code> objects from the <code>sp</code> library and using <code>distfun</code> gets me distances in lat,long euclidean space. But I would like to get geo-spatial distances (eventually to convert to km). Where should I go next?</p>
  
  <pre><code>#basically cribbed from http://cran.r-project.org/web/packages/spatstat/vignettes/shapefiles.pdf (page 9)
  shp &lt;- readShapeSpatial("myShapeFile.shp", proj4string=CRS("+proj=longlat +datum=WGS84"))
  regions &lt;- lapply(slot(shp, "polygons"), function(x) SpatialPolygons(list(x)))
  windows &lt;- lapply(regions, as.owin)
  
  # need to convert this to geo distance
  distance_from_region &lt;- function(regionData, regionName) {
      w &lt;- windows[[regionName]]
      regionData$dists &lt;- distfun(w)(regionData$lat, regionData$long)
      regionData
  }   
  </code></pre>