【发布时间】:2021-12-24 13:13:14
【问题描述】:
我正在尝试使用凸包绘制物种范围区域,然后计算面积并创建一个图形。
180 度国际日期变更线有一个众所周知的问题,我一直在尝试解决 SE 上的许多示例,例如:
How to remedy a path that crosses the international dateline with R
这接近我的目标,但在 mapview 中绘制的不是 ggplot2: How to construct/plot convex hulls of polygons from points by factor using sf?
这是我的尝试:
library(tidyverse)
library(maps)
library(ggmap)
library(sf)
library(sp)
library(rnaturalearth)
library(rnaturalearthdata)
library(ggspatial)
library(mapproj)
生成物种出现数据,其中一些点跨越 180 经度
df <- data.frame(species = rep("sp1",8),
longitude = as.double(c(-170.2, -179.5, 55.9, 167.6, 154.3, 101.7, 70.54, -165.94)),
latitude = as.double(c(8.25, -24.75, 24.25,19.25, 33.45, -15.5, 5.56, 4.6)))
来自 map_data 和 plot 的以太平洋为中心的世界地图
world <- map_data("world2")
map<-ggplot() +
geom_polygon(data = world, aes(x = long, y = lat, group = group),
col = "#78909C", fill = "#78909C", lwd = 0)+
coord_map(orientation = c(90,0, 150), ylim = c(-40, 40), xlim = c(20,210))
向地图添加发生点
map +
geom_point(data = df, mapping = aes(x = longitude, y = latitude))
根据物种出现数据构造最小凸包。
species.sf <- df %>%
st_as_sf( coords = c( "longitude", "latitude" ))
创建船体并环绕日期线
hull<- species.sf %>%
summarise( geometry = st_combine( geometry ) ) %>%
st_convex_hull()
hull<-st_wrap_dateline(hull,options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180"),
quiet = TRUE)
绘制船体 - 在 180 处切割,但显然不包括所有出现点
map +
geom_point(data = df, mapping = aes(x = longitude, y = latitude))+
geom_sf(data=hull, inherit.aes = TRUE)
计算船体面积 - 必须根据船体形状不正确
st_area(hull)
我还尝试将太平洋中心 CRS 应用于地图、点和船体,但怀疑我以错误的顺序或错误的位置应用这些?我对使用 R 进行空间分析非常陌生,所以任何帮助都非常有用。谢谢。
【问题讨论】: