如何在新版R中替代GADMTools制作自定义Shapefile?
替代GADMTools的R空间数据处理方案
方案1:使用sf + giscoR
giscoR提供欧盟官方地理边界数据,适配新版R,配合sf(当前R空间数据处理标准包)可完成需求:
- 安装并加载依赖包
install.packages(c("sf", "giscoR")) library(sf) library(giscoR)
- 获取指定国家边界并合并
# 目标国家ISO3代码与旧代码一致 target_countries <- c("RUS","LTU","LVA","EST","FIN", "POL","BLR") # 获取ADM0级别国家边界 country_shapes <- gisco_get_countries(country = target_countries) # 合并所有国家图层 joinmap <- do.call(rbind, country_shapes)
- 裁剪指定区域
# 裁剪范围参数与旧代码一致 studyarea <- st_crop(joinmap, xmin=19, ymin=50, xmax=25, ymax=56)
- 导出ArcGIS兼容的Shapefile
# 替换为你的目标路径 st_write(studyarea, "path_for_shapefile/studyarea.shp", driver = "ESRI Shapefile")
方案2:使用sf + rnaturalearth
rnaturalearth提供开源全球地理数据,适配新版R,覆盖范围广:
- 安装并加载依赖包
install.packages(c("sf", "rnaturalearth", "rnaturalearthdata")) library(sf) library(rnaturalearth)
- 获取指定国家边界并合并
target_countries <- c("RUS","LTU","LVA","EST","FIN", "POL","BLR") # 获取ADM0级别国家边界,返回sf格式对象 country_shapes <- ne_countries(country = target_countries, returnclass = "sf") joinmap <- country_shapes
- 裁剪指定区域
studyarea <- st_crop(joinmap, xmin=19, ymin=50, xmax=25, ymax=56)
- 导出Shapefile
st_write(studyarea, "path_for_shapefile/studyarea.shp", driver = "ESRI Shapefile")
注意事项
sf包支持所有现代R版本,功能覆盖空间数据处理全流程,可替代GADMTools完成更多操作- 导出的Shapefile包含完整属性信息,可直接在ArcGIS中加载使用
- 若需要细分行政边界(如州/省级别),可在
gisco_get_countries或ne_countries中指定level参数(如level = 1对应一级行政区)
内容的提问来源于stack exchange,提问作者Indrute
相关产品推荐
相关产品推荐

