【发布时间】:2021-01-26 03:40:07
【问题描述】:
使用 spTransform 等可以直接在 R 中转换坐标,但是有没有办法绕过 Spatial 对象并直接在数据框中进行转换?仅在 2 列上运行转换方程?例如。从 latlon 到 British National Grid 作为新列:
# current way using a spatial object
require(raster)
require(rgdal)
# define BNG and latlon
BNG <- CRS("+init=epsg:27700")
LL <- CRS("+init=epsg:4326")
# dummy data
toconv <- data.frame(id=c("a","b","c"), lat=c(54.530776,54.551913,54.455268), lon=c(-2.6006958,-2.4084351,-2.4688599))
# promote to spatial points data frame and define CRS of points
coordinates(toconv) = ~lon + lat
crs(toconv) <- LL
# current LL coordinates as columns in the SPDF
toconv$Xlon <- coordinates(toconv)[,1]
toconv$Ylat <- coordinates(toconv)[,2]
# transform to BNG
conv <- spTransform(toconv, crs(BNG))
# rename the coords from original name to new wanted name
colnames(conv@coords) <- c("Xbng","Ybng")
# extract as data frame, new coords with new name are new columns.
final <- as.data.frame(conv)
但是我想从原始虚拟数据 ('toconv') 直接转到最终输出 ('final') 而不费吹灰之力,是否可以在一个函数中实现? (例如,包含 Helmert 转换或 OSTN02 转换的函数)
【问题讨论】:
-
所以您想要一行代码而不是几行代码来完成所有这些工作?
-
是的,我认为没有空间对象会有这样的功能
-
我认为答案是
gdalUtils::gdaltransform,但我目前处于状态 1 和 NA,我将继续探索
标签: r coordinates spatial