[R-sig-Geo] pixellate.owin when "owin" contains separate, overlapping polygons
Adrian.Baddeley at csiro.au
Adrian.Baddeley at csiro.au
Sat Jun 4 12:40:08 CEST 2011
Robin W Hunnewell rhunne at mac.com wrote:
> I've used pixellate.owin() to convert an object of class "owin" to a pixel image -- the owin in question is
> unusual in that it contains multiple, overlapping polygons.
This is a question about the 'spatstat' package.
Out of curiosity - How did you create such an object? The code should refuse to create it, unless you switched off the error checking.... Overlapping polygons violate the requirements of the owin class, and this will cause trouble sooner or later.
> Now I'd like to change (constrict) the frame area of a resulting "im" object by assigning
> a different and smaller window to it, using pixellate.owin
pixellate.owin is not designed to do that.
The argument 'W' to pixellate.owin is mainly intended as a way of controlling pixel resolution. It is meant to define a pixel raster. The raster must be large enough to contain the original window.
To do what you want, first convert your window to an 'im' object using pixellate.owin (without the 'W' argument), and then trim it to a smaller window using "[.im" as follows (where 'Depth' is your original window and 'ConvexW3' is the desired subwindow)
A <- pixellate(Depth)
B <- A[ConvexW3, drop=FALSE]
C <- B[as.rectangle(ConvexW3)]
Line 2 sets all pixels outside the window 'ConvexW3' to NA. It is needed only if 'ConvexW3' is not a rectangle; it's redundant if 'ConvexW3' is a rectangle.
Line 3 trims the pixel raster to the smallest valid rectangle.
To control the pixel resolution, for example if you want pixels to have size 'eps', replace line 1 by
A <- pixellate(Depth, eps=eps)
Adrian Baddeley
More information about the R-sig-Geo
mailing list