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

Julian Burgos julian at hafro.is
Sat Jul 18 23:00:42 CEST 2015


Actually, you need to set the projection of the original data, and then
use spTransform the coordinates into UTM.  Do this:

data<-read.csv("clipboard",sep="\t")

library(sp)

coordinates(data) <- c("x", "y") # Creates a SpatialPoints object where x
and y are the coordinates, assuming that "x" is the horizontal coordinate
and "y" is the vertical one

proj4string(data) <- CRS("+proj=longlat + ellps=WGS84") # This sets the
projection of the data, assuming that you are using the WGS84 ellipsoid
(if you do not know for sure, it is a safe assumption)

data <-spTransform(data,CRS="+proj=utm +zone=27 +datum=WGS84") # Use
whatever UTM zone you need.

data <- as.data.frame(coordinates(data)) # This converts the SpatialPoints
object back into a data frame

All the best,

Julian

-- 
Julian Mariano Burgos, PhD
Hafrannsóknastofnun/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: julian at hafro.is




> 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
>
> _______________________________________________
> 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