[R-sig-Geo] Problems with gDelaunayTriangulation and neighbors.

Rolf Turner r.turner at auckland.ac.nz
Fri Dec 20 07:50:11 CET 2013



If you are going to do Delaunay triangulation, why not use the 
appropriate software,
i.e. "deldir"?  I ***know*** it's appropriate because I wrote it. :-)

It works without stumbling, and is lucidly documented.  I ***know*** 
it's lucidly
documented because I wrote the documentation. :-)

     cheers,

     Rolf Turner

On 19/12/13 05:37, Christian Jansson wrote:
> Hi,
>
> I'm very happy that rgeos was updated to also do delaunay triangulation,
> but I have problems to match the results with the points.
>
> I need to to what is in the example-code in gDelaunayTriangulation-help.
> With meuse-data it works, but not with my own data.
>
> How can the error in the following code be avoided? So I get out5.
>
> -------------
> library(sp)
> library(rgeos)
>
> tmp.coords <- structure(list(lon = c(-69.9601058046182, -69.9307142312949,
> -69.9492587302774, -69.938119947523, -69.9599320928521, -69.958492947506,
> -69.9517184088961, -69.9515127466649, -69.9608290339626,
> -69.9463054201695), lat = c(-17.922645866545, -17.9157740845672,
> -17.9166152585801, -17.9329659455957, -17.9270430312235, -17.933297069203,
> -17.9170708735245, -17.916779044717, -17.9405611407101,
> -17.9098645380403)), .Names = c("lon", "lat"), class = "data.frame",
> row.names = c(NA, -10L))
> coordinates(tmp.coords) <- c("lon", "lat")
> plot(gDelaunayTriangulation(tmp.coords))
> points(tmp.coords)
>
> out <- gDelaunayTriangulation(tmp.coords, onlyEdges=TRUE)
> lns <- slot(slot(out, "lines")[[1]], "Lines")
> out1 <- SpatialLines(lapply(seq(along=lns), function(i)
> Lines(list(lns[[i]]), ID=as.character(i))))
> out2 <- lapply(1:length(out1), function(i) which(gTouches(tmp.coords,
> out1[i], byid=TRUE)))
> out3 <- do.call("rbind", out2)
> o <- order(out3[,1], out3[,2])
> # The previous line generates "Error in out3[, 1] : subscript out of bounds"
>
> out4 <- out3[o,]
> out5 <- data.frame(from=out4[,1], to=out4[,2], weight=1)



More information about the R-sig-Geo mailing list