dime-worldbank / googletraffic

R package to query Google Maps traffic data and transform into data
Other
55 stars 9 forks source link

Projection Issues with Large Extents #2

Closed ramarty closed 1 year ago

ramarty commented 1 year ago
us_adm0_sp <- getData('GADM', country='USA', level=1)
us_adm0_sp <- us_adm0_sp[!(us_adm0_sp$NAME_1 %in% c("Alaska", "Hawaii")),]
us_adm0_sp <- gBuffer(us_adm0_sp, width = 0)
us_adm0_sp$id <- 1

us_adm0_sp_s <- gSimplify(us_adm0_sp, tol = 20/111.21)
us_adm0_sp_s$id <- 1

grid_df <- gt_make_grid(polygon = us_adm0_sp_s,
                        height  = 2000,
                        width   = 2000,
                        zoom    = 8)

r <- gt_make_raster_from_grid(grid_param_df = grid_df[14:15,],
                              webshot_delay = NULL,
                              google_key    = google_key)

leaflet() %>% 
  addTiles() %>%
  addPolygons(data = grid_df[14:15,],
              popup = ~as.character(id)) %>%
  addRasterImage(r, opacity = 0.8) 
ramarty commented 1 year ago

Issue results from merging/mosaic rasters with different resolutions (eg, tiles above/below each other)

ramarty commented 1 year ago

https://stackoverflow.com/questions/73507052/in-r-merge-mosaic-rasters-with-different-extents-resolutions-and-origins

ramarty commented 1 year ago

Could just flag... only works for small extents. For large extents (district or country), may fail -- and set save as tiles option to TRUE.

But can we think of a threshold? Or try merging, and if merging fails, just export as list -- and flag that exported as a list.

But list is harder... counting number of cells... but theres overlap... so would double count... so not ideal...