我正在尝试运行一个物种分布模型,并需要创建背景点来运行我的逻辑回归模型。我刚刚创建了500个随机点,但它们是在UTM坐标系下的,我需要的是经纬度。是否有一种方法可以在R中将它们转换为经纬度?如果可以,请与我分享代码。我对R还比较新。谢谢!
我正在尝试运行一个物种分布模型,并需要创建背景点来运行我的逻辑回归模型。我刚刚创建了500个随机点,但它们是在UTM坐标系下的,我需要的是经纬度。是否有一种方法可以在R中将它们转换为经纬度?如果可以,请与我分享代码。我对R还比较新。谢谢!
points
)。 set.seed(1)
x <- runif(10, -10000, 10000)
y <- runif(10, -10000, 10000)
points <- cbind(x, y)
UTM,zone 10,datum=WGS84
投影中。library(terra)
v <- vect(points, crs="+proj=utm +zone=10 +datum=WGS84 +units=m")
v
# class : SpatVector
# geometry : points
# dimensions : 10, 0 (geometries, attributes)
# extent : -8764.275, 8893.505, -6468.865, 9838.122 (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
经度/纬度
。y <- project(v, "+proj=longlat +datum=WGS84")
y
# class : SpatVector
# geometry : points
# dimensions : 10, 0 (geometries, attributes)
# extent : -127.5673, -127.4091, -0.05834327, 0.08873723 (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +datum=WGS84 +no_defs
lonlat <- geom(y)[, c("x", "y")]
head(lonlat, 3)
# x y
#[1,] -127.5308 -0.0530354276
#[2,] -127.5117 -0.0583432750
#[3,] -127.4757 0.0337371933
back <- project(y, "+proj=utm +zone=10 +datum=WGS84 +units=m")
sf
包或旧的sp
包来完成。使用sp
,创建一个SpatialPoints
对象并使用spTransform
函数。library(sp)
sputm <- SpatialPoints(points, proj4string=CRS("+proj=utm +zone=10 +datum=WGS84"))
spgeo <- spTransform(sputm, CRS("+proj=longlat +datum=WGS84"))
lnlt <- coordinates(spgeo)
utm_zone <- function(longitude) { trunc((180 + longitude) / 6) + 1 }
longs <- c(-122,-119, -118)
utm_zone(min(longs))
# [1] 10
utm_zone(max(longs))
# [1] 11
utm_zone(max(longs))
+south
元素。s <- vect(cbind(174, -44), crs="+proj=longlat +datum=WGS84")
geom(project(s, "+proj=utm +zone=59"))[, c("x", "y")]
# x y
#740526.3 -4876249.1
geom(project(s, "+proj=utm +south +zone=59"))[, c("x", "y")]
# x y
#740526.3 5123750.9