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)
}

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to