Skip to content

focal point with function using multiple rasters

5 messages · Sarah Goslee, Roozbeh Valavi, Diogo André Alagador

#
Dear colleagues.

 

I have 4 equal-sized rasters respecting 4 climate variables.

I would like to have for each cell the weighted-average climatic distance
(in the Euclidean space defined by the 4 variables) to its 8 closest
neighboring cells, with weight related to the geographic distances.

Can someone guide me on how to do it?

 

Thanks in advance,

Best regards,

Diogo Alagador

MED, University of ?vora, Portugal
#
Hi,

Since you are starting from scratch, I'd suggest looking into the
terra package, documented here:
https://rspatial.org/terra/pkg/index.html

The focal() function is probably what you're looking for, but you will
need to read some of the docs to learn how to load and work with
raster data in general.

You'll also need to think more rigorously about how you want to
calculate climatic distance for an individual grid cell. The
distance() function in terra might help, but it isn't clear to me
which of the many approaches you wish to implement.

Sarah
On Tue, Mar 16, 2021 at 9:58 AM Diogo Andr? Alagador <alagador at uevora.pt> wrote:

  
    
#
Dear Sarah

Thank you your suggestion.
My doubt if the function to use in focal may use data from other multiple rasters.
To say: I need to use the 4 climate rasters to define the climate of each cell in the climatic space.
Then I need to compute  for each cell the Euclidean climatic distance in the 4D space to climates of each neighboring cell. Followed by an weighted average using spatial distance among the focal and enamoring cells.

Is this really implementable in a cost-effective way?

Kind regards,
Diogo Alagador
MED, University of ?vora, Portugal
#
Hi Diogo,

Functions like focal only work with a single layer raster. You might need
to loop through all the cells and extract focal values with *getValuesFocal*
(from raster) or *values* (from terra) and calculate your metric. Tho there
might be a more efficient solution for this.

Cheers,
Roozbeh Valavi
The Quantitative & Applied Ecology Group <http://qaeco.com/>
School of BioSciences, The University of Melbourne, VIC 3010, Australia
*Mobile*: +61 423 283 238 | *Twitter*: @ValaviRoozbeh | *Researchgate
<https://www.researchgate.net/profile/Roozbeh_Valavi>*


On Wed, Mar 17, 2021 at 2:48 AM Diogo Andr? Alagador <alagador at uevora.pt>
wrote:

  
  
#
Dear Roozbeh.

 

Thank you by your suggestion.

Although it seems like a very much busy way to get what I need I was expecting (afraid) that was the real solution to move.

 

Best regards,

Diogo Alagador

MED, University ?vora, Portugal

 

 

De: Roozbeh Valavi <rvalavi at student.unimelb.edu.au> 
Enviada: ter?a-feira, 16 de mar?o de 2021 23:42
Para: Diogo Andr? Alagador <alagador at uevora.pt>
Cc: Sarah Goslee <sarah.goslee at gmail.com>; r-sig-ecology at r-project.org
Assunto: Re: [R-sig-eco] focal point with function using multiple rasters

 

Hi Diogo,

 

Functions like focal only work with a single layer raster. You might need to loop through all the cells and extract focal values with getValuesFocal (from raster) or values (from terra) and calculate your metric. Tho there might be a more efficient solution for this.

 

Cheers,

Roozbeh Valavi

 <http://qaeco.com/> The Quantitative & Applied Ecology Group

School of BioSciences, The University of Melbourne, VIC 3010, Australia

Mobile: +61 423 283 238 | Twitter: @ValaviRoozbeh | Researchgate <https://www.researchgate.net/profile/Roozbeh_Valavi>
On Wed, Mar 17, 2021 at 2:48 AM Diogo Andr? Alagador <alagador at uevora.pt <mailto:alagador at uevora.pt> > wrote:
Dear Sarah

Thank you your suggestion.
My doubt if the function to use in focal may use data from other multiple rasters.
To say: I need to use the 4 climate rasters to define the climate of each cell in the climatic space.
Then I need to compute  for each cell the Euclidean climatic distance in the 4D space to climates of each neighboring cell. Followed by an weighted average using spatial distance among the focal and enamoring cells.

Is this really implementable in a cost-effective way?

Kind regards,
Diogo Alagador
MED, University of ?vora, Portugal 

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org <mailto:R-sig-ecology at r-project.org> 
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology