title: measuring distances in r with get.knnx
body: <p>My task is to calculate the shortest distance between a set of points and a set of polygons that contain them. The set of points is a SpatialPointsDataFrame with 5491 rows, while the set of polygons is a SpatialPolygonsDataFrame with 77 rows.</p>
  <p>As the function <code>geosphere::dist2Line</code> takes too long, I tried with <code>FNN::get.knnx</code>. This function seems convenient to me, because it both calculates the shortest distance from a point to a polygon and also gives the index of that polygon.</p>
  <pre><code>points &lt;- read.dta13(&quot;Results/DHS + IPUMS shapefiles/benin.dta&quot;)
  points_sf &lt;- st_as_sf(points, coords = c(&quot;LONGNUM&quot;, &quot;LATNUM&quot;), crs =  &quot;+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0&quot;)
  
  poly&lt;- sf::read_sf(dsn = &quot;-/world_geolev2_2020.shp&quot;, layer = &quot;world_geolev2_2020&quot;) %&gt;%
    filter(CNTRY_NAME == &quot;Benin&quot;) %&gt;%
    rename(GEOLEV2 = &quot;GEOLEVEL2&quot;) %&gt;%
    st_transform(st_crs(points_sf))
  
  d &lt;- get.knnx(coordinates(as_Spatial(poly)), coordinates(as_Spatial(points_sf)),k=1)
  </code></pre>
  <p>However, the distances calculated by <code>get.knnx</code> are numeric values comprised between 0 and 1. Is there a way to express these distances in meters?</p>