[R-sig-Geo] Shapefile in spatstat package

Adrian.Baddeley at csiro.au Adrian.Baddeley at csiro.au
Fri Aug 12 12:20:13 CEST 2011


Alexandre dos Santos writes:

 > I was trying to use an object SpatialPolygonsDataFrame in shapefile 
 > format with the package spatstat,
 > I used Baddeley's material "Handling in the shapefiles package of 
 > spatstat", but I could not plot the owin created, 
 > I maked for this purpose:

  > require (maptools)
  > require (spatstat)
  > x <- readShapeSpatial ("mtaremanne92.shp")
  > cregions <- slot (x, "polygons")
  > cregions <- lapply (cregions, function (x) {SpatialPolygons (list (x))})
  > cwindows <- lapply (cregions, as.owin)

The vignette ('Handling shapefiles in the spatstat package') says that these commands 
can be used if 'x' is a 'SpatialPolygons' object.

But in your example, 'x' is a 'SpatialPolygonsDataFrame' object, ... so you first need to extract the SpatialPolygons information: 

  x <- readShapeSpatial ("mtaremanne92.shp")
  y <- as(x, "SpatialPolygons")
  cregions <- slot (y, "polygons")
  cregions <- lapply (cregions, function (z) {SpatialPolygons (list (z))})
  cwindows <- lapply (cregions, as.owin)

Adrian Baddeley
====
Prof Adrian Baddeley (UWA/CSIRO)
CSIRO Mathematics, Informatics & Statistics
Leeuwin Centre, 65 Brockway Road, Floreat WA 6014, Australia
Tel: 08 9333 6177 | Fax: 08 9333 6121 | Mob: 0410 447 821
Skype: adrian.baddeley



More information about the R-sig-Geo mailing list