问题描述
我想使用我的空间数据集 (sp_ds
) 作为 ppp
(spatstat Point Pattern 对象) 用于完整的空间测试目的,我尝试这样做:
# Packages
library(spatstat)
library(sf)
library(sp)
library(raster) ## maybe a cause of pointdistance() function,not used yet
# Open spatial data set in GitHub
sp_ds<-read.csv("https://raw.githubusercontent.com/Leprechault/trash/master/myspds.csv")
str(sp_ds)
#'data.frame': 4458 obs. of 2 variables:
# $ Lat : num 9.17 9.71 9.12 9.12 9.71 ...
# $ Long: num 35.8 35.5 35.8 35.8 35.5 ...
# Create boudaries using sf
sfds = st_as_sf(sp_ds,coords=c("Long","Lat"),crs=4326)
traps<-sp_ds
ch <- chull(traps[,c(2,1)])
coords <- traps[c(ch,ch[1]),]
coordinates(coords) <- c("Long","Lat")
proj4string(coords) <- CRS("+init=epsg:4326")
W <- owin(poly=cbind(coordinates(coords)[,2],coordinates(coords)[,1]))
# Create a ppp Point Pattern object
out.ppp<-ppp(x=sp_ds$Lat,y=sp_ds$Long,window=W)
plot(out.ppp)
# Make a CRS test
f1 <- ppm(out.ppp~1)
E <-envelope(f1,Kinhom,nsim = 19,global = TRUE,correction = "border")
plot(E)
但我想以米为单位 r 距离(x 轴),为此我需要将 4326 的坐标参考系统转换为 UTM,但有 3 个 UTM 区域混合:
#34N bounds: (18.0,0.0,24.0,84.0)
#35N bounds: (24.0,30.0,84.0)
#36N bounds: (30.0,36.0,84.0)
请问,有没有一种简单的方法可以在 UTM 中创建一个独特的 ppp
对象,其中包含没有区域叠加的区域混合?
提前致谢!
解决方法
对于穿越区域,米/公里的更好选择是本地自定义投影,例如 laea:https://twitter.com/mdsumner/status/1136794870113218561?s=19
# Packages
library(spatstat)
library(sf)
library(sp)
# Open spatial data set in GitHub
sp_ds<-read.csv("https://raw.githubusercontent.com/Leprechault/trash/master/myspds.csv")
str(sp_ds)
#'data.frame': 4458 obs. of 2 variables:
# $ Lat : num 9.17 9.71 9.12 9.12 9.71 ...
# $ Long: num 35.8 35.5 35.8 35.8 35.5 ...
# sf object convertion
sp_ds <- st_read("https://raw.githubusercontent.com/Leprechault/trash/master/myspds.csv")
sp_ds_sf <- st_as_sf(sp_ds,coords = c("Lat","Long"),crs = 4326)
# Here the laea transformation:
sp_ds_laea = st_transform(sp_ds_sf,crs = "+proj=laea +x_0=3600000 +y_0=3600000 +lon_0=29.9 +lat_0=13.4 +datum=WGS84 +units=m")
# Create boudaries using sf
ch_ds <- st_convex_hull(st_union(sp_ds_laea))
W<- as.owin(ch_ds)
# Create a ppp Point Pattern with sf object
out.ppp <- as.ppp(X=st_coordinates(sp_ds_laea),W=W)
plot(out.ppp)
# Make the CRS test
f1 <- ppm(out.ppp~1)
E <-envelope(f1,Kinhom,nsim = 19,global = TRUE,correction = "border")
plot(E)