[英]How to convert coordinates from degree decimal minutes to decimal degrees in R?
[英]How to convert coordinates in decimal degree to UTM format in R?
所以我得到了例如以下十进制格式的坐标:
X Y
50.13 9.81
50.75 9.84
50.78 10.25
50.45 10.58
我想转换为 WGS 84 UTM 32N; 结果应如下所示:
X Y
556678.000 5664593.472
559258.226 5622360.938
...
这是使用sf
-package 的解决方案
library(data.table) #for reading in sample data
library(magrittr) #for pipe
library(sf)
dt <- data.table::fread("X Y
50.13 9.81
50.75 9.84
50.78 10.25
50.45 10.58")
dt %>%
sf::st_as_sf( coords = c("Y", "X") ) %>%
sf::st_set_crs( 4326 ) %>% #current CRS is WSG84 (I think) <--!! check!!
sf::st_transform( 32632 ) %>% #transform CRS to 32632
sf::st_coordinates() #export new coordinates
# X Y
# 1 557893.3 5553399
# 2 559258.2 5622361
# 3 588124.7 5626105
# 4 612170.9 5589858
您也可以使用 gstat、sp 和 rgdal 软件包执行此操作:
library(gstat)
library(sp)
library(rgdal)
dt <- data.frame(x=c(50.13,50.75,50.78,50.45),y=c(9.81,9.84,10.25,10.58))
coordinates(dt) <- ~ y + x
proj4string(dt) <- CRS("+init=epsg:4326")
spTransform(dt, CRS("+init=epsg:32632"))
# SpatialPoints:
# y x
# 1 557893.3 5553399
# 2 559258.2 5622361
# 3 588124.7 5626105
# 4 612170.9 5589858
出于某种原因,这些值与您在问题中提供的值不匹配,但它们与@Wimpel 结果匹配
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.