Skip to content

Prevent minor discrepancy in pixel resolution using Spatstat

3 messages · Roger Bivand, T.D. Rudolph

#
When I specify eps=25 (m resolution) in a call to distmap...
yrange=c(-100, 100) + sort(c(temp$y, temp$Y2)))
[1] 23.94167
[1] 24.42667

...The resulting resolution is slightly different than 25x25 metres.  So now
when I use it as a mask:
...and convert it to a RasterLayer for matrix algebra with another raster
Error in compare(c(e1, e2)) : Different bounding box
Error in getValues(tempmap * trajrast) :
  error in evaluating the argument 'x' in selecting a method for function
'getValues'

...it doesn't work because the resolution is not exactly equal.  Now I can
sometimes trick it when the number of rows and cells are still equal, BUT...
extent(trajrast)<-extent(tempmap)
Error in compare(c(e1, e2)) : nrows different
Error in getValues(tempmap * trajrast) :
  error in evaluating the argument 'x' in selecting a method for function
'getValues'

...This is not always the case!

How can I prevent the numbers of rows and columns from being so slightly
different because of a minor different in resolution?  Otherwise put, how
can I make the actual resolution of my distmap image exactly 25m as desired?

Tyler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100217/d87eca10/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tempmap.grd
Type: application/octet-stream
Size: 596 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100217/d87eca10/attachment.obj>
#
On Wed, 17 Feb 2010, Tyler Dean Rudolph wrote:

            
I think that you are seeing the impact of your input window not being 
exactly divisible by your eps in as.mask() and then getting nr and nc that 
do not partition the x and y ranges into discrete 25m blocks, because of 
ceiling().

             if (!is.null(eps)) {
                 nr <- ceiling(diff(w$yrange)/eps)
                 nc <- ceiling(diff(w$xrange)/eps)
             }

Browse[2]> nr
[1] 15
Browse[2]> nc
[1] 12

With:

subwin<-owin(xrange=c(-100, 110+2.7) + sort(c(temp$x, temp$X2)),
  yrange=c(-100, 90+18.6) + sort(c(temp$y, temp$Y2)))

you get something like what you want, with a lot of fiddling. Have you 
considered not setting eps, using spatstat.options("npixel") to set nr and 
nc, and tailoring the window to suit 25m (yrange == eps*nr, etc.). If you 
know the xrange, yrange of the raster you want to compare with, maybe use 
that as the source for the window, spatstat.options("npixel") to feed 
through nr and nc, then you could fix eps indirectly?

Hope this helps,

Roger