为什么我的 spatialEco::sf.kde() 输出栅格与输入点数据相反?

问题描述 投票:0回答:0

我正在尝试从点数据集计算空间 KDE。为了实现这一点,我使用了包

sf.kde
.
中的功能
spatialEco

但是,当从点计算 KDE 时,具有 KDE 值的结果栅格似乎被投影到点数据上。

我尝试了不同的方法来缩小问题的范围,它似乎是在 KDE 的计算过程中发生的。我试图为它提供一个参考栅格,但这也不会改变它(无论是否使用参考栅格,结果都是一样的)。当我为函数提供一个不同的、更本地化的 CRS 时,也没有任何改变。

但是我敢肯定,错误出在我的代码中的某个地方,因为包中提供的示例似乎有效。

我试图操纵参数 bw、scale.factor 和标准化,但没有任何帮助。

这是带有样本数据的代码。你能重现这个问题吗?你知道问题是什么以及如何解决吗?



library(tidyverse)
library(spatialEco)
library(terra)
library(sf)
library(tidyterra)


###extract coordinates for sites to later use for plotting
coord<- read.table(text="id site   lat   lng
 1   100  40.3  21.5
 2   101  40.8  22.6
 3   102  39.3  22.8
 4   103  40.3  21.6
 5   104  39.4  22.1
 6   105  40.5  21.4
 7   106  39.5  22.3
 8   107  37.7  20.8
 9   108  40.6  24.7
10   109  40.6  24.8
11   110  39.3  22.4
12   111  39.5  22.8
13   112  39.8  22.5
14   113  39.7  21.2
15   114  40.9  25.5
16   115  37.6  22.4
17   116  39.7  21.0
18   117  37.0  25.0
19   118  38.5  22.9
20   119  38.5  22.5
21   120  40.5  22.5
22   121  40.5  22.6
23   122  40.0  19.9
24   123  40.0  19.7
25   124  39.6  21.2
26   125  39.6  20.7
27   127  37.0  22.8
28   128  38.0  22.2
29   129  40.5  21.9
30   130  38.0  22.2
31   131  40.6  22.5
32   132  38.2  20.7
33   133  39.1  22.9
34   134  38.2  20.7
35   135  40.5  21.4
36   136  38.6  21.7
37   137  39.7  21.7
38   166  41.4  21.6
39   167  35.3  25.5
40   168  37.7  24.3
41   169  38.5  22.6
42   170  35.3  25.6
43   171  37.9  23.0
44   172  35.2  20.8
45   173  41.0  25.2
46   174  40.1  21.3
47   175  37.6  22.7
48   176  37.6  22.8
49   177  37.6  22.8
50   178  40.5  21.4", header=TRUE)


dat2 <- coord |>
  rename(lon = lng)

dat2 <- st_as_sf(dat2, coords = c("lon", "lat")) |>
st_set_crs(4326)


ext(dat2)

r <- rast(ncol = 500, nrow = 300, ext(dat2))

pt.kde <- sf.kde(x = dat2, 
                 bw = 1, ref=r, 
                 scale.factor = 1,
                 standardize = F)

ggplot() +
  geom_spatraster(data = pt.kde) +
  geom_spatvector(data = dat2)



r coordinates geospatial projection kernel-density
© www.soinside.com 2019 - 2024. All rights reserved.