[R-sig-Geo] ext option for Raster's sampleRandom not working?

Ned Horning horning at amnh.org
Wed Jun 5 22:56:45 CEST 2013


Hi -

I am trying to run a script that calculates a common extent between two 
images than then uses that extent to restrict the random selection of 
cells from a raster using the sampleRandom function. For some reason it 
doesn't seem to be working although it used to work. It appears as if 
the "ext=TRUE" argument doesn't have an effect. The cells that are 
returned cover the entire image and are not restricted to the area 
defined by the "ext" variable.

Another thing I notiiced is that when I use "xy=TRUE" along with 
"cells=TRUE" the resulting coordinates do not appear to match with the 
cell numbers. When I use "xyFromCell" to calculate the coordinates of 
the center of a cell returned from sampleRandom I get a good result but 
it is different form the coordinates for that same cell returned from 
sampleRandom.

I checked the extent and it looks fine.

Would someone be able to check if the extent feature in SampleRandom is 
working in the Raster package. If someone thinks of something I'm doing 
wrong please let me know.

Here is the line of code I am using:
sampleCells <- sampleRandom(predImage, size=numSamps, cells=TRUE, 
ext=commonExt)[,1]

I'm using raster 2.1-25 with R 3.0 on Ubuntu 12.04 64 bit

Ned



More information about the R-sig-Geo mailing list