To read the pixel values of an image at the points of a point pattern (in spatstat), use
           "[.im"

If Z is your image and X is a point pattern, then Z[X] is a vector containing the pixel values of Z at the locations of X.

To attach these values to the point pattern, type
    marks(X) <- Z[X]

for example
     with(bei.extra, elev[bei])

This will deal safely with exceptional cases, avoids using undocumented functions that might change, and is also neater to write and read.

I don't know why Barry Rowlingson is giving you advice about spatstat - he recently said no-one should be using spatstat anyway - maybe it's all part of a disinformation campaign!

Adrian

Prof Adrian Baddeley FAA
CSIRO Mathematics, Informatics & Statistics
Leeuwin Centre, 65 Brockway Road, Floreat WA 6014, Australia
Tel: 08 9333 6177 | Fax: 08 9333 6121 | Skype: adrian.baddeley

________________________________
From: Jose Funes [mailto:jefunes@gmail.com]
Sent: Tuesday, 24 July 2012 9:13 AM
To: Rolf Turner
Cc: r-sig-geo@r-project.org; Baddeley, Adrian (CMIS, Floreat)
Subject: Re: [R-sig-Geo] Point pattern add covariates

Dear Rolf,
Barry suggestion addressed my question and the function lookup.img as well.
Thanks
Jose

On Mon, Jul 23, 2012 at 5:29 PM, Rolf Turner <r.turner@auckland.ac.nz<mailto:r.turner@auckland.ac.nz>> wrote:
On 24/07/12 01:26, Jose Funes wrote:
Dear list,
I have point pattern data and would like to attach/add covariates as raster
(image or grid) to it. For example as the case of the bei data with
bei.extra with covariates.

I'm afraid I don't understand what it is that you need to do.
What do you mean by "attach/add"?  In the example of the
"bei" data that you refer to, the images (covariates) "elev"
and "grad" are components of the list "bei.extra" which is
a separate object from the point pattern "bei".  The object
"bei.extra" is not "attached" to the object "bei" in any way.

Barry Rowlingson suggested that you might want to find the
values of a covariate associated with each point of a point
pattern.   The easiest way to do this is to use the (undocumented)
function "lookup.im<http://lookup.im>()".

E.g.:

    em <- with(bei.extra,lookup.im<http://lookup.im>(elev,bei$x,bei$y))
    gm <- with(bei.extra,lookup.im<http://lookup.im>(grad,bei$x,bei$y))

Then you could "attach" these values to the point pattern as
*marks*:

    marks(bei) <- data.frame(elev=em,grad=gm)

Is this (anything like) what you want to do?

    cheers,

        Rolf Turner

P. S.  Adrian:  Do you think we should make "lookup.im<http://lookup.im>()" into a *documented*
function?  I have found myself recommending its use to inquirers on more than
one occasion.

        R.


	[[alternative HTML version deleted]]

