[R-sig-Geo] Pruning a delaunay triangulation with a shape

rundel rundel at gmail.com
Sat Jul 24 02:43:11 CEST 2010


I'm not very familiar with either the tri or nb classes so I'm not entirely
sure what is possible. From a cursory look it seems like this is not
possible with tri as it seems to only internally store the point locations
and recalculates the triangulation whenever the object is printed or
plotted. I have a function below that I think works with nb classes, but I
haven't tested it.



bound <- SpatialPolygons(list(Polygons(list(Polygon(cbind( 
x=c(0.34063939, 0.56754974, 0.95361248, 0.96464284, 0.60694389, 
0.58173163, 0.58330740, 0.91421832, 1.00403700, 0.96464284, 
0.50294332, 0.39263968, 0.22560845, 0.02548613, 0.25397225, 
-0.01233226, 0.34063939), 
y=c(1.02171515, 0.70486571, 0.92207697, 0.84834471, 0.62116963, 
0.53747356, 0.47569788, 0.35812482, 0.02134774, -0.07231216, 
0.15287015, 0.14489909, -0.03444965, 0.09707276, 0.56138672, 
0.58729265, 1.02171515) ) )),ID="bound")))


dat <- data.frame( 
x=c(0.34433527, 0.08592805, 0.55564179, 0.03938242, 0.98044051, 
0.19835405, 0.94186612, 0.56208017, 0.31093811, 0.54341230, 
0.93508703, 0.38160473, 0.89435383, 0.55457428, 0.22406338), 
y=c(0.997803213, 0.094993232, 0.509774611, 0.615526709, 0.004314438, 
0.676662461, 0.026060349, 0.165807011, 0.596449068, 0.469553704, 
0.888788079, 0.163129754, 0.340335312, 0.621845245, 0.019412254) 
) 

dat.tr <- tri.mesh(dat) 
dat.sl <- tri.asSpLines(dat.tr)

dat.nb = tri2nb(dat)


filternb = function(nb, coords, bound) {
	sl = nb2lines(nb,as.list(rep(NA,length(nb))), coords)
	
	out=!gCrosses(sl,bound,byid=TRUE)
	
	k=1
	for(i in 1:length(nb)) {
		l = length(nb[[i]])
		nb[[i]] = nb[[i]][ out[k:(k+l-1)] ]
		k=k+l
	}
	
	return(nb)
}

dat.nb.new = filternb(dat.nb, dat, bound)

plot(bound,col='red')
plot(dat.nb.new,dat,add=T)

-Colin
-- 
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Pruning-a-delaunay-triangulation-with-a-shape-tp5324088p5331731.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list