1

I am trying to accomplish exactly what is being done in this question: Convert line shapefile to raster, value=total length of lines within cell using spatstat::pixellate.psp() technique (see third answer) but I cannot figure out how to control and adjust the resolution of the output raster...

Spatstat documentation says to use the "Window" parameter to adjust resolution but I'm getting the same output resolution whether I use it or not. Also, the third answer in the question cited above uses a dimxy= parameter that is not producing any change in my output resolution no matter what number I input.

  • You need to use the W argument for the function as well as creating an owin object that represents the target resolution. Without your code or a repeatable example one can only speculate but I imagine that you have not, in fact, created the appropriate owin object to pass to the W argument. – Jeffrey Evans Jun 6 '18 at 14:33
  • i have created the owin object but as per the description it sounds like a bounding box... should I understand the owin object as a template for the size of single pixel? – mikeLdub Jun 6 '18 at 14:38
  • It is easy to miss "..." arguments in a function but, often the are passing an argument to another function that do exactly what you want. The problem is that the behavior of the argument (as well as the actual arguments) are in the other functions help. – Jeffrey Evans Jun 6 '18 at 15:18
2

It is important to read a functions help in detail. The W argument controls the spatial domain of the output and the ... arguments explicitly state:

Optional arguments passed to as.mask to determine the pixel resolution

If you look at help for as.mask you will see that the eps argument controls the resolution of a pixel image. You can also just create an owin object, using as.mask, and pass this object to the W argument.

library(spatstat)
library(raster)
X <- psp(runif(10),runif(10), runif(10), runif(10), window=owin())
l <- pixellate(X, eps=0.005)

The im class object can easily be coerced into a raster object using raster::raster.

( l <- raster(l) )
  plot(l)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.