我正在努力栅格化全局数据并使用 tmap 进行绘图。光栅化步骤难以产生稳定的输出,所以我正在尝试使用该包的解决stars::st_rasterize()
方法。这适用于使用本机方法的绘图输出正常的地步。但是 tmap 无法正确渲染并引发与 rgdal/proj 相关的错误。raster
stars::st_rasterize
require(tmap)
require(dplyr)
d = readr::read_csv('https://gist.githubusercontent.com/curran/13d30e855d48cdd6f22acdf0afe27286/raw/0635f14817ec634833bb904a47594cc2f5f9dbf8/worldcities_clean.csv') |>
group_by(lat = 5*round(lat/5), lng = 5*round(lng/5)) |>
summarise(n = length(lat), .groups = 'drop')
r = d |> dplyr::select(lng, lat, n) |>
raster::rasterFromXYZ(crs = '+proj=longlat +datum=WGS84')
r[is.na(r)] = 0
p = raster::rasterToPoints(r, spatial = FALSE) |> as_tibble() |>
sf::st_as_sf(coords = c('x', 'y'), crs = 'WGS84') |>
stars::st_rasterize()
plot(p)
tmap_mode("view")
tm_basemap("Stamen.TonerLite") +
tm_shape(p) +
tm_raster("n", palette = c('white','red'), alpha=0.5)
proj_create: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj/proj.db contains DATABASE.LAYOUT.VERSION.MINOR = 0 whereas a number >= 2 is expected. It comes from another PROJ installation.
proj_create: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj/proj.db contains DATABASE.LAYOUT.VERSION.MINOR = 0 whereas a number >= 2 is expected. It comes from another PROJ installation.
proj_create: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj/proj.db contains DATABASE.LAYOUT.VERSION.MINOR = 0 whereas a number >= 2 is expected. It comes from another PROJ installation.
proj_create: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj/proj.db contains DATABASE.LAYOUT.VERSION.MINOR = 0 whereas a number >= 2 is expected. It comes from another PROJ installation.
proj_create_operation_factory_context: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj/proj.db contains DATABASE.LAYOUT.VERSION.MINOR = 0 whereas a number >= 2 is expected. It comes from another PROJ installation.
pj_obj_create: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj/proj.db contains DATABASE.LAYOUT.VERSION.MINOR = 0 whereas a number >= 2 is expected. It comes from another PROJ installation.
pj_obj_create: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal/proj/proj.db contains DATABASE.LAYOUT.VERSION.MINOR = 0 whereas a number >= 2 is expected. It comes from another PROJ installation.
感谢任何想法来解开这个烂摊子。