title: Check if point is in spatial object which consists of multiple polygons/holes
body: <p>I have a SpatialPolygonsDataFrame with 11589 objects of class "polygons". 10699 of those objects consists of exactly 1 polygon, however the rest of those objects consists of multiple polygons (2 to 22). </p>
  
  <p>If an object of consists of multiple polygons, three scenarios are possible:</p>
  
  <ol>
  <li>Sometimes, those additional polygons describe a "hole" in the geographic ara describe by the first polygon in the object of class "polygons". </li>
  <li>Sometimes, those additional polygons describe additional geographic areas, i.e. the shape of the region is quite complex and described by putting together multiple parts. </li>
  <li>Sometimes, it might be a mix of both, 1) and 2).</li>
  </ol>
  
  <p>Stackoverflow helped me to plot such an spatial object properly (<a href="https://stackoverflow.com/questions/21962452/plot-spatial-area-defined-by-multiple-polygons">Plot spatial area defined by multiple polygons</a>). </p>
  
  <p>However, I am still not able to answer how to determine whether a point (defined by longitude/latitude) is in a polygon. </p>
  
  <p>Below is my code. <strong>I tried to apply the function <code>point.in.polygon</code> in the <code>sp</code> package, but found no way how it could handle such an object which consists of multiple polygons/holes.</strong> </p>
  
  <pre><code># Load packages
  # ---------------------------------------------------------------------------
  library(maptools)
  library(rgdal)
  library(rgeos)
  library(ggplot2)
  library(sp) 
  
  
  # Get data
  # ---------------------------------------------------------------------------
  # Download shape information from the internet
  URL &lt;- "http://www.geodatenzentrum.de/auftrag1/archiv/vektor/vg250_ebenen/2012/vg250_2012-01-01.utm32s.shape.ebenen.zip"
  td &lt;- tempdir()
  setwd(td)
  temp &lt;- tempfile(fileext = ".zip")
  download.file(URL, temp)
  unzip(temp)
  
  # Get shape file
  shp &lt;- file.path(tempdir(),"vg250_0101.utm32s.shape.ebenen/vg250_ebenen/vg250_gem.shp")
  
  # Read in shape file
  map &lt;- readShapeSpatial(shp, proj4string = CRS("+init=epsg:25832"))
  
  # Transform the geocoding from UTM to Longitude/Latitude
  map &lt;- spTransform(map, CRS("+proj=longlat +datum=WGS84"))
  
  
  # Pick an geographic area which consists of multiple polygons
  # ---------------------------------------------------------------------------
  # Output a frequency table of areas with N polygons 
  nPolys &lt;- sapply(map@polygons, function(x)length(x@Polygons))
  
  # Get geographic area with the most polygons
  polygon.with.max.polygons &lt;- which(nPolys==max(nPolys))
  
  # Get shape for the geographic area with the most polygons
  Poly.coords &lt;- map[which(nPolys==max(nPolys)),]
  
  
  # Plot
  # ---------------------------------------------------------------------------
  # Plot region without Google maps (ggplot2) 
  plot(Poly.coords,  col="lightgreen")
  
  
  # Find if a point is in a polygon 
  # ---------------------------------------------------------------------------
  # Define points 
  points_of_interest &lt;- data.frame(long=c(10.5,10.51,10.15,10.4), 
                       lat =c(51.85,51.72,51.81,51.7),
                       id  =c("A","B","C","D"), stringsAsFactors=F)
  
  # Plot points
  points(points_of_interest$long, points_of_interest$lat, pch=19)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/RrZ7W.jpg" alt="enter image description here"></p>