您收到的警告表明您的工作可能会受到 R-spatial 和 rspatial 采用的 PROJ 6(和 GDAL 3)引入的更改的影响。您可以使用以下两个链接获取所有详细信息:
https://rgdal.r-forge.r-project.org/articles/CRS_projections_transformations.html
https://r-spatial.org/r/2020/03/17/wkt.html
要使这些警告消息消失,您只需要使用考虑到这些最近更改的类型sf
和(通过安装/加载相同名称的包)的对象。stars
因此,我建议您在脚本开头使用以下几行代码来替换前六行代码。这将为您提供两个对象(即类型的 GGT 和类型的sf
GGTgrid1 stars
):
GGT <- read.csv("C:/Users/user/Data/newdata2019.csv")
coordinates(GGT) = ~Lon+Lat
GGT <- st_as_sf(GGT)
st_crs(GGT) <- 4326
GGTgrid <- readOGR('C:/Users/user/Desktop/maps/GGTgrid.shp')
coordinates(GGTgrid) <- ~x+y
GGTgrid1 <- st_as_stars(GGTgrid1, crs = 4326)
st_crs(GGTgrid1) <- 4326
对我来说,处理真实数据比使用您的对象名称“虚拟”工作更容易,因为我没有您的原始文件。因此,我更愿意向您展示如何使用sp
包中包含的“meuse”数据进行分析。
通过类比我给你的reprex,我认为你应该能够使用自己的文件进行管理。您会看到,不会再出现警告消息 :-)
请在下面找到我的代表。
代表
library(sp)
library(sf)
library(stars)
library(gstat)
data(meuse) # loading the data (equivalent of your csv file)
coordinates(meuse) = ~x+y # you already know this step ;-)
# Just a look to the class of original data
class(meuse)
#> [1] "SpatialPointsDataFrame"
#> attr(,"package")
#> [1] "sp" # "meuse" is an object of class 'sp'
data(meuse.grid) # loading the data (equivalent of your shp file)
gridded(meuse.grid) = ~x+y
# Just a look to the class of original data
class(meuse.grid)
#> [1] "SpatialPixelsDataFrame"
#> attr(,"package")
#> [1] "sp" # "meuse" is an object of class 'sp'
- 将
meuse
数据转化为sf
对象,将meuse.grid
数据转化为stars
对象
# Convert 'sp' object 'meuse' (i.e. SpatialPointsDataFrame) into 'sf' object
meuse <- st_as_sf(meuse)
class(meuse)
#> [1] "sf" "data.frame" # meuse is indeed of class 'sf'
# Convert 'sp' object 'meuse.grid' (i.e. SpatialPixelDataFrame) into 'stars' object
meuse.grid <- st_as_stars(meuse.grid)
class(meuse.grid)
#> [1] "stars" # meuse.grid is indeed of class 'stars'
vario <- variogram(log(zinc)~1, meuse)
model_meuse <- fit.variogram(vario, model = vgm(psill = 1, model = "Sph", range = 200, nugget = 1))
plot(vario, model = model_meuse)

krige_result <- krige(formula = log(zinc)~1, meuse, meuse.grid, model = model_meuse)
#> [using ordinary kriging]
class(krige_result)
#> [1] "stars"
krige_result
#> stars object with 2 dimensions and 2 attributes
#> attribute(s):
#> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
#> var1.pred 4.77655207 5.2376428 5.5728908 5.7072284 6.1717618 7.4399908 5009
#> var1.var 0.08549102 0.1372838 0.1621815 0.1853301 0.2116141 0.5002793 5009
#> dimension(s):
#> from to offset delta refsys point values x/y
#> x 1 78 178440 40 NA NA NULL [x]
#> y 1 104 333760 -40 NA NA NULL [y]
plot(krige_result[1]) # plot predictions

plot(krige_result[2]) # plot variances

由reprex 包于 2021-10-19 创建(v2.0.1)