Verifique se o ponto está no objeto espacial que consiste em vários polígonos / furos

Eu tenho um SpatialPolygonsDataFrame com 11589 objetos da classe "polígonos". 10699 desses objetos consistem em exatamente 1 polígono, no entanto, o restante desses objetos consiste em vários polígonos (2 a 22).

Se um objeto consiste em vários polígonos, três cenários são possíveis:

Às vezes, esses polígonos adicionais descrevem um "buraco" na área geográfica descrita pelo primeiro polígono no objeto da classe "polígonos".Às vezes, esses polígonos adicionais descrevem áreas geográficas adicionais, ou seja, a forma da região é bastante complexa e descrita reunindo várias partes.Às vezes, pode ser uma mistura de ambos, 1) e 2).

O Stackoverflow me ajudou a plotar adequadamente um objeto espacial (Traçar a área espacial definida por vários polígonos)

No entanto, ainda não sou capaz de responder como determinar se um ponto (definido por longitude / latitude) está em um polígono.

Abaixo está o meu código.Eu tentei aplicar a funçãopoint.in.polygon nosp pacote, mas não encontrou como lidar com esse objeto que consiste em vários polígonos / furos.

# Load packages
# ---------------------------------------------------------------------------
library(maptools)
library(rgdal)
library(rgeos)
library(ggplot2)
library(sp) 


# Get data
# ---------------------------------------------------------------------------
# Download shape information from the internet
URL <- "http://www.geodatenzentrum.de/auftrag1/archiv/vektor/vg250_ebenen/2012/vg250_2012-01-01.utm32s.shape.ebenen.zip"
td <- tempdir()
setwd(td)
temp <- tempfile(fileext = ".zip")
download.file(URL, temp)
unzip(temp)

# Get shape file
shp <- file.path(tempdir(),"vg250_0101.utm32s.shape.ebenen/vg250_ebenen/vg250_gem.shp")

# Read in shape file
map <- readShapeSpatial(shp, proj4string = CRS("+init=epsg:25832"))

# Transform the geocoding from UTM to Longitude/Latitude
map <- 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 <- sapply(map@polygons, function(x)length(x@Polygons))

# Get geographic area with the most polygons
polygon.with.max.polygons <- which(nPolys==max(nPolys))

# Get shape for the geographic area with the most polygons
Poly.coords <- 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 <- 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)

questionAnswers(2)

yourAnswerToTheQuestion