Reputation: 53
So I got for example the following coordinates in decimal format:
X Y
50.13 9.81
50.75 9.84
50.78 10.25
50.45 10.58
I want to transform to WGS 84 UTM 32N; the Result should look like this:
X Y
556678.000 5664593.472
559258.226 5622360.938
...
Upvotes: 0
Views: 1538
Reputation: 27732
here is a solution using the 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
Upvotes: 1
Reputation: 1502
You could do this with the gstat, sp and rgdal packages too:
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
For some reason, these values do not match the values you provide in the question, but they do match @Wimpel results
Upvotes: 1