[GIS] Getting time-zones from latitude and longitude in raster using R

rtime

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.

Best Answer

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.)