将 GPS 信息提取到 "steady" 和 "Moving"
Extract GPS information to "steady" and "Moving"
我有关于 GPS 数据的问题。
我的数据看起来像
问题是,我想从该数据中提取信息到 value3,我想用 "steady" 和 "moving" 填充 value3。
根据纬度和经度的值稳定和移动,但我仍然感到困惑,因为当我试图绘制时。
示例:
35.1754255,126.9130674
35.1754281,126.9130184
35.1754225,126.9130536
35.1807405,126.9055772
剧情结果:
Values 1 ~ 3 正在移动,但只是很少移动,所以可能 value3 会被 "steady"、"short moving"、"long moving" 填充,但我仍然没有了解用于定义短和长的阈值。
我的第二个问题是如何使用 R 代码生成 value3。其实我可以比较下一个值和当前值,如果不同则表示移动,如果不是则表示稳定,但我仍然对短移动和长移动感到困惑。
我的数据中 dput() 的输出
> dput(loc)
structure(list(time = c("2014-06-30 08:26:36", "2014-06-30 08:31:30",
"2014-06-30 08:36:30", "2014-06-30 08:41:30", "2014-06-30 08:46:30",
"2014-06-30 08:51:30", "2014-06-30 08:56:31", "2014-06-30 09:01:30",
"2014-06-30 09:06:30", "2014-06-30 09:11:30", "2014-06-30 09:16:30",
"2014-06-30 09:21:30", "2014-06-30 09:26:30", "2014-06-30 09:31:30",
"2014-06-30 09:36:30", "2014-06-30 09:41:30", "2014-06-30 09:46:30",
"2014-06-30 09:51:52", "2014-06-30 09:56:30", "2014-06-30 10:01:30",
"2014-06-30 10:06:53", "2014-06-30 10:11:30", "2014-06-30 10:16:52",
"2014-06-30 10:21:30", "2014-06-30 10:26:30", "2014-06-30 10:31:30",
"2014-06-30 10:36:51", "2014-06-30 10:41:30", "2014-06-30 10:46:54",
"2014-06-30 10:51:51", "2014-06-30 10:57:30", "2014-06-30 11:01:51",
"2014-06-30 11:06:30", "2014-06-30 11:11:51", "2014-06-30 11:16:30",
"2014-06-30 11:21:51", "2014-06-30 11:26:30", "2014-06-30 11:31:30",
"2014-06-30 11:36:52", "2014-06-30 11:41:30", "2014-06-30 11:46:51",
"2014-06-30 11:51:30", "2014-06-30 11:56:53", "2014-06-30 12:01:32",
"2014-06-30 12:07:30", "2014-06-30 12:11:51", "2014-06-30 12:16:33",
"2014-06-30 12:21:30", "2014-06-30 12:26:30", "2014-06-30 12:31:51",
"2014-06-30 12:36:30", "2014-06-30 12:41:36", "2014-06-30 12:46:30",
"2014-06-30 12:52:10", "2014-06-30 12:56:30", "2014-06-30 13:01:30",
"2014-06-30 13:06:30", "2014-06-30 13:11:30", "2014-06-30 13:16:30",
"2014-06-30 13:21:30", "2014-06-30 13:26:30", "2014-06-30 13:31:30",
"2014-06-30 13:36:30", "2014-06-30 13:41:30", "2014-06-30 13:46:30",
"2014-06-30 13:51:30", "2014-06-30 13:56:30", "2014-06-30 14:01:30",
"2014-06-30 14:06:55", "2014-06-30 14:11:19", "2014-06-30 14:16:19",
"2014-06-30 14:21:19", "2014-06-30 14:26:19", "2014-06-30 14:31:19",
"2014-06-30 14:36:19", "2014-06-30 14:41:19", "2014-06-30 14:46:19",
"2014-06-30 14:51:19", "2014-06-30 14:56:19", "2014-06-30 15:01:19",
"2014-06-30 15:06:19", "2014-06-30 15:11:19", "2014-06-30 15:16:19",
"2014-06-30 15:21:19", "2014-06-30 15:26:19", "2014-06-30 15:31:19",
"2014-06-30 15:36:19", "2014-06-30 15:41:19", "2014-06-30 15:46:19",
"2014-06-30 15:51:19", "2014-06-30 15:56:19", "2014-06-30 16:01:19",
"2014-06-30 16:06:19", "2014-06-30 16:11:19", "2014-06-30 16:16:20",
"2014-06-30 16:21:19", "2014-06-30 16:26:19", "2014-06-30 16:31:19",
"2014-06-30 16:36:19", "2014-06-30 16:41:19"), type = c("location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location"), value1 = c("35.1754255",
"35.1754281", "35.1754225", "35.1753982", "35.1753991", "35.1753997",
"35.1754333", "35.1754143", "35.1754126", "35.1754142", "35.1753987",
"35.1754178", "35.1754176", "35.1753914", "35.1754066", "35.1753833",
"35.1753883", "35.174465", "35.174465", "35.1735813", "35.1744781",
"35.1735813", "35.174502", "35.1749091", "35.1749091", "35.1749091",
"35.1744991", "35.1749091", "35.1751931", "35.1748972", "35.1755879",
"35.1759928", "35.1759928", "35.1763946", "35.1763946", "35.1763882",
"35.1763882", "35.1762131", "35.1760547", "35.1760547", "35.1774352",
"35.1774352", "35.1785821", "35.1785821", "35.1773562", "35.1807058",
"35.1807058", "35.1813436", "35.1802903", "35.1807615", "35.1807615",
"35.1807405", "35.1807405", "35.1805536", "35.1805536", "35.1808169",
"35.1797636", "35.1836812", "35.1836812", "35.1897643", "35.1898214",
"35.1897615", "35.1897765", "35.1897157", "35.1896921", "35.1897299",
"35.18975", "35.1897503", "35.1897673", "35.1897539", "35.1897932",
"35.1897702", "35.1897627", "35.189763", "35.1897438", "35.1898021",
"35.1897853", "35.1897405", "35.1897803", "35.1897844", "35.1897624",
"35.1897769", "35.1897656", "35.1897265", "35.1897488", "35.1897599",
"35.1897477", "35.1897951", "35.189759", "35.1897624", "35.1897692",
"35.1898468", "35.1897727", "35.1897624", "35.1897958", "35.189817",
"35.1897391", "35.1897317", "35.189745", "35.1897624"), value2 = c("126.9130674",
"126.9130184", "126.9130536", "126.9130597", "126.9130549", "126.9130598",
"126.9130484", "126.9130638", "126.9130687", "126.9130553", "126.913074",
"126.9130686", "126.9130779", "126.9130496", "126.9130196", "126.9130507",
"126.9130474", "126.9135807", "126.9135807", "126.9119189", "126.9137426",
"126.9119189", "126.9137499", "126.9124954", "126.9124954", "126.9124954",
"126.9137861", "126.9124954", "126.9142743", "126.9118689", "126.912267",
"126.9131502", "126.9131502", "126.9130495", "126.9130495", "126.9131069",
"126.9131069", "126.911819", "126.9121906", "126.9121906", "126.9123621",
"126.9123621", "126.9093961", "126.9093961", "126.9041179", "126.9055765",
"126.9055765", "126.904599", "126.9054961", "126.905568", "126.905568",
"126.9055772", "126.9055772", "126.9052718", "126.9052718", "126.9050475",
"126.9059447", "126.9052348", "126.9052348", "126.9063181", "126.9062802",
"126.9063452", "126.9064237", "126.9065031", "126.9065168", "126.9063599",
"126.9064195", "126.9064469", "126.9063441", "126.9063828", "126.9064423",
"126.9063459", "126.9063602", "126.9063096", "126.9063355", "126.9063742",
"126.9063253", "126.9063123", "126.9063434", "126.9063729", "126.906397",
"126.9063288", "126.906282", "126.9062903", "126.9063502", "126.9063432",
"126.9063004", "126.9063742", "126.9063343", "126.9063969", "126.9062847",
"126.9063212", "126.9063034", "126.9063969", "126.9063237", "126.906375",
"126.9063572", "126.9063514", "126.9062548", "126.906397"), value3 = c("",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "")), .Names = c("time", "type", "value1", "value2",
"value3"), row.names = c(NA, 100L), class = "data.frame")
这是我的尝试。正如我在上面的评论中提到的,您想自己定义 "short movement" 和 "long movement" 。例如,在 R 中,您可以在 dplyr
包中使用 lag()
并计算移动。我可能错了,但是 1 度大约是 111.32 公里。所以 0.0001 度大约是 11 米。在这次尝试中,如果这个人在经纬度上移动超过11米且小于55米,我认为移动"little movement"。任何更长的移动都被视为 "long movement"。由于我不是gis专业人士,所以我的做法可能不合适。但是,我希望这能给你一些你想要做什么的想法。
P.S。如果您有大量数据,ifelse()
会减慢处理速度。您想考虑使用 data.table
包。
# Note: 1 degree = 111.32 km
#0.0001 degree 11.1132 m
# Convert character to numeric
mydf$value1 <- as.numeric(mydf$value1)
mydf$value2 <- as.numeric(mydf$value2)
library(dplyr)
select(mydf, -type, -value3) %>%
mutate(movement = ifelse(value1 == lag(value1) & value2 == lag(value2), "same",
ifelse(between(abs(value1 - lag(value1)), 0.0001, 0.0005) == TRUE &
between(abs(value2 - lag(value2)), 0.0001, 0.0005) == TRUE, "little", "long")))
# A part of the outcome
#33 2014-06-30 11:06:30 35.175993 126.91315 same
#34 2014-06-30 11:11:51 35.176395 126.91305 little
#35 2014-06-30 11:16:30 35.176395 126.91305 same
#36 2014-06-30 11:21:51 35.176388 126.91311 long
#37 2014-06-30 11:26:30 35.176388 126.91311 same
#38 2014-06-30 11:31:30 35.176213 126.91182 long
#39 2014-06-30 11:36:52 35.176055 126.91219 little
#40 2014-06-30 11:41:30 35.176055 126.91219 same
#41 2014-06-30 11:46:51 35.177435 126.91236 long
#42 2014-06-30 11:51:30 35.177435 126.91236 same
我有关于 GPS 数据的问题。 我的数据看起来像
问题是,我想从该数据中提取信息到 value3,我想用 "steady" 和 "moving" 填充 value3。
根据纬度和经度的值稳定和移动,但我仍然感到困惑,因为当我试图绘制时。
示例:
35.1754255,126.9130674
35.1754281,126.9130184
35.1754225,126.9130536
35.1807405,126.9055772
剧情结果:
Values 1 ~ 3 正在移动,但只是很少移动,所以可能 value3 会被 "steady"、"short moving"、"long moving" 填充,但我仍然没有了解用于定义短和长的阈值。
我的第二个问题是如何使用 R 代码生成 value3。其实我可以比较下一个值和当前值,如果不同则表示移动,如果不是则表示稳定,但我仍然对短移动和长移动感到困惑。
我的数据中 dput() 的输出
> dput(loc)
structure(list(time = c("2014-06-30 08:26:36", "2014-06-30 08:31:30",
"2014-06-30 08:36:30", "2014-06-30 08:41:30", "2014-06-30 08:46:30",
"2014-06-30 08:51:30", "2014-06-30 08:56:31", "2014-06-30 09:01:30",
"2014-06-30 09:06:30", "2014-06-30 09:11:30", "2014-06-30 09:16:30",
"2014-06-30 09:21:30", "2014-06-30 09:26:30", "2014-06-30 09:31:30",
"2014-06-30 09:36:30", "2014-06-30 09:41:30", "2014-06-30 09:46:30",
"2014-06-30 09:51:52", "2014-06-30 09:56:30", "2014-06-30 10:01:30",
"2014-06-30 10:06:53", "2014-06-30 10:11:30", "2014-06-30 10:16:52",
"2014-06-30 10:21:30", "2014-06-30 10:26:30", "2014-06-30 10:31:30",
"2014-06-30 10:36:51", "2014-06-30 10:41:30", "2014-06-30 10:46:54",
"2014-06-30 10:51:51", "2014-06-30 10:57:30", "2014-06-30 11:01:51",
"2014-06-30 11:06:30", "2014-06-30 11:11:51", "2014-06-30 11:16:30",
"2014-06-30 11:21:51", "2014-06-30 11:26:30", "2014-06-30 11:31:30",
"2014-06-30 11:36:52", "2014-06-30 11:41:30", "2014-06-30 11:46:51",
"2014-06-30 11:51:30", "2014-06-30 11:56:53", "2014-06-30 12:01:32",
"2014-06-30 12:07:30", "2014-06-30 12:11:51", "2014-06-30 12:16:33",
"2014-06-30 12:21:30", "2014-06-30 12:26:30", "2014-06-30 12:31:51",
"2014-06-30 12:36:30", "2014-06-30 12:41:36", "2014-06-30 12:46:30",
"2014-06-30 12:52:10", "2014-06-30 12:56:30", "2014-06-30 13:01:30",
"2014-06-30 13:06:30", "2014-06-30 13:11:30", "2014-06-30 13:16:30",
"2014-06-30 13:21:30", "2014-06-30 13:26:30", "2014-06-30 13:31:30",
"2014-06-30 13:36:30", "2014-06-30 13:41:30", "2014-06-30 13:46:30",
"2014-06-30 13:51:30", "2014-06-30 13:56:30", "2014-06-30 14:01:30",
"2014-06-30 14:06:55", "2014-06-30 14:11:19", "2014-06-30 14:16:19",
"2014-06-30 14:21:19", "2014-06-30 14:26:19", "2014-06-30 14:31:19",
"2014-06-30 14:36:19", "2014-06-30 14:41:19", "2014-06-30 14:46:19",
"2014-06-30 14:51:19", "2014-06-30 14:56:19", "2014-06-30 15:01:19",
"2014-06-30 15:06:19", "2014-06-30 15:11:19", "2014-06-30 15:16:19",
"2014-06-30 15:21:19", "2014-06-30 15:26:19", "2014-06-30 15:31:19",
"2014-06-30 15:36:19", "2014-06-30 15:41:19", "2014-06-30 15:46:19",
"2014-06-30 15:51:19", "2014-06-30 15:56:19", "2014-06-30 16:01:19",
"2014-06-30 16:06:19", "2014-06-30 16:11:19", "2014-06-30 16:16:20",
"2014-06-30 16:21:19", "2014-06-30 16:26:19", "2014-06-30 16:31:19",
"2014-06-30 16:36:19", "2014-06-30 16:41:19"), type = c("location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location", "location", "location", "location",
"location", "location", "location"), value1 = c("35.1754255",
"35.1754281", "35.1754225", "35.1753982", "35.1753991", "35.1753997",
"35.1754333", "35.1754143", "35.1754126", "35.1754142", "35.1753987",
"35.1754178", "35.1754176", "35.1753914", "35.1754066", "35.1753833",
"35.1753883", "35.174465", "35.174465", "35.1735813", "35.1744781",
"35.1735813", "35.174502", "35.1749091", "35.1749091", "35.1749091",
"35.1744991", "35.1749091", "35.1751931", "35.1748972", "35.1755879",
"35.1759928", "35.1759928", "35.1763946", "35.1763946", "35.1763882",
"35.1763882", "35.1762131", "35.1760547", "35.1760547", "35.1774352",
"35.1774352", "35.1785821", "35.1785821", "35.1773562", "35.1807058",
"35.1807058", "35.1813436", "35.1802903", "35.1807615", "35.1807615",
"35.1807405", "35.1807405", "35.1805536", "35.1805536", "35.1808169",
"35.1797636", "35.1836812", "35.1836812", "35.1897643", "35.1898214",
"35.1897615", "35.1897765", "35.1897157", "35.1896921", "35.1897299",
"35.18975", "35.1897503", "35.1897673", "35.1897539", "35.1897932",
"35.1897702", "35.1897627", "35.189763", "35.1897438", "35.1898021",
"35.1897853", "35.1897405", "35.1897803", "35.1897844", "35.1897624",
"35.1897769", "35.1897656", "35.1897265", "35.1897488", "35.1897599",
"35.1897477", "35.1897951", "35.189759", "35.1897624", "35.1897692",
"35.1898468", "35.1897727", "35.1897624", "35.1897958", "35.189817",
"35.1897391", "35.1897317", "35.189745", "35.1897624"), value2 = c("126.9130674",
"126.9130184", "126.9130536", "126.9130597", "126.9130549", "126.9130598",
"126.9130484", "126.9130638", "126.9130687", "126.9130553", "126.913074",
"126.9130686", "126.9130779", "126.9130496", "126.9130196", "126.9130507",
"126.9130474", "126.9135807", "126.9135807", "126.9119189", "126.9137426",
"126.9119189", "126.9137499", "126.9124954", "126.9124954", "126.9124954",
"126.9137861", "126.9124954", "126.9142743", "126.9118689", "126.912267",
"126.9131502", "126.9131502", "126.9130495", "126.9130495", "126.9131069",
"126.9131069", "126.911819", "126.9121906", "126.9121906", "126.9123621",
"126.9123621", "126.9093961", "126.9093961", "126.9041179", "126.9055765",
"126.9055765", "126.904599", "126.9054961", "126.905568", "126.905568",
"126.9055772", "126.9055772", "126.9052718", "126.9052718", "126.9050475",
"126.9059447", "126.9052348", "126.9052348", "126.9063181", "126.9062802",
"126.9063452", "126.9064237", "126.9065031", "126.9065168", "126.9063599",
"126.9064195", "126.9064469", "126.9063441", "126.9063828", "126.9064423",
"126.9063459", "126.9063602", "126.9063096", "126.9063355", "126.9063742",
"126.9063253", "126.9063123", "126.9063434", "126.9063729", "126.906397",
"126.9063288", "126.906282", "126.9062903", "126.9063502", "126.9063432",
"126.9063004", "126.9063742", "126.9063343", "126.9063969", "126.9062847",
"126.9063212", "126.9063034", "126.9063969", "126.9063237", "126.906375",
"126.9063572", "126.9063514", "126.9062548", "126.906397"), value3 = c("",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "")), .Names = c("time", "type", "value1", "value2",
"value3"), row.names = c(NA, 100L), class = "data.frame")
这是我的尝试。正如我在上面的评论中提到的,您想自己定义 "short movement" 和 "long movement" 。例如,在 R 中,您可以在 dplyr
包中使用 lag()
并计算移动。我可能错了,但是 1 度大约是 111.32 公里。所以 0.0001 度大约是 11 米。在这次尝试中,如果这个人在经纬度上移动超过11米且小于55米,我认为移动"little movement"。任何更长的移动都被视为 "long movement"。由于我不是gis专业人士,所以我的做法可能不合适。但是,我希望这能给你一些你想要做什么的想法。
P.S。如果您有大量数据,ifelse()
会减慢处理速度。您想考虑使用 data.table
包。
# Note: 1 degree = 111.32 km
#0.0001 degree 11.1132 m
# Convert character to numeric
mydf$value1 <- as.numeric(mydf$value1)
mydf$value2 <- as.numeric(mydf$value2)
library(dplyr)
select(mydf, -type, -value3) %>%
mutate(movement = ifelse(value1 == lag(value1) & value2 == lag(value2), "same",
ifelse(between(abs(value1 - lag(value1)), 0.0001, 0.0005) == TRUE &
between(abs(value2 - lag(value2)), 0.0001, 0.0005) == TRUE, "little", "long")))
# A part of the outcome
#33 2014-06-30 11:06:30 35.175993 126.91315 same
#34 2014-06-30 11:11:51 35.176395 126.91305 little
#35 2014-06-30 11:16:30 35.176395 126.91305 same
#36 2014-06-30 11:21:51 35.176388 126.91311 long
#37 2014-06-30 11:26:30 35.176388 126.91311 same
#38 2014-06-30 11:31:30 35.176213 126.91182 long
#39 2014-06-30 11:36:52 35.176055 126.91219 little
#40 2014-06-30 11:41:30 35.176055 126.91219 same
#41 2014-06-30 11:46:51 35.177435 126.91236 long
#42 2014-06-30 11:51:30 35.177435 126.91236 same