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.

janosdivenyi
  • 303
  • 1
  • 2
  • 7

2 Answers2

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

janosdivenyi
  • 303
  • 1
  • 2
  • 7
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
fdetsch
  • 5,183
  • 2
  • 29
  • 41