title: How to extract xy-coordinates from raster where its highest value is located within a polygon?
body: <p>given is a raster as well as a SpatialPolygonsDataframe. 
  In order to retrieve the highest value of the raster within the area of a polygon, raster::extract can be used. It works fine. </p>
  
  <p>How to get additionally the coordinates of the extracted highest value of the raster within the area of a polygon?</p>
  
  <pre><code># create raster
  r &lt;- raster(ncol=36, nrow=18)
  r[] &lt;- runif(ncell(r))
  # create SpatialPolygons from GridTopology
  grd &lt;- GridTopology(c(-150, -50), c(40, 40), c(8, 3))
  Spol &lt;- as(grd, "SpatialPolygons")
  # create SpatialPolygonsDataFrame
  centroids &lt;- coordinates(Spol)
  x &lt;- centroids[,1]
  y &lt;- centroids[,2]
  SPDF &lt;- SpatialPolygonsDataFrame(Spol, data=data.frame(x=x, y=y, row.names=row.names(Spol)))
  # extract max value of raster for each SpatialPolygon
  ext &lt;- raster::extract(r, SPDF, fun=max)
  </code></pre>
  
  <p>*example code is taken from R-documentation </p>