For my masters project, I have data frame of boating vessel positions (VesPos – lon,lat), time (fixed_timestamp_utc, years, quarters) and Vessel ID (vessel_id). I also have a multi-polygon object of a ICES designation area “6a” (ICES_6a) as my spatial window for edge-correction. My data runs across multiple years, some which do not have data for every quarter (specifically the first and last year).
I am trying to create a ppp object to be used for Spatio-temporal kernel density estimates (STKDE) with this data. However, when I do, all data points are omitted as they lay outside the spatial window.
list of packages in use,ggplot2,sf,dplyr,lubridate,ggspatial,tidyr,sp,spatstat,sqldf,sparr
`# Current Data
wd <-setwd("C:/Users/tonyl/OneDrive/Desktop/University")
VesPos <- read.csv("C:/Users/tonyl/OneDrive/Desktop/University/data/vessel_position_20240524.csv")
ICES_6a <- st_read("C:/Users/tonyl/OneDrive/Desktop/University/data/ICES_6a/ICES_6a.shp")`
`#convert date to timeframe (years, quarter; examples 1999,3)
VesPos$fix_timestamp_utc <- mdy_hm(VesPos$fix_timestamp_utc)
VesPos$year <- year(VesPos$fix_timestamp_utc)
VesPos$quarter <- quarter(VesPos$fix_timestamp_utc)`
`#ICES deisgnation 6a multipolygon projection
ICES_6a_projected <- st_transform(ICES_6a, crs = 3857)
window_owin <- as.owin(ICES_6a_projected)`
`# depending on the trial and error, the data is omitted because it lays outside the window
points_pp <- ppp(x = VesPos$latitude,
y = VesPos$longitude,
marks = VesPos$quarter,
window = window_owin,
check=TRUE,
checkdup= TRUE)`
`stkde_results <-spattemp.density(points_pp,
h = h_spatial,
lambda = h_temporal,
tlim = c(1,4),
sres = 128)`
`### after running spattemp.density() with the funky ppp object
Calculating trivariate smooth...Done.
Edge-correcting...Error in approx(xords, kords, x) :
need at least two non-NA values to interpolate`
I have sieved through the data to find issues with NA values, or if the window/data are not projected correctly (through visual checks). I have simplified the data frames to only contain relevant columns in case of a naming convention overlap (unaware if a real issue here).
Separately, both maps looks normal in co-ordinates, so I assume it may be due to the way I have tried to create the ppp object.
[ICES 6a](https://i.sstatic.net/4aty95iL.png) [ICES 6a on the world map](https://i.sstatic.net/Hl9SHNRO.png) [example vessel paths with co-oridnates](https://i.sstatic.net/3Gxc4HAl.png)
Thanks for any help, I’ve hit a brick wall and my dyslexia has burnt out my brain while trying to troubleshoot. Any pointers in the right direction would be helpful.
Adamm0355 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.