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.
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]]
Hi Admas,Sorry I missed out the reproducible example.Here it is: dput(xy)structure(list(ID = 1:120, X = c(-102.6, -101.9, -97.1, -97,?-95.7, -99.1, -100.1, -97.2, -97, -99.3, -96, -95.2, -98.8, -98.1,?-99.6, -97.8, -96.1, -98.3, -95.6, -96.8, -101.2, -101.1, -97.2,?-111.1, -111.2, -116, -117.6, -103.7, -107.1, -102.3, -105.6,?-105.3, -108.5, -103.2, -94.1, -101.9, -94.7, -101.1, -97.9,?-111.4, -111.2, -110.5, -111.3, -107.3, -102.3, -104.7, -106.7,?-101.8, -106, -103, -107.9, -103.7, -103.8, -109.2, -108.9, -109.5,?-102.1, -104.6, -105.6, -101.7, -104, -108.3, -107.1, -103.9,?-105.2, -105.7, -104.7, -106.7, -108.8, -107.7, -102.2, -107.8,?-109.4, -106.1, -106.4, -104.2, -101.1, -99.9, -99.7, -101.3,?-113.3, -119.4, -113.8, -114.7, -112.8, -110.3, -113.6, -111.1,?-116.3, -118.5, -118.9, -117.4, -111.7, -114.1, -114.8, -113.8,?-115.8, -108.4, -109.1, -115.6, -114.2, -114, -113.4, -113.7,?-114.5, -112.9, -116.4, -113.1, -114.4, -117.5, -118, -113.8,?-112.8, -110.7, -113.6, -114.1, -114, -114.9, -112.7, -112.1),?? ? Y = c(52.88, 52.08, 50.93, 52.35, 51.03, 49.55, 51.1, 49,?? ? 50.63, 53.15, 50.47, 49.62, 50.42, 49.18, 50.15, 53.97, 50.18,?? ? 49.95, 49.02, 49.53, 52.12, 53.97, 49.92, 58.77, 56.65, 58.38,?? ? 57.75, 58.18, 57.35, 55.53, 57.25, 55.15, 59.57, 56.23, 58.73,?? ? 54.77, 56.35, 56.87, 55.8, 52.07, 50.72, 49.12, 51.58, 49.72,?? ? 50.9, 49.38, 50.47, 51.52, 51.27, 49.22, 50.98, 50.55, 51.25,?? ? 51.52, 49.68, 50.9, 49.62, 52.82, 50.33, 50.13, 53.33, 52.77,?? ? 51.48, 51.98, 52.42, 53.22, 50.43, 52.17, 52.37, 50.27, 51.2,?? ? 49.37, 53.13, 53.92, 49, 49.82, 50.43, 49.92, 49.42, 49.18,?? ? 54.72, 55.2, 53.28, 54.13, 53.03, 54.42, 53.32, 53.88, 55.42,?? ? 56.08, 55.18, 56.23, 53.42, 53.88, 55.28, 55.97, 54.15, 55.83,?? ? 54.05, 51.2, 49.47, 51.12, 49, 49.93, 49.63, 51.47, 53.58,?? ? 50.88, 50.55, 53.4, 52.93, 52.45, 49.63, 50.02, 49.13, 51.78,?? ? 49.52, 52.42, 52.33, 50.05)), .Names = c("ID", "X", "Y"), row.names = c(NA,?-120L), class = "data.frame") [[alternative HTML version deleted]]
By the way, this question is more appropriate for R-sig-geo. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/18/14, 8: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.