Page 1 of 2
Exporting Dsurface map into GIS

Posted:
Tue Oct 21, 2014 11:37 am
by Lombardijv
Murray,
I wanted to know if there was a way to export a density surface map from R into a GIS (shape file?), and if so what would I export the file as? Reason why I am asking is because my advisors and I wanted to see if we could overlay the density surface map on top of a city zoning map in order to identify potential hot spots of human - carnivore contact.
- Jason
Re: Exporting Dsurface map into GIS

Posted:
Tue Oct 21, 2014 3:50 pm
by murray.efford
Hi Jason
I don't have a simple answer. secr masks and Dsurfaces don't include projection information that would be needed. The next version of secr will have a method for making a raster package RasterLayer object from a Dsurface, and then I expect you could export from raster, sp etc. Meantime, you have the options of exporting the raw coordinates and density values (e.g. covariate D.0), or constructing a RasterLayer object with the raster signature for matrix objects (see ?raster).
Murray
Re: Exporting Dsurface map into GIS

Posted:
Mon Jun 01, 2015 1:50 pm
by sixtystrat
So then, how would one extract the values for D.0? I can get the x and y okay but am having trouble with the r language to get me down to D.0. Thanks!
Joe
Re: Exporting Dsurface map into GIS

Posted:
Mon Jun 01, 2015 5:36 pm
by murray.efford
A Dsurface is a sort of mask. Group-specific densities are stored as columns in the covariates attribute, extracted with covariates(). 'D.0' is used for 'all groups'. Unfortunately, I wrote a 'print' method for Dsurfaces that makes it look as if D.0 is part of the same dataframe as x and y, which it isn't.
- Code: Select all
shorePossums <- predictDsurface(possum.model.Ds)
head(covariates(shorePossums))
head(covariates(shorePossums)$D.0)
The working version (2.9.5) available from the Density website also has documentation for making a 'raster' object from a Dsurface that may help (see Examples in ?raster once you've installed and loaded 2.9.5).
Murray
Re: Exporting Dsurface map into GIS

Posted:
Tue Jun 02, 2015 11:17 am
by sixtystrat
That worked! If I wanted to estimate N for a subset of the study area within that grid (a conservation area for example), could I simply sum the per-pixel density values within that subset or would I have to re-run the model using that area as a mask? The former is a lot quicker... I understand that my densities (which are on a per ha basis) for summing would have to be adjusted because my pixels are larger than 1 ha. Thanks!
Joe
Re: Exporting Dsurface map into GIS

Posted:
Tue Jun 02, 2015 4:25 pm
by murray.efford
Joe
There's no need to re-fit the model. You can sum pixels as you suggest, or, more directly, use region.N specifying the 'region' argument, which may be a mask or a SpatialPolygonsDataFrame (see Details in ?region.N).
Murray
Re: Exporting Dsurface map into GIS

Posted:
Wed Jun 03, 2015 7:40 am
by sixtystrat
Great. Thanks as always for your prompt response Murray.
Joe
Exporting fx.total into GIS

Posted:
Wed Mar 28, 2018 3:36 pm
by cowzrgr8
Mr. Efford,
I have a similar question about exporting a map into GIS. Is there a way to export a plot created by fx.total into GIS? I am having difficulties turning this plot into a raster using writeSpatialShape, raster, writeRaster, etc.
Thank you
Becca
Re: Exporting Dsurface map into GIS

Posted:
Wed Mar 28, 2018 4:14 pm
by murray.efford
- Code: Select all
fxsurface <- fx.total(ovenbird.model.D, sessnum = 3)
r <- raster(fxsurface, 'D.fx')
library(raster)
plot(r)
# or, if that doesn't work
plot(r, useRaster = FALSE)
But first, do you really want to use fx.total? These pretty plots are usually misleading. Be prepared to explain in words exactly what it is that you are plotting and why, and do _not_ call it a 'density plot'.
Re: Exporting Dsurface map into GIS

Posted:
Wed Mar 28, 2018 4:39 pm
by cowzrgr8
Thank you! My hope is to display best trap locations for Blanding's turtles based off trap captures and predicted density (I'm not trying to suggest population density from these maps).
Unfortunately when I run that code the raster looks nothing like the original plot. Do you think using the fxi.contour instead presents similar results to that of the fx.total? I was hoping for more of a color gradient to depict best trap locations, but perhaps the polygons created from fxi.contour will display similar results.
Thank you