0

I have a raster with longitudes and latitudes for the US with meteorological data (for about 100k grid points). I would like to get the time zone for each point in order to transform the time to local time. Here is how my raster look like:

> raster
class       : SpatialPointsDataFrame 
features    : 95025 
extent      : -179.9979, 179.9918, 1, 85.33336  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0 
variables   : 1
names       : narr.a_221_20141002_1200_000.sub 
min values  :                                0 
max values  :                              100 

This problem is somewhat similar to https://stackoverflow.com/questions/23414340/convert-to-local-time-zone-using-latitude-and-longitude, except that I have lots of points. The suggested solution there does not work as the Google API accepts only limited number of requests per day and I do not think that the brute force solution would be the most efficient.

I am an absolute beginner in geographical data, but familiar with R, so I need a solution which works in R.

  • isn't it possile to subset your data and do the process over several days? That is if you can't find auxiliary data e.g. time zone vector map. – dof1985 Apr 16 '15 at 16:51
  • 2
    Try to do it in 2 steps: 1) find time zone by long/lat; 2) convert time to local time using time zone. Here is a link how to make the first step: earthtools.org/webservices.htm#timezone – Remigijus Pankevičius Apr 16 '15 at 17:19
  • 2
    Something like this dataset might help. It can be opened using rgdal and then do a point in polygon overlay – MickyT Apr 16 '15 at 21:04
  • 1
    Package geonames might be of interest. – user32309 Apr 17 '15 at 5:23
  • Please extract your answer from your question and use it to write an answer instead. – PolyGeo Nov 1 '16 at 11:46
0

As the number of points are way to much to request the timezone by lon/lat for each, the solution of @MickyT worked:

tz <- shapefile("us/tz_us.shp")
tz_polygon <- SpatialPolygons(tz@polygons, proj4string=tz@proj4string)
pts_over_tz <- over(raster, tz)

(Also note that my "raster" is actually a SpatialPointsDataFrame object, created by rasterToPoints(r, spatial = TRUE) where r is indeed a RasterLayer object.)

0

For future reference, this can be easily achieved with tz_lookup() from the lutz package. Using US cities as input point data:

library(USAboundaries) 
library(lutz)

cts = us_cities()
tzs = tz_lookup(cts)
table(tzs)
             America/Anchorage                  America/Boise                America/Chicago 
                            12                             47                           2658 
                America/Denver                America/Detroit             America/Hermosillo 
                           313                            222                              1 
  America/Indiana/Indianapolis           America/Indiana/Knox      America/Indiana/Tell_City 
                           114                              1                              1 
     America/Indiana/Vincennes                 America/Juneau    America/Kentucky/Louisville 
                             6                              1                             19 
   America/Kentucky/Monticello            America/Los_Angeles              America/Matamoros 
                             1                            850                              3 
             America/Menominee                America/Moncton               America/New_York 
                             4                              1                           2507 
                  America/Nome    America/North_Dakota/Beulah America/North_Dakota/New_Salem 
                             3                              1                              1 
               America/Phoenix                  America/Sitka                America/Toronto 
                            76                              3                              2 
             America/Vancouver               America/Winnipeg               Pacific/Honolulu 
                             1                              1                             83

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.