[R-sig-Geo] converting latlong in decimal degrees to utm

Bede-Fazekas Ákos bfalevlist at gmail.com
Sat Jul 18 17:46:30 CEST 2015


Dear Moses,
you need firstly install the package "sp", then load it, and after that you should convert your data.frame to SpatialPoints or SpatialPointsDataFrame by setting the coordinates.

if (!("sp" %in% row.names(installed.packages()))){ # if package "sp" not yet installed
	suppressMessages(install.packages("sp", verbose = FALSE, quiet = TRUE, INSTALL_opts = c("--no-lock"), repos = "http://cran.us.r-project.org")) # installs it
} # if
library(sp) # loads it
coordinates(data) <- c("x", "y") # sets coordinates
if (class(data) == "SpatialPoints") {writeLines("Well done.")} # Now you can set projection.

Hope it helps,
Ákos

-----Original Message-----
From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of moses selebatso
Sent: 2015. július 18. 17:27
To: R-sig-Geo at r-project.org
Subject: [R-sig-Geo] converting latlong in decimal degrees to utm

I am trying to get my data (sample below) to utm before I can use it for Kernel Density Estimates. Can someone help?
> data<-read.csv("clipboard",sep="\t")
> head(data)
          x        y
1 -21.76580 23.20185
2 -21.76692 23.20126
3 -21.76690 23.20127
4 -21.76761 23.20338
5 -21.77223 23.20354
6 -21.77193 23.20327
> proj4string(data) <- CRS("+proj=utm +zone=34 +south +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs")
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘proj4string<-’ for signature ‘"data.frame", "CRS"’
Thank you, in advance. Moses SELEBATSO

(+267) 318 5219 (H) (+267) 716 393 70 (C)
  (+267) 738 393 70 (C
	[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list