我正在计算一个对象围绕一个对象的多个位置之间的行进距离。我为对象(无法越过的边界)和个人移动创建了SpatialLines多边形。有没有一种方法可以将边界合并到SpatialLinesLengths对象的计算中?我知道在计算KUD时是可能的,但是我还无法弄清楚如何转换该信息以用于计算行进距离。
第二,有没有一种方法可以将边界对象添加到绘图中,并迫使线性运动围绕该对象运动?如果是这样,是否可以略微弯曲线以使绘图看起来更逼真?
proj4string(dat.sp) <- CRS("+init=epsg:4326") #set that projection to actual data
dat.proj <- spTransform(dat.sp, CRS("+init=epsg:32611")) #transform data to the correct spatial projection
isle.shp <- readOGR(dsn = "C:////isle.shp", layer = "isle) #load in the boundary object
isle.sp <- spTransform(isle.shp, CRS("+init=epsg:32611")) #transform the shapefile to spatial points
datline.proj <- list(0)
ID <- sort(unique(dat.proj$ID)) #creates a vector of ids
for(i in 1:length(ID)){
datline.proj[[i]] <- Lines(list(Line(coordinates(dat.proj[dat.proj@data$ID==ID[i],]))), ID=ID[i])
} #for every ID, set spatial 'coordinates' and assign a 'Line' object to the list of 'Lines'
track.proj <- SpatialLines(datline.proj) #coerce 'Lines' objects into a 'SpatialLines' object
proj4string(track.proj) <- CRS("+init=epsg:32611") #make it follow the the same projection
isle.bound <- as(isle.sp, 'SpatialLinesDataFrame') #convert the boundary object spatial polygons df to a spatial lines df
distance <- SpatialLinesLengths(track.proj, longlat = TRUE) #calculating distance traveled
distravel <- data.frame(Transmitter = ID, distance) #combine distance info with the individual data
track.proj <- SpatialLinesDataFrame(track.proj, data = distravel, match.ID = FALSE) #attach the df to generate a SpatialLinesDataFrame
track.proj@data #view the movements of individuals
#now plot the SpatialLines object for every individual
plot_list <- list() #create an empty list
for(i in 1:length(ID)){ #for every iteration
file_name = paste("Spatial Lines Plots_", ID[i], ".png", sep="")
#create a file name for each plot
png(file_name) #save as a .png
p <- plot(isle.sp, col = "grey80")
p <- title(main = ID[i], col.main = "black", cex.main = 2)
p <- plot(track.proj[i,], lwd = 3, col = "black", add = TRUE)
plot_list[[i]] <- p #fill the plot_list with the plot created in the previous lines
dev.off() #turn plotting off after each run of the loop
} #close for loop