You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R terra包栅格化后出现垂直白线的原因排查求助

Troubleshooting Vertical White Lines When Upscaling a Coarse Raster to Fine Resolution

Hey there, let's break down why those vertical white lines are appearing in your plot and walk through better ways to fill your fine-resolution raster with coarse values.

Why the White Lines Happen

The core issue comes from floating-point precision errors in your resolution calculation and an unnecessary detour through point data:

  • Your res_drop calculates to 89.99999 instead of the exact integer 90 (since 0.25 / 0.002777778 = 90 exactly). Using a non-integer fact in terra::disagg() creates a misalignment between your disaggregated coarse raster and the target fine raster.
  • Converting the disaggregated raster to points and then rasterizing back introduces gaps: some fine-resolution pixels don't get matched to any points, resulting in the white (NA) vertical lines you see.

Better Solutions to Avoid White Lines

Option 1: Use Exact Integer Disaggregation + Resampling

Skip the point conversion entirely and use precise integer scaling:

# Use the exact integer factor (0.25 / 0.002777778 = 90)
res_drop <- 90

# Disaggregate the coarse raster with the exact integer factor
raster_coarse_disagg <- terra::disagg(raster_coarse, fact = res_drop)

# Resample to match the fine raster's exact extent and alignment (eliminates any tiny misalignment)
raster_coarse_filled <- terra::resample(raster_coarse_disagg, raster_fine, method = "near")

# Check the result and plot
raster_coarse_filled
plot(raster_coarse_filled)

Option 2: Rasterize Coarse Raster Polygons Directly

Convert the coarse raster to polygon features and rasterize those to the fine grid—this ensures full coverage without gaps:

# Convert coarse raster to polygons (each cell becomes a polygon)
raster_coarse_poly <- terra::as.polygons(raster_coarse)

# Rasterize the polygons to the fine raster
raster_coarse_filled <- terra::rasterize(
  x = raster_coarse_poly, 
  y = raster_fine, 
  field = "layer1", 
  fun = max, 
  touches = TRUE
)

# Plot the result
plot(raster_coarse_filled)

Option 3: Extract Coarse Values to Fine Raster

Use extract() to directly assign coarse values to each fine pixel:

# Extract the coarse raster value for every fine raster pixel
coarse_values <- terra::extract(raster_coarse, raster_fine)$layer1

# Create a copy of the fine raster and assign the coarse values
raster_coarse_filled <- raster_fine
terra::values(raster_coarse_filled) <- coarse_values

# Plot the result
plot(raster_coarse_filled)

All three methods will eliminate the vertical white lines by ensuring full, aligned coverage of the fine raster with your coarse data.

内容的提问来源于stack exchange,提问作者89_Simple

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 17:45:39