我对空间数据不是很有经验,但是,也许您可以将其用作入门:
library(sp)
library(raster)
library(rgeos)
# load map
d <- getData("GADM", country = "Germany", level = 2)
# generate some random points
set.seed(1)
p <- data.frame(
lon = jitter(sample(8:13, 20, T)),
lat = jitter(sample(49:52, 20, T))
)
# match points with polygons
mat <- gContains(d, SpatialPoints(p, proj4string=CRS(sp::proj4string(d))), byid=TRUE)
hits <- colSums(mat)
cols <- rev(heat.colors(diff(range(hits))+1))
# plot
plot(d, col = cols[hits+1], border = "green")
with(p, points(lon, lat, col = "blue", pch = 19, cex = .5))
