[英]Shapefile extent - from UTM to lat/long
I have a SpatVector in a UTM projection, with the extent in easting/northing values, and I would like to reproject it to a lat/long projection and obtain the extent in degrees.我在 UTM 投影中有一个 SpatVector,其范围为东/北值,我想将其重新投影为纬度/经度投影并获得度数。 I already tried the project() function of the terra package, but nothing changes.我已经尝试过 terra package 的 project() function,但没有任何变化。
This is the extent of my SpatVector: extent: 293596.6, 415718.1, 5048171, 5168476 (xmin, xmax, ymin, ymax).这是我的 SpatVector 的范围:范围:293596.6、415718.1、5048171、5168476(xmin、xmax、ymin、ymax)。
And I would like to obtain something like this: extent: -10.4778, 70.2623, 29.94065, 68.34284 (xmin, xmax, ymin, ymax)我想得到这样的东西: 范围:-10.4778, 70.2623, 29.94065, 68.34284 (xmin, xmax, ymin, ymax)
Thank you for your help!!谢谢您的帮助!!
This is what I use to convert UTM to lat/lon:这是我用来将 UTM 转换为纬度/经度的方法:
utm_to_latlon <- function(utme, utmn, utmzone) {
y <- sp::SpatialPoints(cbind(utme, utmn))
sp::proj4string(y) <- sp::CRS(paste0("+proj=utm +zone=", utmzone, " +ellps=WGS84 +datum=WGS84"))
y <- sp::spTransform(y, sp::CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))
colnames(y@coords) <- c("lon", "lat")
data.frame(y@coords)
}
I don't know of a single function (in sp
or rgeos
or otherwise) that does this itself.我不知道有一个 function (在sp
或rgeos
或其他方式中)可以自行完成此操作。
Here is how you can use terra::project
以下是使用terra::project
的方法
Example data示例数据
library(terra)
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
lonlat to UTM lonlat 到 UTM
utm <- terra::project(v, "+proj=utm +zone=32")
ext(utm) |> round()
#SpatExtent : 266046, 322164, 5481445, 5563062 (xmin, xmax, ymin, ymax)
And back然后回来
geo <- terra::project(v, "+proj=longlat")
ext(geo) |> round(1)
#SpatExtent : 5.7, 6.5, 49.4, 50.2 (xmin, xmax, ymin, ymax)
To only project the extent:仅投影范围:
e <- as.polygons(utm, ext=TRUE)
e <- terra::project(e, "+proj=longlat")
ext(e) |> round(1)
#SpatExtent : 5.7, 6.5, 49.4, 50.2 (xmin, xmax, ymin, ymax)
Or variations like this, depending on your ultimate goal:或者像这样的变化,取决于你的最终目标:
as.points(ext(utm), crs=crs(utm)) |> project("+proj=longlat") |> crds()
# x y
#[1,] 5.772571 49.44059
#[2,] 5.723418 50.17350
#[3,] 6.508450 50.19301
#[4,] 6.545861 49.45960
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.