Export polygons generated from adehabitat.
In this post, you will learn how to:
- Calculate UDs from test
data from Masked boobies.
- Calculate UDs using adehabitat.
-
Export UDs as shapefiles to visualize in other programs.
Note that reference system must be adjusted, also href can be adapted.
Load data. This test data is from masked boobies.
To access the
data you have to install the package sula:
devtools::install_github(“MiriamLL/sula”)
#devtools::install_github("MiriamLL/sula")
library(sula)
Data<-(GPS_raw)
You can use the structure of the data to organize your data similarly. It also works with csv data (if you have excel data you can also save it as csv data an import it to R)
You can use the package sp to transform your data frame to spatial data (in this case you end up with SpatialPointsDataFrame). This way you can tell R that you have coordinates. If you dont have the package sp you need to install it.
#install.packages('sp')
library(sp)
DataSp<-as.data.frame(Data)
coordinates(DataSp) <- c("Longitude", "Latitude")
class(DataSp)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
If you dont have the package adehabitat you have to install it. I strongly encourage you to read the vignette, here is the link..
Now you have a object class estUDm as a result.
class(DataUD)
[1] "estUDm"
The function getvertices calculates the polygon. You can adjust the percent, here I stated 95%.
DataUD_pol <- getverticeshr(DataUD, percent = 95, unout = c("m2"))
You can select the data from one individual to create individual UDs.
GPS01<-subset(Data,Data$IDs=='GPS01')
As before, you transform the data frame to SpatialPointsDataFrame and calculate the kernels using the reference value.
head(GPS01)
Latitude Longitude DateGMT TimeGMT IDs
1 -27.20097 -109.4531 02/11/2017 17:05:30 GPS01
2 -27.20084 -109.4531 02/11/2017 17:09:35 GPS01
3 -27.20053 -109.4529 02/11/2017 17:13:50 GPS01
4 -27.20092 -109.4531 02/11/2017 17:17:59 GPS01
5 -27.20065 -109.4529 02/11/2017 17:22:13 GPS01
6 -27.20061 -109.4528 02/11/2017 17:26:25 GPS01
GPS01Sp<-as.data.frame(GPS01)
coordinates(GPS01Sp) <- c("Longitude", "Latitude")
proj4string(GPS01Sp) <- CRS("+proj=utm +zone=12 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
GPS01UD=kernelUD(GPS01Sp,h="href") # Using reference
GPS01UD
********** Utilization distribution of an Animal ************
Type: probability density
Smoothing parameter estimated with a href parameter
This object inherits from the class SpatialPixelsDataFrame.
See estUD-class for more information
You can check the h value used with the following line. This is important because it can be adjusted and you should state it while describing your methods.
GPS01UD@h
$h
[1] 0.02096601
$meth
[1] "href"
The most common home ranges calculations are the 50% and the 95% areas. Here are some lines to obtain those polygons.
GPS01UD95HR<-getverticeshr(GPS01UD,percent=95)
GPS01UD50HR<-getverticeshr(GPS01UD,percent=50)
Here you can check on you polygons visually.
I advice to first identify which folder do you want to use to save your polygons. I have an Rproject and I have created a folder named GIS where I want my polygons to be.
There are many ways to export your polygons.
One is using the package rgdal which comes from Geospatial Data Abstraction Library.
The other way to export your polygons is using the package sf. However, to be able to export your polygons, they should be transform to a sf object.
… and thats it.
Hopefully now you have your shapefiles that can be open in any GIS software such as QGIS.