2011-03-15 36 views
0

我有一個數據框架中邊界橢球的x,y座標。然後我在data.fame中有幾個query x,y座標。在X,Y座標的包圍橢圓體是使用函數計算...查詢x,y座標橢球內部/外部座標

exy <- ellipsoidhull(X[,1:2]) 

這樣....

plot(predict(exy), xlim=c(-0.018, 0.015), ylim=c(-0.018,0.015), 
    cex=0.1, type="l") 

給我這個樣子....

陰謀

enter image description here

我有這樣的查詢....

 V2  V3 
-0.0167 -0.0137 
-0.0159 -0.0127 
-0.0150 -0.0127 
-0.0164 -0.0137 
-0.0164 -0.0134 
-0.0173 -0.0131 

我如何才能找到哪個query位於邊界橢球內/外?有一個R功能來做到這一點?謝謝

回答

2

mgcv提供了這樣的功能(但不是唯一的 - 如果你想了解空間物體,請參閱sp::overlay)。這是in.out()函數的例子。

library(mgcv) 
data(columb.polys) 
bnd <- columb.polys[[2]] 
plot(bnd,type="n") 
polygon(bnd) 
x <- seq(7.9,8.7,length=20) 
y <- seq(13.7,14.3,length=20) 
gr <- as.matrix(expand.grid(x,y)) 
inside <- in.out(bnd,gr) 
points(gr,pch=as.numeric(inside)+1) 

enter image description here

+0

@Roman ...感謝您的方向。 'sp'軟件包對於我想要做的事來說是一個完美的選擇 – user645600 2011-03-15 11:15:14