我怎样才能转换这个特定的坐标?
How can I convert this specific coordinates?
更新问题:
从最初的 table 个具有 X / Y 坐标的点开始,我想用 R 转换这些坐标。
从这个(在相同的数量级):
对此:
抱歉,提前致谢!
可能不是最优雅的方式,但似乎可以完成工作
示例数据
library(tidyverse)
mydf <- tibble(
etab = c("Guadeloupe","Martinique","Guyane","La Reunion","Corse"),
x = c(658750, 709950, 357950, 365750, 659245),
y = c(1796550,1609550,539650,7670150,6856374),
espg = c(2989,2989,2972,2975,2154)
)
# etab x y espg
# 1: Guadeloupe 658750 1796550 2989
# 2: Martinique 709950 1609550 2989
# 3: Guyane 357950 539650 2972
# 4: La Reunion 365750 7670150 2975
# 5: Corse 659245 6856374 2154
代码
library(data.table)
library(sf)
#split data.frma by espg
L <- split(setDT(mydf), by = "espg")
# Loop over list L, make data an sf-object and transform to WGS84
L2 <- lapply(seq_along(L), function(x) {
data <- L[[x]]
cur_esgp <- as.numeric(names(L)[x])
st_as_sf(data, coords = c("x","y")) %>%
sf::st_set_crs(cur_esgp) %>%
st_transform(4326)
} )
# bind the lists' elements back together
final <- purrr::reduce(L2, sf:::rbind.sf)
输出
mapview::mapview(final)
更新问题:
从最初的 table 个具有 X / Y 坐标的点开始,我想用 R 转换这些坐标。
从这个(在相同的数量级):
对此:
抱歉,提前致谢!
可能不是最优雅的方式,但似乎可以完成工作
示例数据
library(tidyverse)
mydf <- tibble(
etab = c("Guadeloupe","Martinique","Guyane","La Reunion","Corse"),
x = c(658750, 709950, 357950, 365750, 659245),
y = c(1796550,1609550,539650,7670150,6856374),
espg = c(2989,2989,2972,2975,2154)
)
# etab x y espg
# 1: Guadeloupe 658750 1796550 2989
# 2: Martinique 709950 1609550 2989
# 3: Guyane 357950 539650 2972
# 4: La Reunion 365750 7670150 2975
# 5: Corse 659245 6856374 2154
代码
library(data.table)
library(sf)
#split data.frma by espg
L <- split(setDT(mydf), by = "espg")
# Loop over list L, make data an sf-object and transform to WGS84
L2 <- lapply(seq_along(L), function(x) {
data <- L[[x]]
cur_esgp <- as.numeric(names(L)[x])
st_as_sf(data, coords = c("x","y")) %>%
sf::st_set_crs(cur_esgp) %>%
st_transform(4326)
} )
# bind the lists' elements back together
final <- purrr::reduce(L2, sf:::rbind.sf)
输出
mapview::mapview(final)