Skip to content

from long/lat to UTM

2 messages · Greg Snow, (Ted Harding)

#
zone!".
[snip]
I found a shapefile of time zones at: 
http://openmap.bbn.com/data/shape/timezone/ 

A google search on the keywords timezone & shapefile finds a 
few other possibilities.
The "maptools" package can read in the above shapefile and 
convert it to a list of polygons and the "sgeostat" has an
"in.polygon" function to see if a point is in a given polygon.

The following code worked for me:

library(maptools)
tz <- read.shape('c:/maps/WrldTZA')
plot(tz)
plot(tz,xlim=c(-150,-50), ylim=c(20,50))

mappoly <- Map2poly(tz)

library(sgeostat)

tmp <- sapply(mappoly, function(x){ x <- na.exclude(x)
	in.polygon( -110, 42, x[,1], x[,2] ) } )

tz$att.data[tmp,]


the -110 and 42 come from me plotting the map and using 
locator to approximate where I am at.  I was actually 
suprized at how quick the sapply was (under a second on
my fairly fast pc (windows 2000)).

It shouldn't be too hard to convert this into a more general
function.




Greg Snow, Ph.D.
Statistical Data Center
greg.snow at ihc.com
(801) 408-8111
#
On 10-Mar-05 Greg Snow wrote:
Many thanks, Greg. That looks just the job, and I'll look
into it.

All best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 10-Mar-05                                       Time: 18:10:23
------------------------------ XFMail ------------------------------