[R-sig-Geo] Problem with gain/offset and sampleRegular
Ned Horning
horning at amnh.org
Fri Oct 7 22:59:44 CEST 2011
Hi - I am working on a topographic correction script and am having a
problem with the gain and offset settings.
This is how I set the gain and offset:
gainVal <- 0.108078
offsetVal <- -0.37
gain(satImage) <- gainVal
offs(satImage) <- offsetVal
When I look at the gain/offset values they look fine:
> gain(satImage)
[1] 0.108078
> offs(satImage)
[1] -0.37
When I get a bunch of samples using sampleRegular (or sampleRandom) the
retrieved values are not correct:
> satImageSamps <- sampleRegular(satImage, numSamps, cells=TRUE)
> head(satImageSamps)
cell p125r49_5t19890217_subset
[1,] 1504 0.41935178
[2,] 1511 0.48943690
[3,] 1518 0.51279861
[4,] 1525 0.40767093
[5,] 1532 0.06892616
[6,] 1539 0.30254324
But if I extract the value for the first cell in satImageSamps the value
looks like what I would expect:
> extract(satImage, 1504)
6.871226
If I run the script without altering the gain and offset values I still
get different values for the same cell number using sampleRegular and
extract but they are roughly the same. I have a similar problem using
sampleRandom - the value returned for a cell is different than what I
get using extract with the cell number.
Is this a bug or am I doing something wrong?
I am using raster version 1.9-19 downloaded from the CRAN.
All the best,
Ned
More information about the R-sig-Geo
mailing list