0

I have a dataset with UTM coordinates and site names. I have transformed my UTM coordinates to DD using this code:

coordinates(Spatial)<-~Longitude+Latitude
sputm <- SpatialPoints(Spatial, proj4string=CRS("+proj=utm +zone=32V +datum=WGS84"))
spgeo <- spTransform(sputm, CRS("+proj=longlat +datum=WGS84"))
lnlt <- coordinates(spgeo)

However, then I loose the section name which I need to know which coordinate belongs to what section. Anyone know how I can solve this?

harre
  • 7,081
  • 2
  • 16
  • 28
Lene
  • 23
  • 4
  • What is a "Section"? It might help if you provide a small sample of representative data, see https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jul 14 '22 at 12:35
  • It looks like the spatial file in this example: https://cran.r-project.org/web/packages/actel/vignettes/a-0_workspace_requirements.html – Lene Jul 14 '22 at 13:04

1 Answers1

0

It goes like this:

library(sp)
d <- data.frame(x=c(0,1000), y=c(0,1000), section=1:2) 
coordinates(d) <- ~x+y
proj4string(d) = "+proj=utm +zone=1"
geo <- spTransform(d, CRS("+proj=longlat +datum=WGS84"))
as.data.frame(geo)
#  section        x           y
#1       1 178.5113 0.000000000
#2       2 178.5202 0.009019487

Or with "terra":

library(terra)
d <- data.frame(x=c(0,1000), y=c(0,1000), section=1:2) 
v <- vect(d, geom=c("x", "y"), crs="+proj=utm +zone=1")
g <- project(v, "+proj=longlat +datum=WGS84")
as.data.frame(g, geom="XY")
#  section        x           y
#1       1 178.5113 0.000000000
#2       2 178.5202 0.009019487
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63