title: Calculate minimum distance from polygon to spatial point
body: <p>I am having trouble finding the distance between polygons and spatial points. I am trying to measure the distance between districts (polygons) and former tin mines (spatial points). I suspect I may have done something wrong with the projection. I seem to be able to calculate the distance between the districts, but not for districts and mines. </p>
  
  <pre><code>#Open file
  mapping&lt;- readOGR(dsn="C:/Users/noble/OneDrive - London School of Economics/LSE/EC465/Extended Essay/Stack Exchange Question/gadm2.Peninsula.dbf")
  
  
  #Define the districts
  Kinta &lt;- mapping[mapping@data$NAME_1 == "Perak" &amp;
               mapping@data$NAME_2 == "Kinta", ]
  Gombak &lt;- mapping[mapping@data$NAME_1 == "Selangor" &amp;
               mapping@data$NAME_2 == "Gombak", ]
  
  #Set a projection
  EPSG.3375&lt;-"+proj=omerc +lat_0=4 +lonc=102.25 +alpha=323.0257964666666 +k=0.99984 +x_0=804671 +y_0=0 +ellps=GRS80 +units=m +no_defs"
  Gombak.km&lt;-spTransform(Gombak,CRS(EPSG.3375))
  Kinta.km&lt;-spTransform(Kinta,CRS(EPSG.3375))
  
  #Calculate the distance
  gDistance(Kinta.km, Gombak.km, byid=TRUE)
  
  #Open data on tin mines and define as spatial points
  tin.01&lt;-read.csv("C:/Users/noble/OneDrive - London School of Economics/LSE/EC465/Extended Essay/Stack Exchange Question/Tin Mine Location_01.csv")
  coordinates(tin.01)&lt;-8:9
  
  proj4string(tin.01) &lt;- CRS("+proj=omerc +lat_0=4 +lonc=102.25 +alpha=323.0257964666666 +k=0.99984 +x_0=804671 +y_0=0 +ellps=GRS80 +units=m +no_defs")
  
  #Find distance between district and mines
  gDistance(Kinta.km,tin.01,byid=TRUE)
  </code></pre>
  
  <p>My output for the distance between polygons appear to be correct:</p>
  
  <pre><code>&gt; gDistance(Kinta.km, Gombak.km, byid=TRUE)
     59
  71 100676
  </code></pre>
  
  <p>But my output for distance between the districts and mines are definitely wrong:</p>
  
  <pre><code>&gt; gDistance(Kinta.km,tin.01,byid=TRUE)
      59
  1 661153.5
  2 661152.6
  3 661153.0
  4 661152.7
  5 661151.8
  6 661152.9
  7 661153.1
  8 661153.3
  9 661153.2
  </code></pre>
  
  <p>What I intend to do is to:
  1) calculate the distance between all districts in Malaysia with all the former tin mines; and
  2) extract the distance of the closest tin mine to each district. </p>
  
  <p>Here's a <a href="https://drive.google.com/open?id=1PRG6pj7IP5Mmy2s7JuuKQlmxmdtJM8GF" rel="nofollow noreferrer">link</a> to the data I'm using. I'm using GADM data for the district polygons and I've hand coded the location of historical tin mines myself. Would appreciate all help given. Thank you.</p>