r - Assigning location values based on date and time of a second data set -


i have 2 data frames: 1 sequence of gps locations associated date-times (posixct)

gps <- data.frame(lat=c(58.65209, 58.65183, 58.65142, 58.65129, 58.65126, 58.65124, 58.65122, 58.65119, 58.65117, 58.65115),                   lon=c(-3.178559, -3.177934, -3.177277, -3.177536, -3.177494, -3.177713, -3.177806, -3.177899, -3.177991, -3.178084),                    datetime=c("2016-10-01 16:23:59 gmt", "2016-10-01 16:31:59 gmt", "2016-10-01 16:39:59 gmt", "2016-10-01 16:47:59 gmt", "2016-10-01 16:55:59 gmt", "2016-10-01 17:03:59 gmt", "2016-10-01 17:11:59 gmt", "2016-10-01 17:19:59 gmt", "2016-10-01 17:27:59 gmt", "2016-10-01 17:35:59 gmt"))  gps$datetime <- as.posixct(as.character(gps$datetime)) 

and sequence of depths associated date-times (posixct).

depth <- data.frame(depth=c(0.0, 0.1, 0.0, 0.0, 0.1, 1.5, 1.7, 1.7, 1.4, 1.5, 1.8, 2.1, 2.3, 1.7, 2.0, 2.6, 2.2, 2.1, 3.4, 3.3),                      datetime=c("2016-10-01 16:22:56 gmt", "2016-10-01 16:23:06 gmt", "2016-10-01 16:23:16 gmt", "2016-10-01 16:23:59 gmt", "2016-10-01 16:24:52 gmt", "2016-10-01 16:25:24 gmt", "2016-10-01 16:32:40 gmt", "2016-10-01 16:32:51 gmt", "2016-10-01 18:45:30 gmt", "2016-10-01 18:45:40 gmt", "2016-10-01 18:46:54 gmt", "2016-10-01 18:47:04 gmt", "2016-10-01 18:47:14 gmt", "2016-10-01 18:47:25 gmt", "2016-10-01 18:51:03 gmt", "2016-10-01 18:51:14 gmt", "2016-10-01 18:51:24 gmt", "2016-10-01 18:54:11 gmt", "2016-10-01 18:54:21 gmt", "2016-10-01 18:54:32 gmt"))  depth$datetime <- as.posixct(as.character(depth$datetime)) 

for each depth location want assign location (latitude , longitude) based on when interpolated track location data frame suggests should i.e. if locations go point point b @ point along line depth data lie, assuming uniform speed between points, given it's date-time.

the final product 2 vectors in data-frame assign each depth value latitude , longitude.

thank you.

assuming constant velocity (uniform speed and constant direction) between successive way-points in gps data, can perform linear interpolation separately lat , lon using approx stats:

depth$lat <- approx(x=gps$datetime, y=gps$lat, xout=depth$datetime, method="linear")$y depth$lon <- approx(x=gps$datetime, y=gps$lon, xout=depth$datetime, method="linear")$y 

in usage, interpolated values datetime in depth outside of range of datetime in gps assigned na. see ?approx other ways dealing interpolating outside range of input.

using data, result is:

print(depth) ##   depth            datetime      lat       lon ##1    0.0 2016-10-01 16:22:56       na        na ##2    0.1 2016-10-01 16:23:06       na        na ##3    0.0 2016-10-01 16:23:16       na        na ##4    0.0 2016-10-01 16:23:59 58.65209 -3.178559 ##5    0.1 2016-10-01 16:24:52 58.65206 -3.178490 ##6    1.5 2016-10-01 16:25:24 58.65204 -3.178448 ##7    1.7 2016-10-01 16:32:40 58.65179 -3.177878 ##8    1.7 2016-10-01 16:32:51 58.65179 -3.177863 ##9    1.4 2016-10-01 18:45:30       na        na ##10   1.5 2016-10-01 18:45:40       na        na ##11   1.8 2016-10-01 18:46:54       na        na ##12   2.1 2016-10-01 18:47:04       na        na ##13   2.3 2016-10-01 18:47:14       na        na ##14   1.7 2016-10-01 18:47:25       na        na ##15   2.0 2016-10-01 18:51:03       na        na ##16   2.6 2016-10-01 18:51:14       na        na ##17   2.2 2016-10-01 18:51:24       na        na ##18   2.1 2016-10-01 18:54:11       na        na ##19   3.4 2016-10-01 18:54:21       na        na ##20   3.3 2016-10-01 18:54:32       na        na 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -