Adrian, Thanks a lot for sharing your script. I was trying to write my own function but your code saved me a lot of time. It worked just fine. I just have one question. I couldn't find the function is.tess. Where is it? -- Adalberto Pineda.
-----Original Message----- From: Adrian Baddeley [mailto:adr...@maths.uwa.edu.au] Sent: Sunday, April 19, 2009 10:45 PM To: Adalberto Pineda; r-sig-geo@stat.math.ethz.ch; Adrian Baddeley Subject: [R-sig-Geo] Converting Tessellation objects into shape files Adalberto Pineda <apin...@dataquick.com> writes: > I was trying to convert an object of class tess generated using the spatstat > package into a shape file Source the code below, and then apply the function 'tess2SP' to your tessellation object. This will convert it to a SpatialPolygons object, which you can then output as a shapefile. (This only works if the tessellation is made of polygons or rectangles.) Adrian Baddeley ----------------------------------------------------------------------------------------- require(spatstat) require(sp) # convert spatstat objects to sp classes owin2Polygons <- function(x, id="1") { stopifnot(is.owin(x)) x <- as.polygonal(x) closering <- function(df) { df[c(seq(nrow(df)), 1), ] } pieces <- lapply(x$bdry, function(p) { Polygon(coords=closering(cbind(p$x,p$y)), hole=is.hole.xypolygon(p)) }) z <- Polygons(pieces, id) return(z) } tess2SP <- function(x) { stopifnot(is.tess(x)) y <- tiles(x) nom <- names(y) z <- list() for(i in seq(y)) z[[i]] <- owin2Polygons(y[[i]], nom[i]) return(SpatialPolygons(z)) } owin2SP <- function(x) { stopifnot(is.owin(x)) y <- owin2Polygons(x) z <- SpatialPolygons(list(y)) return(z) } This message contains confidential information and is in...{{dropped:5}} _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo