[R-sig-Geo] now with an example for you: Problems with getting less than 100% of home range area by CharHull{adehabitatHR}
Clement Calenge
clement.calenge at oncfs.gouv.fr
Fri Dec 13 10:32:58 CET 2013
> - now i create an example which you can use (see below) -
>
> I want to create home ranges by the CharHull-function in adehabitatHR
> (CharHull {adehabitatHR} - Estimation of the Home Range by Delaunay
> Triangulation method).
>
> The Description says that I could "select a given percentage of the
> smallest triangles (measured by their area) as the home-range
> estimation". Now I want to select an home range with an area less than
> 100% of the total CharHull-Area, and finally plotting the contour or
> converting to a shape-file. But the command "getverticeshr()" doesn't
> result in 95 % homerange area, it only shows a single small polygon
> which is a part of the outer polygons of the total home range.
>
> So is there any argument like the "percent= ...." - command in the
> mcp()-function? The argument "percent=..." in plot() also result in
> these same single polygons.
There is indeed a problem with the function CharHull. Actually, an
object returned by the function CharHull is an object of class MCHu,
which is basically a list of SpatialPolygonsDataFrame (one spdf per
animal). In the case of the function CharHull, each row of the
SpatialPolygonsDataFrame corresponds to one additional hull added to the
home range, but it should correspond to the additionnal hull merged with
hulls corresponding to lower percentage. I will correct this bug in the
package asap. Meanwhile, you can use the following function to correct
the object returned by CharHull:
correctCharHull <- function(x, unin = c("m", "km"), unout = c("ha",
"m2", "km2"))
{
if (!require(rgeos))
stop("the package rgeos is required for this function")
if (!require(maptools))
stop("the package maptools is required for this function")
unin <- match.arg(unin)
unout <- match.arg(unout)
resu <- lapply(x, function(polr) {
pfs <- proj4string(polr)
pol <- as(polr, "SpatialPolygons")
lip <- list(pol[1])
for (i in 2:nrow(polr)) {
poo <- rbind(pol[i], lip[[i-1]])
pls <- slot(poo, "polygons")
pls1 <- lapply(pls, maptools::checkPolygonsHoles)
slot(poo, "polygons") <- pls1
lip[[i]] <- rgeos::gUnionCascaded(poo, id = rep(i,
length(row.names(poo))))
}
are <- adehabitatHR:::.arcpspdf(lip[[1]])
for (i in 2:length(lip)) {
are[i] <- adehabitatHR:::.arcpspdf(lip[[i]])
}
spP <- do.call("rbind", lip)
if (unin == "m") {
if (unout == "ha")
are <- are/10000
if (unout == "km2")
are <- are/1e+06
}
if (unin == "km") {
if (unout == "ha")
are <- are * 100
if (unout == "m2")
are <- are * 1e+06
}
df <- data.frame(area = are, percent = polr[[2]])
res <- SpatialPolygonsDataFrame(spP, df)
if (!is.na(pfs))
proj4string(res) <- CRS(pfs)
return(res)
})
class(resu) <- "MCHu"
return(resu)
}
For example:
data(puechabonsp)
lo<-puechabonsp$relocs[,1]
## Home Range Estimation
res <- CharHull(lo)
## Use of the correcting function:
res <- correctCharHull(res)
## get the 80% home range
ver <- getverticeshr(res,80)
plot(ver, col="grey")
HTH,
Clément Calenge
>
> I hope, you can help me.
>
> For your information: I have a SpatialPointsDataFrame with one animal
> but more than 6000 points which I have transformed successfully to
> CharHull - Polygons, a "MCHu"-class-object but after this the unsolved
> problem has begun.
>
> And here is an example-data:
>
> ###start###
>
> library(sp)
> library(rgdal)
> library(adehabitatHR)
>
> ### first the data.frame by dput(spdf_proj)
> spdf_proj <-
> structure(list(tag.local.identifier = structure(c(1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L), .Label = "2337", class = "factor"), utm.easting =
> c(683974.34404956,
> 683974.760661362, 683965.172048386, 683987.281009456,
> 683985.362453604,
> 683982.219900401, 688531.512618968, 688646.734103846,
> 688648.699663448,
> 688645.493334214, 688672.516759366, 688647.254958931,
> 687718.469882875,
> 687720.16874801, 687713.469156302, 687715.945476163,
> 684638.357135326,
> 682851.713841839, 682477.884670838, 686067.563387058,
> 682250.807247258,
> 682257.865282583, 681883.067916919, 681785.074428023,
> 679682.011093641,
> 679683.959645211, 679679.61072749, 679682.334770195,
> 679682.016356632,
> 681870.417032469, 681833.431666185, 681835.819298651,
> 682169.045982226,
> 682481.102026817, 681898.903336465, 681815.124474645,
> 681767.856349565,
> 679683.60677096, 679679.512331425, 679685.090362144,
> 680056.806449304,
> 680669.183843293, 680574.455914651, 680135.313954264,
> 679377.580233857,
> 679962.24379583, 681449.590749334, 682487.75669767,
> 680411.258032117,
> 679696.668518938, 679693.528686564, 679772.603933245,
> 679773.633868724,
> 679736.151907987, 679052.282925451, 678976.337308103,
> 679033.29446238,
> 678931.539793955, 678958.703684971, 678946.400181795,
> 678850.167005458,
> 678773.910379499, 678698.286869888, 678670.305173271,
> 678919.107223046,
> 678849.346729342, 681189.259381922, 681760.407535151,
> 681703.846635682,
> 681398.684724269, 681404.573105136, 680342.303016419,
> 680154.993589284,
> 678462.168244616, 678391.786039819, 676898.732907242,
> 676001.82835349,
> 678008.813312216, 681769.954749672, 681759.207974324,
> 681507.518781024,
> 681593.03220131, 681540.302993985, 681484.948396701,
> 681473.096193411,
> 681472.290180181, 681495.69034936, 681435.364563687,
> 681447.201456387,
> 681484.561357977, 681486.557645373, 681560.45748688,
> 681569.439596909,
> 681563.610777719, 681588.547306751, 681569.219963467,
> 681513.790788761,
> 681152.416214584, 681081.49854309, 681135.953821302), utm.northing
> = c(5872351.4785664,
> 5872343.56503875, 5872346.22796992, 5872363.42149295,
> 5872353.8039064,
> 5872349.47411571, 5868340.77361732, 5868243.52829709,
> 5868235.77558357,
> 5868232.40916611, 5868253.49144986, 5868237.26716877,
> 5869057.86016266,
> 5869090.09085241, 5869056.34011199, 5869062.72910834,
> 5870701.37302118,
> 5874368.47157975, 5876177.09623027, 5878230.03361947,
> 5870680.9824509,
> 5870676.63887016, 5870979.35579, 5871339.76634507,
> 5873840.86397719,
> 5873841.23739579, 5873841.43141602, 5873842.6355962,
> 5873844.68392672,
> 5871046.00928802, 5870883.25601619, 5870971.63656481,
> 5870724.34128791,
> 5870884.41119196, 5871004.71015641, 5870912.68946024,
> 5871079.80253065,
> 5873839.88786636, 5873837.58571748, 5873842.99459642,
> 5871951.44683181,
> 5870220.93377831, 5870073.8804179, 5869500.17597069,
> 5868159.55631067,
> 5867142.10863469, 5870163.2230145, 5871573.15193546,
> 5873155.16709993,
> 5873906.4137855, 5873904.82657411, 5873914.76176622,
> 5873923.17474623,
> 5873499.82015583, 5872526.93430836, 5872245.66202465,
> 5872260.85296241,
> 5869177.40600652, 5869162.02197482, 5869085.16044548,
> 5868978.3021106,
> 5868905.01581302, 5868857.42295838, 5868902.29988844,
> 5868275.63384941,
> 5867353.8085983, 5868186.05946818, 5868896.81150499,
> 5869342.47718761,
> 5869161.06440822, 5868981.86688963, 5867817.37248634,
> 5867771.05004108,
> 5868056.05939298, 5868402.53585019, 5868159.41355345,
> 5868319.36565231,
> 5868603.79684903, 5869309.1656903, 5868948.79591208,
> 5869112.41864817,
> 5869300.35951534, 5869263.37159654, 5869176.9064542,
> 5869136.82566771,
> 5869116.05926684, 5869101.72778812, 5869055.03378991,
> 5869106.26144798,
> 5869151.08873567, 5869141.30813259, 5869115.13596271,
> 5868956.49020514,
> 5868937.08258008, 5869027.92636603, 5869132.38225557,
> 5869118.44574871,
> 5869157.45021195, 5869112.02210622, 5869153.69116562)), .Names =
> c("tag.local.identifier",
> "utm.easting", "utm.northing"), class = "data.frame", row.names =
> 362243:362342)
>
> ### projection
> utm32CRS <- CRS("+proj=utm +zone=32 +datum=WGS84")
> coordinates(spdf_proj) <- c("utm.easting", "utm.northing")
> proj4string(spdf_proj) <- utm32CRS
>
> ### CharHull
> spdf_CharHull <- CharHull(spdf_proj)
>
> ### Plotting
> plot(spdf_CharHull, percent=95)
> ### -> only one single outer polygon instead of wanted 95 % - area of
> the total CharHull-Polygons
>
> ### getting contours
> getverticeshr.MCHu(spdf_CharHull, percent=95)
> ### same problem as above
>
> ###end###
>
>
> -------- Originalnachricht --------
> Betreff: [R-sig-Geo] Problems with getting less than 100% home range
> area by CharHull{adehabitatHR}
> Datum: 10.12.2013 20:48
> Von: Simon Wohlfahrt <simonwohlfahrt at posteo.de>
> An: <r-sig-geo at r-project.org>
>
> Hello,
>
> I want to construct home ranges by the CharHull-function in
> adehabitatHR (CharHull {adehabitatHR} - Estimation of the Home Range by
> Delaunay Triangulation method).
>
> The Description says that I could "select a given percentage of the
> smallest triangles (measured by their area) as the home-range
> estimation".
> Now I want to select an home range with an area less than 100% of the
> total CharHull-Area, and finally plotting the contour or converting to a
> shape-file.
> But the command "getverticeshr()" doesn't result in 95 % homerange
> area, it only shows a single small polygon which is a part of the outer
> polygons of the total home range.
>
> So is there any argument like the "percent= ...." - command in the
> mcp()-function? The argument "percent=..." in plot() also result in
> these same single polygons.
>
> I hope, you can help me.
>
> For your information: I have a SpatialPointsDataFrame with one animal
> but more than 6000 points which I have transformed to CharHull -
> Polygons, a successfully but after this the unsolved problem have begun.
>
> Thank you!
>
> Simon
>
> simonwohlfahrt at posteo.de
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> .
>
--
Clément CALENGE
Cellule d'appui à l'analyse de données
Direction des Etudes et de la Recherche
Office national de la chasse et de la faune sauvage
Saint Benoist - 78610 Auffargis
tel. (33) 01.30.46.54.14
More information about the R-sig-Geo
mailing list