简体   繁体   中英

Exporting a contoured Kernel density estimation plot to raster or shapefile format

I'm trying to perform Kernel density estimation in R using some GPS data that I have. My aim is to create a contoured output with each line representing 10% of the KDE. From here i want to import the output (as a shapefile or raster) into either QGIS or arcmap so I can overlay the output on top of existing environmental layers.

So far i have used AdehabitatHR to create the following output using the below code:

kud<-kernelUD(locs1[,1], h="href")
vud<-getvolumeUD(kud)
vud <- estUDm2spixdf(vud)
xyzv <- as.image.SpatialGridDataFrame(vud)
contoured<-contour(xyzv, add=TRUE)

在此处输入图片说明

Aside from being able to remove the colour, this is how i wish the output to appear (or near to). However i am struggling to figure out how i can export this as either a shapefile or raster? Any suggestions would be gratefully received.

With the amt package this should be relatively straightforward:

library(adehabitatHR)
library(sf)
library(amt)

data("puechabonsp")
relocs <- puechabonsp$relocs


hr <- as.data.frame(relocs) %>% make_track(X, Y, name = Name) %>% 
  hr_kde(trast = raster(amt::bbox(., buffer = 2000), res = 50)) %>% 
  hr_isopleths(level = seq(0.05, 0.95, 0.1))

# Use the sf package to write a shape file, or any other supported format

st_write(hr, "~/tmp/home_ranges.shp")

Note, it is also relatively easy to plot

library(ggplot2)
ggplot(hr) + geom_sf(fill = NA, aes(col = level))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM