I'd like to use my spatial data set (sp_ds
) as ppp
(spatstat Point Pattern object) for complete spatial tests purposes, and I try to do:
# 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)
But I'd like to r distance (x axis) in meters and for this I need to convert the coordinate reference system of 4326 to UTM, but a have 3 UTM zones mixture:
#34N bounds: (18.0, 0.0, 24.0, 84.0)
#35N bounds: (24.0, 0.0, 30.0, 84.0)
#36N bounds: (30.0, 0.0, 36.0, 84.0)
Please, is there a simple way to create a unique ppp
object in UTM with a mixture of zones without zone superposition?
Thanks in advance!
For traversing zones, the better choice for meters/kilometres is a local custom projection such as 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)