[R-sig-Geo] Counting kernelUD home range polygons
Angelika Gummert
Angelika.Gummert at gmx.de
Wed Jun 10 14:16:46 CEST 2015
Hi,
I am sending my question again since there was a problem with my email,
making my message unreadable in the archive.
-------
Hi,
I wanted to count the number of polygons (home ranges of my species) inside
a grid in order to estimate the number of species in a given area. I
followed the example on this website, but it doesn't work properly:
<https://3c.gmx.net/mail/client/dereferrer?redirectUrl=http%3A%2F%2Fgis.stac
kexchange.com%2Fquestions%2F116388%2Fcount-overlapping-polygons-in-single-sh
ape-file-with-r>
http://gis.stackexchange.com/questions/116388/count-overlapping-polygons-in-
single-shape-file-with-r
Here is what I did:
#Data
You can download a part of my data here:
<https://3c.gmx.net/mail/client/dereferrer?redirectUrl=http%3A%2F%2Fwww.link
file.de%2Fdownload-136449c43d7939ea2de29accbc9cc981.php>
http://www.linkfile.de/download-136449c43d7939ea2de29accbc9cc981.php
#Calculation of the species home range
Fishsplit<-split(Data, f=Data$Species ) #split data
HaeVit<-Fishsplit[["Haemulon vittata"]]
HaeVit2 <- SpatialPoints(HaeVit[,2:3])
HaeVitKernel<-kernelUD(HaeVit2, kern ="epa") #home range estimation
HomeRange1 <- getverticeshr(HaeVitKernel, 95) #create Polygon
Question1: I repeated the calculation for each individual species. I have in
total around 600 species, so it will take a long time if I do it like this.
The function kernelUD returns a list of elements of class estUD when the
object xy passed as argument contains the relocations of several animals
(i.e., belong to the class SpatialPointsDataFrame). But somehow I am unable
to convert my species data to a SpatialPointsDataFrame which allows me to
calculate several home ranges.
Question2: I would like to define a barrier (boundary of the Ocean) that
cannot be crossed by the animals. I know that there is an argument named
boundary, but I don't know how I can used it in order to add the ocean
borders of the Caribbean sea (shapefile) as boundary.
# Load shapefile of the Caribbean Sea (you are able to download it at
<https://3c.gmx.net/mail/client/dereferrer?redirectUrl=http%3A%2F%2Fwww.natu
ralearthdata.com%2Fdownloads%2F10m-physical-vectors%2F10m-ocean%2F>
http://www.naturalearthdata.com/downloads/10m-physical-vectors/10m-ocean/
World <- readOGR(dsn = "Z:/./Oceans", layer = "LME66")
Caribbean <- World[World at data$OBJECTID %in% c("25"),]
#create a grid
bb <- bbox(Caribbean)
cs <- c(1, 1)*0.5 # cell size
cc <- bb[, 1] + (cs/2) # cell offset
cd <- ceiling(diff(t(bb))/cs) # number of cells per direction
grd <- GridTopology(cellcentre.offset=cc, cellsize=cs, cells.dim=cd)
grd
# find the count of polygons below each grid cell
sp_grd <- SpatialGrid(grd)
proj4string(sp_grd) <- CRS("+proj=cea +datum=WGS84 +ellps=WGS84
+towgs84=0,0,0")
Polygons<-Homerange1+ Homerange 2+ Homerange 3+ Homerange 4
Question3: I don't know how I should "combine" the polygons. This is not
working since I can not count the polygons (see result). I don't know if it
is even necessary if I calculate the home range for several species at once.
PolygonsSP<- as(Polygons, "SpatialPolygons")
crs(sp_grd)<-crs(PolygonsSP)
o <- over(sp_grd, CombinedPolyTestSP, returnList=TRUE)
ct <- sapply(o, length)
summary(ct)
SGDF <- SpatialGridDataFrame(sp_grd, data=data.frame(ct=ct))
# plot
spplot (SGDF, "ct", colorkey=TRUE,col.regions=colorRampPalette(c("white",
"red"), bias=2),
panel = function(...) {
panel.gridplot(..., border="black")
sp.polygons(Caribbean)
sp.points(Data[,2:3], cex=1,pch = 20, col="black")
})
Result: the plot shows, that only 1 Polygon was counted in each grid cell.
So the 4 home range polygons were counted as one.
I hope you can help me to fix this problem,
Best regards
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list