Exporting rasters

Hi all, I am new to here and new to using R as well. I have been creating Kernel Density Estimates for radio-collared grouse. The code I am using will produce a plot showing the KDE as a raster with the specified kernel level indicated:

Rplotraster

The kernel level (the black line on the plot) is automatically exported as a shapefile in the coding, but I would really love to export the underlying raster so I can import that into GIS as well. I have spent some time trying to do this, but I really have no idea how.

Here is the code block I used:

# Creates and exports kernel density isopleths as shapefiles
# Allows greater flexibility in selecting bandwidth
# Created by John Leonard 08_23_2016
# User defined input. Modify lines below.
############################################################################
per = 95
hmeth = rhrHref # select one: rhrHref, rhrHlscv, rhrHpi, rhrHrefScaled
h_meth = "rhrHref" # Same as above but with quotations. You must specify both.
############################################################################
# Load packages
require(rhr)
require(sp)
require(maptools)
require(rgdal)
rhr_results = matrix(nrow=0, ncol=8)
colnames(rhr_results)<-c("ID", "HR_TYPE", "KERNEL_LEVEL", "POINTS",
                         "AREA_HA", "h_value1", "h_value2", "h_meth")
for (i in 1:length(newlist)){
  name= names(newlist[i])
  xy<-SpatialPoints(newlist[[i]]@coords)
  bandwidth= hmeth(xy)$h
  kde<-rhrKDE(xy, h = bandwidth, levels = per)
  name = names(newlist[i])
  row = nrow(newlist[[i]])
  area = (rhrArea(kde, levels = per)$area/10000)
  h_value1=bandwidth[1]
  h_value2=bandwidth[2]
  plot(kde, main = name)
  plot(xy, add=TRUE)
  iso<-rhrIsopleths(kde, levels = per)
  plot(iso, main = name)
  writePolyShape(iso,paste0(name,"_",per,"_",h_meth), factor2char=TRUE)
  cat(showWKT(proj4string(newlist[[i]])),
      file=paste0(name,"_",per,"_",h_meth,".prj"))
  rhr_results=rbind(rhr_results, c(name, "RHR",per,row,
                                   area, h_value1,h_value2, h_meth))
}
rm(area, bandwidth, h_meth, h_value1, h_value2, i,
   iso, kde, name, per, row, xy, hmeth) # remove unwanted objects

Okay so now I realize that this is not a raster, but when I export it to a shapefile and load it into GIS, I still can't get the resulting polygon with all of the colored isopleths.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.