其他
R语言经纬度度分秒转小数点
library(readxl)
ENdata <- read_excel(path = "样点.xlsx", sheet = 1, col_names = T) #读取EXCEL数据
EDegreedata <- strsplit(ENdata$E, split = "°") #度分隔符
Du <- vector()
for (i in 1:length(EDegreedata)){
Du[i] <- EDegreedata[[i]][1]
}
FenMiao <- vector()
for (i in 1:length(EDegreedata)){
FenMiao[i] <- EDegreedata[[i]][2]
}
EMindata <- strsplit(FenMiao, split = "′") #分分隔符
Fen <- vector()
for (i in 1:length(EMindata)){
Fen[i] <- EMindata[[i]][1]
}
Miao <- vector()
for (i in 1:length(EMindata)) {
Miao[i] <- EMindata[[i]][2]
}
Miaodata <- strsplit(Miao, split = "″") #秒分隔符
for (i in 1:length(Miaodata)) {
Miao[i] <- Miaodata[[i]]
}
E <- as.numeric(Du)+as.numeric(Fen)/60+as.numeric(Miao)/3600
NDegreedata <- strsplit(ENdata$N, split = "°") #度分隔符
Du <- vector()
for (i in 1:length(NDegreedata)){
Du[i] <- NDegreedata[[i]][1]
}
FenMiao <- vector()
for (i in 1:length(NDegreedata)){
FenMiao[i] <- NDegreedata[[i]][2]
}
NMindata <- strsplit(FenMiao, split = "′") #分分隔符
Fen <- vector()
for (i in 1:length(NMindata)){
Fen[i] <- NMindata[[i]][1]
}
Miao <- vector()
for (i in 1:length(NMindata)) {
Miao[i] <- NMindata[[i]][2]
}
Miaodata <- strsplit(Miao, split = "″") #秒分隔符
for (i in 1:length(Miaodata)) {
Miao[i] <- Miaodata[[i]]
}
N <- as.numeric(Du)+as.numeric(Fen)/60+as.numeric(Miao)/3600
EN <- data.frame(E,N)
write.csv(EN, file = "EN.csv") #输出结果文件