admin管理员组文章数量:1123400
I have used the rgdal
and raster
packages for converting my data from UTM 32 to UTM 33. However, these libraries have been replaced. Could you advise on the equivalent codes in the new terra
and sf
packages to perform the same operation?
Example data:
library(StatDA) ## contain the data
data <- data("trondelagC")
d_Tr <- subset(trondelagC,X.Medium=="Till") ##wgs32
proj4string(d_Tr) <- CRS("+init=epsg:32632") ## states the coordinate system
d1_Tr <- spTransform(x=d_Tr,CRS("+init=epsg:32633")) ## gives coordinates in UTM 33
In the latest version of R and RStudio this does not work any longer, I would appreciate any suggestions
I have used the rgdal
and raster
packages for converting my data from UTM 32 to UTM 33. However, these libraries have been replaced. Could you advise on the equivalent codes in the new terra
and sf
packages to perform the same operation?
Example data:
library(StatDA) ## contain the data
data <- data("trondelagC")
d_Tr <- subset(trondelagC,X.Medium=="Till") ##wgs32
proj4string(d_Tr) <- CRS("+init=epsg:32632") ## states the coordinate system
d1_Tr <- spTransform(x=d_Tr,CRS("+init=epsg:32633")) ## gives coordinates in UTM 33
In the latest version of R and RStudio this does not work any longer, I would appreciate any suggestions
Share Improve this question edited 13 hours ago jpsmith 16.9k6 gold badges20 silver badges44 bronze badges asked 13 hours ago Belinda FlemBelinda Flem 12 bronze badges New contributor Belinda Flem is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 5 |1 Answer
Reset to default 0Here is the general idea
library(terra)
xy <- cbind(c(0, 10), c(10, 50))
project(xy, from="+proj=longlat", to="epsg:32633")
# [,1] [,2]
#[1,] -1161976.4 1143849
#[2,] 141743.6 5550619
Or more formally:
v <- vect(xy, crs="lonlat")
p <- project(v, "epsg:32633")
# class : SpatVector
# geometry : points
# dimensions : 2, 0 (geometries, attributes)
# extent : -1161976, 141743.6, 1143849, 5550619 (xmin, xmax, ymin, ymax)
# coord. ref. : WGS 84 / UTM zone 33N (EPSG:32633)
crds(p)
# x y
#[1,] -1161976.4 1143849
#[2,] 141743.6 5550619
And see ?terra::project
and/or ?sf::st_transform
for additional possibilities.
本文标签: rHow to change UTM zone of a data setStack Overflow
版权声明:本文标题:r - How to change UTM zone of a data set - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736565956a1944704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
robCompositions
. But you are probably looking to something like :d_Tr |> sf::st_as_sf(coords = c("E32wgs","N32wgs"),crs = 32632 ) |> sf::st_transform(crs=32633)
– VinceGreg Commented 11 hours ago