[R-sig-Geo] convert from spatstat to sp

Edzer Pebesma edzer.pebesma at uni-muenster.de
Fri Oct 29 22:36:51 CEST 2010

There is; if your question is about converting an object of class im
(spatstat) to an object of class SpatialGridDataFrame (sp), it is in
package maptools:

whitenoise <- im(matrix(rnorm(1200),30,40))
x = as(as(whitenoise, "SpatialGridDataFrame"), "SpatialPixelsDataFrame")

if your polygons are in SpatialPolygons object pol, then

sel = overlay(x, pol)
x.sel = x[!is.na(sel),]

should get you there.

On 10/29/2010 09:28 PM, Peter Larson wrote:
> Hello all,
> Is there any way to convert from spatstat to sp?
> Specifically, I am looking to clip a density plot produced in spatstat
> to include only points within a polygon boundary in a shapefile. if
> there is a way to clip in spatstat, this would also be acceptable.
> Any ideas?
> Thanks
> pete
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de

More information about the R-sig-Geo mailing list