Skip to content

Instantly share code, notes, and snippets.

@romunov
Created June 7, 2017 09:05
Show Gist options
  • Save romunov/93e42a05c2d5112b8e7fa8bd12ebb670 to your computer and use it in GitHub Desktop.
Save romunov/93e42a05c2d5112b8e7fa8bd12ebb670 to your computer and use it in GitHub Desktop.
gist for daniel
xy <- read.table(text = "date | lon | lat | trip | distancetocoast
2014-06-11 19:02:00 | -58,3508585 | -51,88438373 | 1 | 2236.067977
2014-06-12 01:02:00 | -58,35589725 | -51,88349529 | 1 | 1000
2014-06-12 13:02:00 | -58,27224941 | -51,91903677 | 1 | 7211,102551
2014-06-12 19:02:00 | -58,27974654 | -51,90535003 | 1 | 5830,951895
2014-06-13 01:02:00 | -58,32331901 | -51,89410464 | 1 | 3605,551275
2014-06-13 07:02:00 | -58,35833139 | -51,88809227 | 1 | 1414,213562
2014-06-13 13:02:00 | -58,35617673 | -51,88156281 | 1 | 1000
2014-06-13 19:02:00 | -58,34055711 | -51,89002367 | 1 | 2236,067977
2014-06-14 01:02:00 | -58,34982536 | -51,8715761 | 2 | 1000
2014-06-14 13:02:00 | -58,3073814 | -51,92722937 | 2 | 7071,067812
2014-06-14 19:02:00 | -58,34581314 | -51,86761133 | 3 | 1000
2014-06-15 01:02:00 | -58,34050624 | -51,88382088 | 3 | 1414,213562
2014-06-15 13:02:00 | -58,2974691 | -51,91795326 | 3 | 6324,55532
2014-06-15 19:02:00 | -58,19881901 | -51,95172233 | 3 | 13000
2014-06-16 01:02:00 | -58,1348416 | -51,98673766 | 3 | 18788,29423
2014-06-16 07:02:00 | -57,99399544 | -52,06988191 | 3 | 28861,73938
2014-06-16 13:02:00 | -58,00469754 | -52,02795069 | 3 | 26627,05391
2014-06-16 19:02:00 | -57,92758675 | -52,02184666 | 3 | 29000
2014-06-17 01:02:00 | -57,91658235 | -51,99748699 | 3 | 28284,27125
2014-06-17 07:02:00 | -57,77015528 | -51,99031797 | 3 | 30805,8436
2014-06-17 13:02:00 | -57,99601712 | -51,91519551 | 3 | 17804,49381
2014-06-17 19:02:00 | -58,06820013 | -51,92972737 | 3 | 14866,06875
2014-06-18 01:02:00 | -58,19845185 | -51,89522513 | 3 | 7615,773106
2014-06-18 07:02:00 | -58,35241361 | -51,88015998 | 3 | 1000
2014-06-18 13:02:00 | -58,35603546 | -51,88336878 | 3 | 1000
2014-06-18 19:02:00 | -58,33350332 | -51,87308427 | 3 | 1000
2014-06-19 01:02:00 | -58,33839581 | -51,87846631 | 3 | 1414,213562
2014-06-19 07:02:00 | -58,42661519 | -51,80902388 | 4 | 0
2014-06-19 13:02:00 | -58,30461883 | -51,93745837 | 4 | 7810,249676
2014-06-19 19:02:00 | -58,18362875 | -51,96475914 | 4 | 14317,82106",
header = TRUE, sep = "|", dec = ",")
head(xy)
library(zoo)
library(sp)
# for only trip 1, to be generalized
k <- xs[[1]]
rollapply(data = 1:nrow(k), width = 2, FUN = function(x, k) {
k <- k[x, ]
pts <- SpatialPoints(k[, c("lon", "lat")])
max(spDists(pts, longlat = TRUE))
}, k = k)
@dgp89
Copy link

dgp89 commented Jun 7, 2017

Hi @romunov, I am trying to addapt the code but still can´t make it work
I have done this:

library(zoo) library(sp) k <- p.1[[1]] rollapply(data = 1:767, width = 2, FUN = function(x, k) { k <- k[x, ] pts <- SpatialPoints(p.1[, c("lon", "lat")]) max(spDists(pts, longlat = TRUE)) }, k = k)

I try to attach here part of the excel

https://www.dropbox.com/s/buon3e5oarh7dxm/p1.xlsx?dl=0
https://drive.google.com/drive/folders/0B7mltLkUahnQM0RjMDRkOGFDc0U?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment