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

如何用边界线分割区域/多边形:苏门答腊SHP文件分割实践

基于巴里桑山脉中心线分割苏门答腊岛区域的R语言实现

我拥有sumatra.shp与bukit_barisan.shp文件,希望以**巴里桑山脉(Bukit Barisan)**的中心线为边界,分割sumatra.shp中的苏门答腊岛区域。以下是相关R语言处理及可视化代码:

# 将空间多边形数据框转换为数据框
sumatra_df <- fortify(sumatera)
bukit_df <- fortify(bukit_barisan)
# 生成中心线的样条插值
spline_fit <- smooth.spline(bukit_df$long, bukit_df$lat)
# 创建中心线数据框
centerline <- data.frame(long = spline_fit$x, lat = spline_fit$y)
# 加载所需库
library(ggplot2)
library(rnaturalearth)
library(rnaturalearthdata)
library(sf)
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
id <- world %>% filter(admin == "Indonesia")
library("ggspatial")
ggplot() + 
  geom_sf(data = id, fill = "white") + 
  geom_sf(data = world[world$admin != "Indonesia", ], fill = "antiquewhite") + 
  geom_polygon(data = western_df, aes(x = long, y = lat, group = group), fill = "lightgray", color = "lightgray") +
  geom_point(data = centerline, aes(x = long, y = lat), color = "black", size = 0.01) + 
  annotate(geom = "text", x = 101.5, y = 0.25, label = "Sumatra", fontface = "italic", color = "grey22", size = 6, angle = -45) + 
  annotation_scale(location = "bl", width_hint = 0.5) + 
  annotation_north_arrow(location = "bl", which_north = "true", pad_x = unit(0.75, "in"), pad_y = unit(0.5, "in"), style = north_arrow_fancy_orienteering) + 
  coord_sf(xlim = c(94, 107), ylim = c(-8, 6), expand = FALSE) + 
  xlab("经度") + ylab("纬度") + 
  ggtitle("") + 
  theme(panel.grid.major = element_line(color = gray(0.5), linetype = "dashed", size = 0.2), 
        panel.background = element_rect(fill = "aliceblue"))

可视化结果

苏门答腊岛区域示意图

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 12:05:18