[R] LAT/LON to UTM in R

Adams, Jean jvadams at usgs.gov
Wed Nov 19 15:53:18 CET 2014


Zilefac,

I tried to run your "reproducible" code, but you didn't provide an object
"xy".

Jean

On Tue, Nov 18, 2014 at 10:20 AM, Zilefac Elvis <zilefacelvis at yahoo.com>
wrote:

> Hi,
> I am trying to convert lat/lon to UTM but my results are extremely flawed.
> Is it because of wrong UTM zone or my lon points are negative?
>
> I read a shapefile from ESRI using:
> library(rgdal)
> stations <- readOGR(".","stations")
> print(proj4string(stations))
> ## +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
>  How to convert to UTM the following lat/lon points? Reproducible example
> at the end.
>
>
> library(sp)
>
> coordinates(xy) <- c("X", "Y")
> proj4string(xy) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84
> +no_defs")  ## for example
> res <- spTransform(xy, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84
> +no_defs"))
> res
> as(res, "SpatialPoints")
> x<-as(res, "SpatialPoints")
> xx<-as.data.frame(x)
>
> #OR
>
> project(as.matrix(xy[,c("X","Y")]), "+proj=longlat +ellps=WGS84
> +datum=WGS84 +no_defs")
> Everything goes wrong with the values.
>
> Please help.
>
>
>
>
>
> Zilefac.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list