[R-sig-Geo] Converting Tessellation objects into shape files

Adalberto Pineda apineda at dataquick.com
Mon Apr 20 22:31:11 CEST 2009

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:adrian at maths.uwa.edu.au]
Sent: Sunday, April 19, 2009 10:45 PM
To: Adalberto Pineda; r-sig-geo at stat.math.ethz.ch; Adrian Baddeley
Subject: [R-sig-Geo] Converting Tessellation objects into shape files

Adalberto Pineda <apineda at 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



# convert spatstat objects to sp classes

owin2Polygons <- function(x, id="1") {
  x <- as.polygonal(x)
  closering <- function(df) { df[c(seq(nrow(df)), 1), ] }
  pieces <- lapply(x$bdry,
                   function(p) { 
                             hole=is.hole.xypolygon(p))  })
  z <- Polygons(pieces, id)

tess2SP <- function(x) {
  y <- tiles(x)
  nom <- names(y)
  z <- list()
  for(i in seq(y))
    z[[i]] <- owin2Polygons(y[[i]], nom[i])

owin2SP <- function(x) {
  y <- owin2Polygons(x)
  z <- SpatialPolygons(list(y))

This message contains confidential information and is in...{{dropped:5}}

More information about the R-sig-Geo mailing list