kasc2spixdf {adehabitat} | R Documentation

## Conversion of maps from/to the package "sp"

### Description

These functions convert maps of classes available in adehabitat toward classes available in the package `sp` and conversely.
`kasc2spixdf` converts an object of class `kasc` into an object of class `SpatialPixelsDataFrame`.
`asc2spixdf` converts an object of class `asc` into an object of class `SpatialGridDataFrame`.
`spixdf2kasc` converts an object of class `SpatialPixelsDataFrame` or `SpatialGridDataFrame` into an object of class `asc` or `kasc`.
`area2spol` converts an object of class `area` into an object of class `SpatialPolygons`.
`spol2area` converts an object of class `SpatialPolygons` or `SpatialPolygonsDataFrame` into anobject of class `area`.
`attpol2area` gets the data attribute of an object of class `SpatialPolygonsDataFrame` and stores is into a data frame.
`traj2spdf` converts an object of class `traj` into an object of class `SpatialPointsDataFrame`.
`traj2sldf` converts an object of class `traj` into an object of class `SpatialLinesDataFrame`.

### Usage

    kasc2spixdf(ka)
    asc2spixdf(a)
    spixdf2kasc(sg)
    area2spol(ar)
    spol2area(sr)
    attpol2area(srdf)
    traj2spdf(tr)
    traj2sldf(tr, byid = FALSE)

### Arguments

`ka` | an object of class `kasc`.
`a` | an object of class `asc`.
`sg` | an object of class `SpatialPixelsDataFrame` or `SpatialGridDataFrame`.
`ar` | an object of class `area`.
`sr` | an object of class `SpatialPolygons` or `SpatialPolygonsDataFrame`.
`srdf` | an object of class `SpatialPolygonsDataFrame`.
`tr` | an object of class `traj`.
`byid` | logical. If `TRUE`, one objects of class `Lines` correspond to one animal. if `FALSE`, one object of class `Lines` correspond to one burst.

### Details

We describe here more in detail the functions `spol2area` and `attpol2area`. Objects of class `area` do not deal with holes in the polygons, whereas the objects of class `SpatialPolygons` do. Therefore, when holes are present in the `SpatialPolygons` object passed as argument, the function `spol2area` ignore them and returns only the external contour of the polygon (though a warning is returned).

### Author(s)

Clément Calenge calenge@biomserv.univ-lyon1.fr

### See Also

`import.asc` for information on objects of class `asc`, `as.kasc` for info on objects of class `kasc`, `as.area` for info on objects of class `area`, `as.traj` for objects of class `traj`.

### Examples

    ## Not run:
    if (require(sp)) {

    #########################################
    ##
    ## Conversion kasc -> SpatialPixelsDataFrame
    ##

    data(puechabon)
    toto <- kasc2spixdf(puechabon$kasc)
    image(toto)
    summary(toto)

    #### and conversely
    toto <- spixdf2kasc(toto)
    image(toto)
    hist(toto)

    data(meuse.grid)
    m <- SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")],
                               data = meuse.grid)
    i <- spixdf2kasc(m)
    image(i)

    ### conversion asc -> SpatialPixelsDataFrame
    cuicui <- asc2spixdf(getkasc(toto,1))
    image(cuicui)

    #########################################
    ##
    ## Conversion area -> SpatialRings
    ##

    data(elec88)
    ar <- as.area(elec88$area)
    plot(ar)
    toto <- area2spol(ar)
    plot(toto)

    #########################################
    ##
    ## Conversion SpatialRings -> area
    ##

    ## First create an object of class "SpatialRingsDataFrame"
    tutu <- SpatialPolygonsDataFrame(toto, elec88$tab)

    ## and then conversion:
    coincoin <- spol2area(tutu)

    plot(coincoin)
    ## gets the attributes
    haha <- attpol2area(tutu)
    area.plot(coincoin, values = haha$Waechter)

    #########################################
    ##
    ## Conversion traj -> SpatialPointsDataFrame
    ##

    data(puechcirc)
    plot(puechcirc)

    toto <- traj2spdf(puechcirc)
    plot(toto)

    #########################################
    ##
    ## Conversion traj -> SpatialLinesDataFrame
    ##

    data(puechcirc)
    plot(puechcirc)

    toto <- traj2sldf(puechcirc)
    plot(toto)

    }
    ## End(Not run)

[Package adehabitat version 1.4 Index]