-----Original Message-----
From: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Roger Bivand
Sent: Tuesday, March 06, 2007 8:28 AM
To: Gabor Grothendieck
Cc: r-sig-geo at stat.math.ethz.ch
Subject: Re: [R-sig-Geo] LL to UTM
On Tue, 6 Mar 2007, Gabor Grothendieck wrote:
Thanks. I looked at spTransform prior to posting but don't
What I want is to create a function that returns UTM coordinates:
LL2UTM <- function(lat, long, zone = 18) { ...
}
library(rgdal)
LL2UTM <- function(lat, long, zone=18) {
project(cbind(long, lat), paste("+proj=utm +zone=", zone, sep="")) }
gets you there, for example for:
lat <- seq(30,45,1)
long <- seq(-78,-72,1)
grd <- expand.grid(lat, long)
LL2UTM(grd[,1], grd[,2])
The project() interface to PROJ4 does not support datum
transfromation, the spTransform() method does. The cost is
having to convert the data to a Spatial* object:
SP_grd <- SpatialPoints(cbind(grd[,2], grd[,1]),
proj4string=CRS("+proj=longlat +datum=NAD83"))
SP_grd1 <- spTransform(SP_grd, CRS("+proj=utm +zone=18 +datum=NAD83"))
returning a SpatialPoints object - use the coordinates()
method to retrieve as a matrix.
Assuming that your input geographical coordinates are in
NAD84/WGS84, and the output UTM coordinates are in the same
datum, project() will be OK. If you need datum
transformation, which may lead to errors of hundreds of
metres if not used, the PROJ4 string needs more detail. If
this is at the block scale, datum transformation will make a
difference if the input and output specifications vary (say
placing points on a UTM map not in WGS84/NAD83). At the
continental scale the differences are typically not great,
but then you wouldn't use UTM anyway.
Hope this helps,
Roger
If necessary, zone=18 can be hardcoded in the function and that arg
removed.
I assume that using spTransform its just a one line body.
me the specific line that it should be?
Thanks.
On 3/6/07, Edzer J. Pebesma <e.pebesma at geo.uu.nl> wrote:
Gabor,
package rgdal provides an interface to the PROJ.4 library for
projection of geographical data. Look for the function (or rather
method) spTransform. It takes any of the spatial classes
package sp, and afaik any of the known projection
UTM and ellipsoids (LL reference "model").
--
Edzer
Gabor Grothendieck wrote:
I am currently using this web page to convert LL to UTM