Skip to content

overlay fx, consistent topology, sample a point on a 'patch edge'

3 messages · Ilona Naujokaitis-Lewis, Edzer Pebesma, Roger Bivand

#
NO

Dear list-serve,
Thanks in advance to all those who help out with the inquiries, it is has
helped me numerous times. Here go my questions...

I am trying to vary existing landscapes which are composed of habitat
(patches) and non-habitat. My goals are to vary the number of patches in a
landscape, and the size of each patch. 

My landscape files are originally raster files, which I have converted to
ascii format. When importing into R, they are of class SpatialGridDataFrame,
are fully gridded. Each cell is represented by a 0: non-habitat, or a value
ranging between >0 and <=1, which represents varying degrees of habitat
quality. Patches are simply identified where adjoining cells are
The approach I have taken is to create a mask of my ascii landscape file so
that already existing patches are masked. This allows me to sample a point
in the region of my landscape that is identified as non-habitat. I then
apply the dilate function to essentially 'grow' a patch.

I have followed the code from the following link:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/115868.html
The only difference is that once I have effected the dilate function, which
is of class 'owin', I then:
1) coerce "owin" to "im" object class
2) coerce "im" object class to a SpatialGridDataframe

My problems are:
1. How to overlay my final 2 layers:  1) dilated object (object class
SpatialGridDataFrame) and 2) original landscape patch layer (also object
class SpatialGridDataFrame). I need the resulting object to be an object of
class SpatialGridDataFrame with only 1 band consisting of original patches,
the new patches, and non-habitat so I can perform additional data
manipulations. The overlay function does not appear to work with 2 objects
of this class. Any alternative suggestions? 

2. My dilated points object (SGDF) does not have topology identical to the
original layer - I think I need them to be the same for the overlay process,
and if yes, how do I change this. The cell size remains the same but the
offset and cell dimension are not identical.
For example:
	> getGridTopology(dilate_SGDF)
  	                  X1  X2
	cellcentre.offset 1050 890
	cellsize            20  20
	cells.dim           15  11
	> getGridTopology(original_layer)
        	             x   y
	cellcentre.offset 1030 870
	cellsize            20  20
	cells.dim           16  12

3. I would like to sample on the patch edge and use the dilate or erode
functions to increase or decrease the size of a patch. How can I force the
sampling of a spatial point, which becomes the centre for the dilate/erode
function, to fall on a patch edge. In other words, if I was to look at the
landscape file in ascii format I would need to sample a grid cell that has a
value of >0, but where at least 1 of the cells surrounding this point, in
all orthogonal directions, has a value = 0. 

4. How to constrain the newly added patches so that they does not overlap
with existing patches.

5. How to add patches of different sizes -perhaps I can simply add a loop to
my code?

I am using Windows XP and R.2.6.1. Any help on these issues would be greatly
appreciated. Thanks in advance for your help on these multiple but related
issues. I do appreciate the time that people take in responding to these
inquiries.

Best,
ilona

Ilona Naujokaitis-Lewis
Centre for Applied Conservation Research
Forest Sciences Department
University of British Columbia
3041-2424 Main Mall
Vancouver, BC V6T 1Z4
 
phone: 604 822.4382
email: ilonan at interchange.ubc.ca
#
Ilona Naujokaitis-Lewis wrote:
Method overlay only combines objects of different class. If you have two 
grids and want to create a third, and all three have the same 
topology/number of cells, then simply use vectorized expressions like

grd$out = grd$dilated != grd$original
You could coerce the "wrong" one into a SpatialPointsDataFrame and the 
use function (method) overlay with the good grid to get the right indexes.
--
Edzer
#
On Thu, 7 Feb 2008, Edzer Pebesma wrote:

            
This is possible, but dilute.owin() not only extends the im object where 
the dilated region would cross the existing boundary, but also clips off 
parts not containing dilated cells. In this modified version:

dilate1.owin <- function (w, r, ..., include.bb=FALSE)
{
     verifyclass(w, "owin")
     if (r < 0)
         stop("r must be nonnegative")
     if (r == 0)
         return(w)
     if (w$type != "mask")
         w <- as.mask(w, ...)
     epsilon <- sqrt(w$xstep^2 + w$ystep^2)
     r <- max(r, epsilon)
     if (!include.bb) bb <- bounding.box(w)
     else bb <- w
     newbox <- owin(bb$xrange + c(-r, r), bb$yrange + c(-r, r))
     w <- rebound.owin(w, newbox)
     distant <- distmap(w)
     dil <- w
     dil$m <- (distant$v <= r)
     return(dil)
}

the input ranges are used, buffered out by the dilation range in each 
direction. So from the cited example:
window: binary image mask
106 x 106 pixel array (ny, nx)
enclosing rectangle: [-0.03, 1.03] x [-0.03, 1.03] units
gets you there more or less.

Roger

PS. The other questions are still open, the edge detection feels a bit 
like image analysis, say the biOps package for a range of filters to 
choose the cells on the edge of the patch (perhaps, untried).