Here's another way to do it, I've used a slightly different grid that is
only 360 cells across. This won't work if the trip segments also cross the 0
longitude, but I'll have a go at something in trip to do that too.

Cheers, Mike.

library(sp)
library(trip)

## read track data
a <- read.table(file="79355.txt", h=T, sep="\t")
a$date <- as.POSIXct(strptime(as.character(a$date),"%d/%m/%Y %H:%M"), "GMT")
a$device_code <- as.factor(a$device_code)
a <- a[order(a$date), ]

## set up trip object
tr <- a
tr$longitude[tr$longitude < 0] <- tr$longitude[tr$longitude < 0] + 360
coordinates(tr) <- ~longitude+latitude
tr <- trip(tr, c("date", "device_code"))

## 0-360 grid
gt0360 <- GridTopology(c(0, -70), c(1, 1), c(360, 57))
grd <- tripGrid(tr, grid = gt0360)

## convert grid to -180/180 by indexing the x-coords and the grid
grd0 <- as.image.SpatialGridDataFrame(grd)
subX <- grd0$x > 180
grd0$x[subX] <- grd0$x[subX] - 360
grd0$x <- sort(grd0$x)
grd0$z <- rbind(grd0$z[subX,], grd0$z[!subX,])

## convert back to sp
grd <- image2Grid(grd0)



On Fri, Oct 1, 2010 at 12:38 PM, Michael Sumner <mdsumner@gmail.com> wrote:

> Thanks David, I'll investigate.
>
> Also, I've been thinking there's probably no real reason not to allow
> 2-location trips. ;)
>
> Cheers, Mike
>
> 2010/9/30 Pinaud David <pinaud@cebc.cnrs.fr>:
>  >  Hi Mike!
> > I've fixed my problem by running this (unelegant) code, with the same
> idea
> > as yours. I don't know if it's worth to include it in the trip package,
> but
> > here is the code! Feel free to adapt it and use it if you want.
> > I needed to change a little bit the trip class definition to convert a
> path
> > with two locations in a trip object. You set the limit at 3 locs when
> > defining a trip object, it makes sense that an interesting trip would
> have
> > more than 3 locs, but some colleagues here are working with dispersal of
> > individuals, calculating distance and bearing with 2 locs (birth / death
> or
> > birth/first reproduction place), so the package can be also usefull in
> this
> > case.
> > Thanks
> > David
> >
> > Le 09/09/2010 15:28, Michael Sumner a écrit :
> >>
> >> Sorry to have missed this.
> >>
> >> There's really no way to do this in longitude / latitude without a lot
> >> of manual handling. You could split into two trips, one using the
> >> eastern hemisphere, the other the western and use a shared [-180,180]
> >> grid that you sum together.
> >>
> >> What to do at the split coordinate depends on your actual data, there
> >> are many options.
> >>
> >> If you are still looking for an answer I could have a closer look at
> >> your example code, but real data would be more helpful if you can
> >> share it. There are a number of problems in the code you posted that
> >> prevent it from being easily run.
> >>
> >> Cheers, Mike.
> >>
> >>
> >>
> >>
> >> On Fri, Aug 6, 2010 at 8:10 PM, Pinaud David<pinaud@cebc.cnrs.fr>
>  wrote:
> >>>
> >>> Dear all,
> >>> I want to calculate a grid of time spent per cell with albatross data.
> >>> The
> >>> goal is then to relate this to fisheries data set on a 1x1° grid.
> >>> I use the trip package with tripGrid(), but have some problems with
> birds
> >>> crossing the date line.
> >>> Usually I use a projection to do that but here I need to keep the 1x1°
> >>> grid
> >>> in order to relate density tu some data (fisheries...).
> >>> I've tried with recenter() and nowrapSpatialLines(), without success.
> >>> Here a code:
> >>>
> >>> library(trip)
> >>> library(maps)   # to draw world maps
> >>>
> >>> d<- data.frame(x=c(seq(50, 180, 10), seq(-170, 50, 10)), y=rnorm(n=37,
> >>> m=-50, sd=3), tms=Sys.time()-(37:1*60*60*24), id=rep(1, 37))  # an
> >>> example
> >>> coordinates(d)<- ~x+y
> >>> tr<- trip(d, c("tms", "id"))
> >>> proj4string(at)<- CRS("+proj=longlat +ellps=WGS84")
> >>>
> >>> map('world')
> >>> plot(tr, add=T)
> >>> points(coordinates(tr), t="l")
> >>>
> >>> # grid
> >>> grid.base<- expand.grid(Long=seq(-180, 180, by=1), Lat=seq(-70, -15,
> >>> by=1))
> >>>   # tab coords
> >>> coordinates(grid.base)<- ~ Long + Lat
> >>> proj4string(grid.base)<- CRS("+proj=longlat +ellps=WGS84")
> >>> gt<- makeGridTopology(grid.base, cellsize = c(1, 1))  # def grid topo
> >>>
> >>> # time spent per cell
> >>> tppc<- tripGrid(tr, grid = gt)
> >>> tppc01<- tppc               # a copy for pres/abs
> >>> tppc01@data$z<- ifelse(tppc@data$z>  0, 1, 0)
> >>>
> >>> image(tppc, col=rev(heat.colors(500)))  # seems ok
> >>> map('world', add=T)
> >>> points(coordinates(tr), t="l")
> >>>
> >>> # but with presence/absence:
> >>> image(tppc01, col=c("white", "green"))
> >>> map('world', add=T)
> >>> points(coordinates(tr), t="l", col="blue")
> >>>
> >>> Some ideas ?
> >>>
> >>>
> >>> Many thanks for your time.
> >>> David
> >>>
> >>> --
> >>> ***************************************************
> >>> David PINAUD
> >>> Ingénieur de Recherche "Analyses spatiales"
> >>>
> >>> Centre d'Etudes Biologiques de Chizé - CNRS UPR1934
> >>> 79360 Villiers-en-Bois, France poste 485
> >>> Tel: +33 (0)5.49.09.35.58
> >>> Fax: +33 (0)5.49.09.65.26
> >>> http://www.cebc.cnrs.fr/
> >>>
> >>> ***************************************************
> >>>
> >>>
> >>>
> >>>
> >>> __________ Information from ESET Mail Security, version of virus
> >>> signature
> >>> database 5346 (20100806) __________
> >>>
> >>> The message was checked by ESET Mail Security.
> >>> http://www.eset.com
> >>>
> >>>
> >>> _______________________________________________
> >>> R-sig-ecology mailing list
> >>> R-sig-ecology@r-project.org
> >>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
> >>>
> >>>
> >>
> >>
> >
> > --
> > ***************************************************
> > David PINAUD
> > Ingénieur de Recherche "Analyses spatiales"
> >
> > Centre d'Etudes Biologiques de Chizé - CNRS UPR1934
> > 79360 Villiers-en-Bois, France
> > poste 485
> > Tel: +33 (0)5.49.09.35.58
> > Fax: +33 (0)5.49.09.65.26
> > http://www.cebc.cnrs.fr/
> >
> > ***************************************************
> >
> >
> >
> >
> > __________ Information from ESET Mail Security, version of virus
> signature
> > database 5492 (20100930) __________
> >
> > The message was checked by ESET Mail Security.
> > http://www.eset.com
> >
> >
>
>
>
>  --
> Michael Sumner
> Institute for Marine and Antarctic Studies, University of Tasmania
> Hobart, Australia
> e-mail: mdsumner@gmail.com
>



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner@gmail.com

	[[alternative HTML version deleted]]

