[R-sig-Geo] spatstat crashes R when converting tess to sp objects

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sun Oct 28 13:57:56 CET 2012


On Sun, Oct 28, 2012 at 12:22 PM, O'Hanlon, Simon J
<simon.ohanlon at imperial.ac.uk> wrote:
> Dear list,

> #Reproducible example

 I think maptools isn't coping with certain types of tess object. I
can reproduce this in three lines without needing a download :)

1, start R, use some packages:

$ R --vanilla

R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i486-pc-linux-gnu (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(spatstat)
Loading required package: mgcv
This is mgcv 1.7-21. For overview type 'help("mgcv-package")'.
Loading required package: deldir
deldir 0.0-20
spatstat 1.28-2
Type ‘help(spatstat)’ for an overview of spatstat
     ‘latest.news()’ for news on latest version
     ‘licence.polygons()’ for licence information on polygon calculations

2. Run this to create some objects:

> example(tess)

tess>   A <- tess(xgrid=0:4,ygrid=0:4)

tess>   A
Tessellation
Tiles are equal rectangles, of dimension 1 x 1 units
4 by 4 grid of tiles
window: rectangle = [0, 4] x [0, 4] units

tess>   B <- A[c(1, 2, 5, 7, 9)]

tess>   B
Tessellation
Tessellation is determined by a factor-valued image with 5 levels
window: binary image mask
384 x 192 pixel array (ny, nx)
enclosing rectangle: [0, 3] x [1, 4] units

tess>   v <- as.im(function(x,y){factor(round(5 * (x^2 + y^2)))}, W=owin())

tess>   levels(v) <- letters[seq(length(levels(v)))]

tess>   E <- tess(image=v)

tess>   E
Tessellation
Tessellation is determined by a factor-valued image with 11 levels
window: binary image mask
128 x 128 pixel array (ny, nx)
enclosing rectangle: [0, 1] x [0, 1] units

3. Try conversion:

> as(E,"SpatialPolygons")
Error in as(E, "SpatialPolygons") :
  no method or default for coercing "tess" to "SpatialPolygons"

4. Try conversion with maptools:

> library(maptools)
Loading required package: foreign
Loading required package: sp
Loading required package: lattice
Checking rgeos availability: TRUE
> as(E,"SpatialPolygons")

 *** caught segfault ***
address (nil), cause 'memory not mapped'

I've not looked at the maptools code, but the tess object can be one
of three types according to ?tess, and I bet the conversion code
doesn't check what its dealing with...

Barry



More information about the R-sig-Geo mailing list