Skip to content

Commit

Permalink
version 1.5-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Calenge authored and gaborcsardi committed Jan 16, 2007
1 parent 9fc31f5 commit 214f358
Show file tree
Hide file tree
Showing 144 changed files with 10,429 additions and 8,632 deletions.
6 changes: 6 additions & 0 deletions CONTENTS
Expand Up @@ -360,6 +360,12 @@ Keywords: multivariate
Description: Habitat Suitability Maps Built from the ENFA
URL: ../../../library/habitat/html/predict.enfa.html

Entry: puech
Aliases: puech
Keywords: datasets
Description: Radio-Tracking Data of Wild Boars (2)
URL: ../../../library/habitat/html/puech.html

Entry: puechabon
Aliases: puechabon
Keywords: datasets
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: adehabitat
Version: 1.5-1
Date: 2006/10/30
Version: 1.5-2
Date: 2007/01/16
Title: Analysis of habitat selection by animals
Author: Clement Calenge, contributions from Mathieu Basille, Stephane Dray and Scott Fortmann-Roe
Maintainer: Clement Calenge <calenge@biomserv.univ-lyon1.fr>
Expand All @@ -9,4 +9,4 @@ Suggests: gpclib, sp, spatstat, MASS, tkrplot, shapefiles
Description: A collection of tools for the analysis of habitat selection by animals
Encoding: latin1
License: GPL version 2 or newer
Packaged: Mon Oct 30 10:08:16 2006; calenge
Packaged: Tue Jan 16 11:42:18 2007; calenge
1 change: 1 addition & 0 deletions INDEX
Expand Up @@ -86,6 +86,7 @@ plot.area Graphical Display of Objects of Class "area"
plot.ltraj Graphical Display of an Object of Class "ltraj"
plot.sahrlocs Exploratory Analysis of Habitat Selection
predict.enfa Habitat Suitability Maps Built from the ENFA
puech Radio-Tracking Data of Wild Boar (2)
puechabon Radio-Tracking Data of Wild Boar
puechcirc Movements of wild boars tracked at Puechabon
puechdesIII Habitat Selection by the Wild Boar at Puechabon
Expand Down
124 changes: 78 additions & 46 deletions R/angles.r
@@ -1,68 +1,100 @@
"angles" <-
function (x, id = levels(x$id), burst = levels(x$burst),
date = NULL, slsp = c("remove", "missing"))
{
"angles" <- function (x, id = levels(x$id), burst = levels(x$burst),
date = NULL, slsp = c("remove", "missing"))
{
## The function is deprecated
.Deprecated("as.ltraj")

## Verifications
if (!inherits(x, "traj"))
stop("x should be of class \"traj\"")
stop("x should be of class \"traj\"")
slsp <- match.arg(slsp)


## prepangles is used to remove successive relocations
## located at the same place
prepangles <- function(x)
{
{
## Verifications
if (!inherits(x, "traj"))
stop("x should be of class \"traj\"")
stop("x should be of class \"traj\"")

## split per burst
li <- split(x, x$burst)

## keeps only the successive relocations at different places
foo <- function(y) {
oo <- unlist(lapply(2:nrow(y),
function(i) (!all(y[i,c("x","y")]==y[i-1,c("x","y")]))))
oo <- c(TRUE,oo)
y <- y[oo,]
oo <- unlist(lapply(2:nrow(y),
function(i)
(!all(y[i,c("x","y")]==y[i-1,c("x","y")]))))
oo <- c(TRUE,oo)
y <- y[oo,]
}

## output
res <- do.call("rbind", lapply(li, foo))
return(res)
}
}

## gets the selected bursts
x <- getburst(x, burst = burst, id = id, date = date)

## if the angles are to be removed when successive relocations are
## on the same place
if (slsp=="remove")
x <- prepangles(x)
x <- prepangles(x)

## split per burst
li <- split(x, x$burst)

## To compute the angles
foo <- function(x) {
xy<-as.matrix(x[,c("x","y")])
ang<-1:(nrow(xy)-2)
for (i in 2:(nrow(xy)-1)) {
na <- 0
ref1<-xy[i-1,]
xyb1<-t(t(xy)-ref1)
ang1<--atan2(xyb1[i,2],xyb1[i,1])

## calcul de la position de x2 et x3 rotaté
x2<-c(sqrt(sum(xyb1[i,]^2)), 0)
if (sum(abs(x2)) < 1e-7)
na<-1
x3b<-x3<-xyb1[i+1,]
x3b[1]= cos(ang1)*x3[1] - sin(ang1)*x3[2]
x3b[2]= sin(ang1)*x3[1] + cos(ang1)*x3[2]
x3<-x3b

## et recalcul de l'angle
x3<-x3-x2
if (sum(abs(x3)) < 1e-7)
na<-1
ang[i-1]<-atan2(x3[2],x3[1])
if (na > 0.5)
if (slsp == "missing")
ang[i - 1] <- NA
}
so<-data.frame(id=x$id[-c(1,nrow(xy))],
x=xy[-c(1,nrow(xy)),1],
y=xy[-c(1,nrow(xy)),2],
date=x$date[-c(1,nrow(xy))],
burst=x$burst[-c(1,nrow(xy))],
angles=ang)

## gets the coordinates
xy<-as.matrix(x[,c("x","y")])
ang<-1:(nrow(xy)-2)


for (i in 2:(nrow(xy)-1)) {

## current relocation, with the previous one
na <- 0
ref1<-xy[i-1,]

## the origin of the space is placed on the previous reloc
xyb1<-t(t(xy)-ref1)
ang1<--atan2(xyb1[i,2],xyb1[i,1])

## Position of rotated x2 and x3
x2<-c(sqrt(sum(xyb1[i,]^2)), 0)
if (sum(abs(x2)) < 1e-7)
na<-1
x3b<-x3<-xyb1[i+1,]
x3b[1]= cos(ang1)*x3[1] - sin(ang1)*x3[2]
x3b[2]= sin(ang1)*x3[1] + cos(ang1)*x3[2]
x3<-x3b

## Computation of the angles
x3<-x3-x2
if (sum(abs(x3)) < 1e-7)
na<-1
ang[i-1]<-atan2(x3[2],x3[1])
if (na > 0.5)
if (slsp == "missing")
ang[i - 1] <- NA
}

## output
so<-data.frame(id=x$id[-c(1,nrow(xy))],
x=xy[-c(1,nrow(xy)),1],
y=xy[-c(1,nrow(xy)),2],
date=x$date[-c(1,nrow(xy))],
burst=x$burst[-c(1,nrow(xy))],
angles=ang)
}

## output
lo <- do.call("rbind", lapply(li, foo))
row.names(lo) <- 1:nrow(lo)
return(lo)
}
}

34 changes: 20 additions & 14 deletions R/ararea.r
@@ -1,17 +1,23 @@
"ararea" <-
function(x)
"ararea" <- function(x)
{
if (!inherits(x, "area"))
stop("x should be of class \"area\"")
if (!require(gpclib))
stop("package gpclib needed for this function")
uu <- split(x[,2:3], x[,1])
foo <- function(y) {
class(y) <- "data.frame"
u <- area.poly(as(y, "gpc.poly"))
}
res <- unlist(lapply(uu, foo))
names(res) <- names(uu)
return(res)
## Verifications
if (!inherits(x, "area"))
stop("x should be of class \"area\"")

## package gpclib needed
if (!require(gpclib))
stop("package gpclib needed for this function")

## Computes the area of each polygon
uu <- split(x[,2:3], x[,1])
foo <- function(y) {
class(y) <- "data.frame"
u <- area.poly(as(y, "gpc.poly"))
}

## Output
res <- unlist(lapply(uu, foo))
names(res) <- names(uu)
return(res)
}

31 changes: 16 additions & 15 deletions R/area2dxf.r
@@ -1,23 +1,22 @@
"area2dxf" <-
function(x, file, lay=1:nlevels(factor(x[,1])))
{
## vérification du format du fichier
"area2dxf" <- function(x, file, lay=1:nlevels(factor(x[,1])))
{
## Verifications of file format
if (!inherits(x, "area"))
stop("x should be of class area")
stop("x should be of class area")
if (substr(file, nchar(file)-3, nchar(file))!=".dxf")
file<-paste(file, ".dxf", sep="")
file<-paste(file, ".dxf", sep="")

## Vérification que le premier et le dernier point de chaque polygone
## sont identiques. Sinon modifier de fichier de façon ad hoc
## Verifications that the polygons are closed (identical first
## and last point for all polygons)
lipol<-split(x, x[,1])
for (i in 1:length(lipol)) {
j<-lipol[[i]]
if (!all(j[1,]==j[nrow(j),]))
lipol[[i]]<-rbind.data.frame(lipol[[i]], lipol[[i]][1,])
j<-lipol[[i]]
if (!all(j[1,]==j[nrow(j),]))
lipol[[i]]<-rbind.data.frame(lipol[[i]], lipol[[i]][1,])
}
x<-do.call("rbind.data.frame",lipol)
## header

## header of file
text<-" 0\nSECTION\n 2\nHEADER\n 9\n$EXTMIN\n 10\n"
text<-paste(text, min(x[,2]),"\n", sep="")
text<-paste(text, " 20\n", sep="")
Expand All @@ -30,8 +29,8 @@ function(x, file, lay=1:nlevels(factor(x[,1])))
text<-paste(text, "2\nTABLES\n 0\nENDSEC\n 0\n", sep="")
text<-paste(text, "SECTION\n 2\nBLOCKS\n 0\n", sep="")
text<-paste(text, "ENDSEC\n 0\nSECTION\n 2\nENTITIES\n", sep="")
## création du corps du fichier: boucle

## The main part of the file
lp<-split(x[,2:3], x[,1])
for (i in 1:length(lp)) {
text<-paste(text, " 0\nPOLYLINE\n 8\n", sep="")
Expand All @@ -43,6 +42,8 @@ function(x, file, lay=1:nlevels(factor(x[,1])))
text<-paste(text, " 0\nSEQEND\n")
}
text<-paste(text, " 0\nENDSEC\n 0\nEOF\n")

## write the file
cat(text, file=file)
}

35 changes: 23 additions & 12 deletions R/area2spol.r
@@ -1,21 +1,32 @@
"area2spol" <-
function(ar)
{
"area2spol" <- function(ar)
{
## Verifications
if (!inherits(ar, "area"))
stop("ka should be of class \"area\"")
stop("ka should be of class \"area\"")

## sp needed
if (!require(sp))
stop("the package sp is required for this function")
stop("the package sp is required for this function")

## splits ar into a list where each element is a polygon
class(ar) <- "data.frame"
li <- split(ar[,2:3],ar[,1])

## stores the elements as SpatialPolygons
res <- lapply(li, function(x) {
if (!all(unlist(x[1,]==x[nrow(x),])))
x <- rbind(x,x[1,])
x <- as.matrix(x)
y <- Polygon(x, hole=FALSE)
if (y@ringDir<0)
y <- Polygon(x[nrow(x):1,], hole=FALSE)
return(y)

## Verification that the polygon is closed
if (!all(unlist(x[1,]==x[nrow(x),])))
x <- rbind(x,x[1,])

## converts as spol
x <- as.matrix(x)
y <- Polygon(x, hole=FALSE)
if (y@ringDir<0)
y <- Polygon(x[nrow(x):1,], hole=FALSE)
return(y)
})
## The output
resb <- SpatialPolygons(lapply(1:length(res),
function(i) Polygons(list(res[[i]]),
names(res)[i])))
Expand Down
14 changes: 8 additions & 6 deletions R/as.area.r
@@ -1,12 +1,14 @@
"as.area" <-
function(x)
{
"as.area" <- function(x)
{
## Verifications
if (!inherits(x, "data.frame"))
stop("x should be of class \"data.frame\"")
stop("x should be of class \"data.frame\"")
if (ncol(x) != 3)
stop("x should have three columns")
stop("x should have three columns")
## ID is again transormed into a factor
if (!is.factor(x[,1]))
x<-factor(x[,1])
x[,1] <-factor(x[,1])
## The class
class(x)<-c("area", "data.frame")
return(x)
}
Expand Down
13 changes: 9 additions & 4 deletions R/as.asc.r
@@ -1,10 +1,13 @@
"as.asc" <-
function(x, xll=1, yll=1, cellsize=1, type=c("numeric", "factor"),
lev=levels(factor(x)))
{
"as.asc" <- function(x, xll=1, yll=1, cellsize=1,
type=c("numeric", "factor"),
lev=levels(factor(x)))
{
## Verifications
type<-match.arg(type)
if (!inherits(x, "matrix"))
stop("x should be a matrix")

## creates the attributes
mode(x)<-"numeric"
attr(x, "xll")<-xll
attr(x, "yll")<-yll
Expand All @@ -13,6 +16,8 @@ function(x, xll=1, yll=1, cellsize=1, type=c("numeric", "factor"),
if (type=="factor")
attr(x, "levels")<-lev
class(x)<-"asc"

## Output
return(x)
}

0 comments on commit 214f358

Please sign in to comment.