光栅仅在tmap中部分绘制

问题描述 投票:0回答:1

我的一些包含栅格的地图仅部分绘制。地图的南部部分被切断。看起来像是内存限制,但我不知道是否如此。另一个选项是有关重投影和 bbox 的内容...尽管如此,相同 crs 的其他光栅在此项目中运行良好。 Final map cut off in the south

library(tmap)
library(tmaptools)
library(sf)
library(raster)
library(maps)

raster.file <-   tempfile()
download.file("https://github.com/andliszmmu/storage/raw/main/copernicus_2000.tif", raster.file, mode="wb")

ocean.pal   <- '#afdff9'
prj         <- CRS("+proj=eqdc +lat_0=57 +lon_0=46.8 +lat_1=69.4367 +lat_2=51.3043 +x_0=0 +y_0=0 +ellps=sphere +units=m +no_defs")
map_bbox    <- st_bbox(c(xmin = -1700000, ymin = -1780000, xmax = 1040000, ymax = 2330000), crs = prj)

land        <- st_as_sf(maps::map("world", plot = FALSE, fill = TRUE))
land        <- land[land$ID=='Russia',]
land        <- st_transform(land, prj)

model        <- raster(paste0(raster.file))

  tm =  
    tm_shape(land, bbox = map_bbox) +
    tm_fill(col = ocean.pal) +
    tm_shape(model)+
    tm_raster(style='fixed',
              breaks = c(0, 35,45,55,67,75,85,95,112, 200),
              palette=c('lightgreen', 'yellow', 'red', 'grey', 'white', 'blue', '#f21deb', 'darkgreen', 'green'),
              labels=c("a","b","c","d","e","f","g","h","i"),
              alpha = 1,
              #n=5,
              stretch.palette = FALSE,
              title = 'Landscape classification',
              legend.show = TRUE,
              legend.reverse = TRUE,
              legend.z=0) +
    tm_layout(frame = T,
              frame.lwd = 2,
              inner.margins = c(0,0,0,0),
              outer.margins = c(0.07, 0.127, 0.07, 0.112),
              asp = 39/56,
              legend.frame = T,
              legend.format = list(text.separator = "–"),
              legend.frame.lwd = 1,
              legend.outside = F,
              legend.position = c(0.001, 0.999),
              legend.just = c("left", "top"),
              legend.width = -0.32,
              legend.height = 0.9,
              legend.text.size = 0.7,
              legend.title.size = 1.1,
              legend.bg.color = "white",
              title.size = 0.7,
              title.bg.color = 'white',
              title.position = c('left', 'bottom')) +
    tmap_options(check.and.fix = TRUE,
                 max.raster = c(plot = 1e8, view = 1e8))
  
tm
    

我检查了文档和网络,但没有找到解决方案。
该栅格的参数为:
类:光栅层
尺寸:2000、1441、2882000(nrow、ncol、ncell)
分辨率:0.0343、0.0179(x、y)
范围:19.64043、69.06673、41.19558、76.99558(xmin、xmax、ymin、ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
来源:copernicus_2000.tif
名称:copernicus_2000
值:20、200(最小值、最大值)
光栅下采样(分辨率 <- 0.0343, 0.0343) did not help.

r raster tmap
1个回答
0
投票

那些不符合要求的预测可能很难协商。好奇您的其他数据都没有被剪切,但我假设没有一个数据延伸到问题栅格的南部?

无论哪种方式,这里都有一个解决方案。它涉及

raster::extend()
栅格的南部范围:

library(tmap)
library(tmaptools)
library(sf)
library(raster)
library(maps)

# PROJ4 string
prj <- "+proj=eqdc +lat_0=57 +lon_0=46.8 +lat_1=69.4367 +lat_2=51.3043 +x_0=0 +y_0=0 +ellps=sphere +units=m +no_defs"

# Load SpatRaster from working directory previously downloaded from
# https://github.com/andliszmmu/storage/raw/main/copernicus_2000.tif
r <- raster("data/copernicus_2000.tif")

# Return extent of raster
st_bbox(r)
#     xmin     ymin     xmax     ymax 
# 19.64043 41.19558 69.06673 76.99558 

# Extend the southern extent of r e.g. change 41.19558 to 30
r <- extend(r, extent(19.64043, 69.06673, 30, 76.99558))

map_bbox <- st_bbox(c(xmin = -1700000, ymin = -1780000, xmax = 1040000, ymax = 2330000), crs = prj)

ocean.pal <- '#afdff9'
land <- st_as_sf(maps::map("world", plot = FALSE, fill = TRUE))
land <- land[land$ID=='Russia',]
land <- st_transform(land, prj)

tm =
  tm_shape(land, bbox = map_bbox) +
  tm_fill(col = ocean.pal) +
  tm_shape(r)+
  tm_raster(style = 'fixed',
            breaks = c(0, 35,45,55,67,75,85,95,112, 200),
            palette=c('lightgreen', 'yellow', 'red', 'grey', 'white', 'blue', '#f21deb', 'darkgreen', 'green'),
            labels=c("a","b","c","d","e","f","g","h","i"),
            alpha = 1,
            #n=5,
            stretch.palette = FALSE,
            title = 'Landscape classification',
            legend.show = TRUE,
            legend.reverse = TRUE,
            legend.z=0) +
  tm_layout(frame = T,
            frame.lwd = 2,
            inner.margins = c(0,0,0,0),
            outer.margins = c(0.07, 0.127, 0.07, 0.112),
            asp = 39/56,
            legend.frame = T,
            legend.format = list(text.separator = "–"),
            legend.frame.lwd = 1,
            legend.outside = F,
            legend.position = c(0.001, 0.999),
            legend.just = c("left", "top"),
            legend.width = -0.32,
            legend.height = 0.9,
            legend.text.size = 0.7,
            legend.title.size = 1.1,
            legend.bg.color = "white",
            title.size = 0.7,
            title.bg.color = 'white',
            title.position = c('left', 'bottom')) +
  tmap_options(check.and.fix = TRUE,
               max.raster = c(plot = 1e8, view = 1e8))

tm

1

© www.soinside.com 2019 - 2024. All rights reserved.