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

如何在R中将智利Shapefile经度范围从(-180,180)转为(0,360)

将(-180,180)范围的Shapefile转换为(0,360)以匹配ERA5-Land栅格

问题背景

需要用智利的Shapefile裁剪ERA5-Land全球逐小时9x9km栅格数据,但两者经度范围不匹配:

  • Shapefile经度范围:(-109.455, -66.41472)(-180到180坐标系)
  • ERA5-Land栅格经度范围:(-0.05, 359.95)(0到360坐标系)

使用raster::rotate()转换栅格耗时过长,因此选择修改Shapefile的经度范围,将其从(-180,180)转换为(0,360),此方法仅处理少量矢量数据,效率极高。

参考范围信息

extent(ch_shp)
#class      : Extent 
#xmin       : -109.455 
#xmax       : -66.41472 
#ymin       : -55.98403 
#ymax       : -17.50755 

extent(ras)
#class      : Extent 
#xmin       : -0.05 
#xmax       : 359.95 
#ymin       : -90.05 
#ymax       : 90.05 

解决方案代码

方法1:使用sf包(推荐,现代矢量处理标准)

# 加载包
library(sf)
library(raster)

# 读取智利Shapefile
ch_shp <- st_read("path/to/your/chile_shapefile.shp")

# 将西经坐标(<0)转换为0-360范围:经度值+360
ch_shp_360 <- ch_shp
st_geometry(ch_shp_360) <- st_geometry(ch_shp_360) + c(360, 0)

# 验证转换后的范围
extent(ch_shp_360)
# 预期输出:xmin:250.545, xmax:293.58528, ymin:-55.98403, ymax:-17.50755

方法2:使用raster包(兼容旧版Spatial对象)

# 加载包
library(raster)

# 读取Shapefile
ch_shp <- shapefile("path/to/your/chile_shapefile.shp")

# 修改坐标:经度+360,纬度不变
coordinates(ch_shp) <- coordinates(ch_shp) + c(360, 0)

# 重新设置范围(可选,确保extent正确)
extent(ch_shp) <- extent(250.545, 293.58528, -55.98403, -17.50755)

后续裁剪操作

范围匹配后,即可快速执行裁剪/掩膜:

# 裁剪栅格到Shapefile范围
cropped_ras <- crop(ras, ch_shp_360)

# (可选)用Shapefile掩膜提取智利区域数据
masked_ras <- mask(cropped_ras, ch_shp_360)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 09:01:00