##Ellipse=group
##Layer=vector
##Field=Field Layer
##stdv= number 0.5
##Car_shape = output vector
##weighted=boolean True.
# stdv : choix de la valeur normale ou intervalle de confiance (de 0 à 1)
# weighted pondéré par le champs Field ou non pondéré
library(car)
coords<-coordinates(Layer)
weights=Layer[[Field]]
if(weighted) {
sa = dataEllipse(coords, levels=c(stdv), weights=weights,segments = 100, draw = FALSE)
}else {
sa = dataEllipse(coords, levels=c(stdv),segments = 100, draw = FALSE)
}
sp = SpatialPolygons( list( Polygons(list(Polygon(sa)), 1)))
sp.df <- data.frame( ID=1:length(sp))
res = SpatialPolygonsDataFrame(sp,sp.df)
proj4string(res) <- Layer@proj4string
Car_shape<-res