我从这里下载了一个大的SpatialPolygonsDataFrame:
http://omap.africanmarineatlas.org/BIOSPHERE/pages/3_terrestrial%20vegetation.htm
我使用以下内容创建了SpatialPolygonsDataFrame:
white_veg <- readOGR(dsn="data",
layer="Whites vegetation")
我有一个单独的数据帧,看起来像这样:
id <- c(1,2,3,4,5,6,7,8)
lat <- c(13.8, 13.552, 13.381, -15.440, -15.860, 13.967, -27.750, -27.750)
lon <- c(2.250, 2.687, 2.865, 23.250, 23.340, 30.527, 21.420, 21.420)
x <- c(566, 537, 554, 879, 811, 268, 216, 216)
y <- c(8, 10.32, 3.83, 64.8, 53.7, 4, 5.8, 2.2)
locations <- data.frame(id, lat, lon, x, y)
我想在中创建一个新列
locations
white_veg
lat
+
lon
坐标在内部,例如
white_veg@data$DESCRIPTIO
.
我读过
a question
在…上
gcontains()
从
rgeos
包,但这只返回长度为1的逻辑向量,我不确定这表示什么:
locations_coords <- data.frame(locations$lat, locations$lon)
locations_spoints <- SpatialPoints(locations_coords,proj4string=CRS(proj4string(white_veg)))
gContains(white_veg, locations_spoints)
this on the GIS SE
,使用
over
从
sp
但答案不够透彻,我无法理解。