pointsInPoly(spBayes)
pointsInPoly()所属R语言包:spBayes
Finds points in a polygon
查找点在一个多边形
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Given a polygon and a set of points this function returns the subset of points that are within the polygon.
此函数返回给定的多边形的一组点在多边形内的点的子集。
用法----------Usage----------
pointsInPoly(poly, points, ...)
参数----------Arguments----------
参数:poly
an nx2 matrix of polygon vertices. Matrix columns correspond to vertices' x and y coordinates, respectively.
nx2的多边形顶点矩阵。矩阵的列对应的顶点的x和y坐标,分别。
参数:points
an mx2 matrix of points. Matrix columns correspond to points' x and y coordinates, respectively.
mx2矩阵点。矩阵的列相对应的点的x和y坐标,分别。
参数:...
currently no additional arguments.
目前没有任何额外的参数。
Details
详细信息----------Details----------
It is assumed that the polygon is to be closed by joining the last vertex to the first vertex.
据推测,该多边形是通过加入到第一个顶点的最后一个顶点封闭。
值----------Value----------
If points are found with the polygon, then a vector is returned with elements corresponding to the row indices of points, otherwise NA is returned.
如果点被发现与多边形,然后返回一个向量points,否则NA返回的行指数对应的元素。
(作者)----------Author(s)----------
Andrew O. Finley <a href="mailto:finleya@msu.edu">finleya@msu.edu</a>, <br>
Sudipto Banerjee <a href="mailto:sudiptob@biostat.umn.edu">sudiptob@biostat.umn.edu</a>, <br>
实例----------Examples----------
## Not run: [#不运行:]
##Example 1[#示例1]
points <- cbind(runif(1000, 0, 10),runif(1000, 0, 10))
poly <- cbind(c(1:9,8:1), c(1,2*(5:3),2,-1,17,9,8,2:9))
point.indx <- pointsInPoly(poly, points)
plot(points, pch=19, cex=0.5, xlab="x", ylab="y", col="red")
points(points[point.indx,], pch=19, cex=0.5, col="blue")
polygon(poly)
##Example 2[#示例2]
##a function to partition the domain[#函数域进行分区]
tiles <- function(points, x.cnt, y.cnt, tol = 1.0e-10){
x.min <- min(points[,1])-tol
x.max <- max(points[,1])+tol
y.min <- min(points[,2])-tol
y.max <- max(points[,2])+tol
x.cnt <- x.cnt+1
y.cnt <- y.cnt+1
x <- seq(x.min, x.max, length.out=x.cnt)
y <- seq(y.min, y.max, length.out=y.cnt)
tile.list <- vector("list", (length(y)-1)*(length(x)-1))
l <- 1
for(i in 1 length(y)-1)){
for(j in 1 length(x)-1)){
tile.list[[l]] <- rbind(c(x[j], y[i]),
c(x[j+1], y[i]),
c(x[j+1], y[i+1]),
c(x[j], y[i+1]))
l <- l+1
}
}
tile.list
}
n <- 1000
points <- cbind(runif(n, 0, 10), runif(n, 0, 10))
grd <- tiles(points, x.cnt=10, y.cnt=10)
plot(points, pch=19, cex=0.5, xlab="x", ylab="y")
sum.points <- 0
for(i in 1:length(grd)){
polygon(grd[[i]], border="red")
point.indx <- pointsInPoly(grd[[i]], points)
if(!is.na(point.indx[1])){
sum.points <- length(point.indx)+sum.points
text(mean(grd[[i]][,1]), mean(grd[[i]][,2]), length(point.indx), col="red")
}
}
sum.points
## End(Not run)[#(不执行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|