Ilona Naujokaitis-Lewis wrote: > 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 > >> 0. >> > > 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? > 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 > 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 > 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 _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo