Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trip/time-spent approach #6

Open
mdsumner opened this issue Jan 23, 2019 · 0 comments
Open

trip/time-spent approach #6

mdsumner opened this issue Jan 23, 2019 · 0 comments

Comments

@mdsumner
Copy link
Member

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_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant