[R-sig-Geo] OWIN spatial point pattern

Rolf Turner r.turner at auckland.ac.nz
Wed Jan 18 22:25:46 CET 2012


On 19/01/12 09:54, Jose Funes wrote:
> Hi,
> I am trying to create an binary mask and use it to create a ppp object and
> to be able to compute a density surface. I have failed in defining the owin
> as a mask. Please read code below:
>
> ####Definition of the window as matrix: from raster to image and from image
> image to matrix
> sudan1<-readGDAL("sudanbndry1")
> im.sudan<- as.im(sudan1)
> Vsudan<- im.sudan$v
> Wsudan<- levelset(Vsudan,21,"==")
> matrix.sudan<- as.matrix(Wsudan)
>
> ###Points pattern###
>
> sudan98<- read.csv("sudan98.txt")
> sudan98sa<- ppp(sudan98$Longitude, sudan98$Latitude,
> owin(mask=matrix.sudan,xrange,yrange))
>
> Error in owin(...) :
>    If one of xrange, yrange is specified then both must be.
>
> Your feedback are welcome, thanks.

Your example is ***not*** self contained and reproducible, as the 
Posting Guide
specifies it should be.  We do not have (convenient) access to 
"sudanbndry1".

It appears, from the code that you posted, that neither "xrange" nor 
"yrange",
which appear in your call to owin(), is defined.  However, if that were 
the case,
the resulting error message would be different.

Here is a simple (reproducible!) example:

     set.seed(42)
     m <- matrix(sample(c(TRUE,FALSE),100,TRUE),10,10)
     w <- owin(mask=m,xrange,yrange)

     Error in owin(mask = m, xrange, yrange) : object 'xrange' not found

So you actually did something different from what you are telling us.

The following works:

     set.seed(42)
     m <- matrix(sample(c(TRUE,FALSE),100,TRUE),10,10)
     w <- owin(mask=m,xrange=c(0,1),yrange=c(0,1))

So your call to owin() should work if you specify appropriate values for 
xrange
and yrange.

If you still have problems please provide a *reproducible* example, with the
code that you actually used.

     cheers,

         Rolf Turner



More information about the R-sig-Geo mailing list