Skip to content

trip/time-spent approach #6

@mdsumner

Description

@mdsumner
library(trip)
tr <- ...

## overall extent for trip
r <- raster::raster(spex::buffer_extent(tr, 1), res = 0.1, crs = raster::projection(tr))

## turn into line segments, with timedur on each
lines <- explode(tr)
cells <- tabularaster::cellnumbers(r, lines)

library(dplyr)
## now cells has object_ (the line segment), and cell_ (the pixel index)
## copy on timedur and id and starttime
cells <- cells %>% mutate(starttime = lines$starttime[object_], 
                          timedur = lines$timedur[object_], 
                          id = lines$id[object_])

## we have to distribute the timedur evenly across each cell (it's close enough)
cells <- cells %>% group_by(object_) %>% mutate(timedur = timedur / n()) %>% ungroup()
## we can get the lon/lat from the raster
cells <- cells %>% mutate(lon = raster::xFromCell(r, cell_), lat = raster::yFromCell(r, cell_))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions