【发布时间】:2021-09-30 01:46:55
【问题描述】:
我希望创建一系列四等分的圆(即分成 4 个相等的象限),每个圆的半径为 50 公里,我可以将它们映射到整个美国的各种经度和纬度。我还想要根据需要旋转这些四等圆的选项。
使用下面的代码(以及来自here 的指导),我已经能够进行以下操作:
我有两个问题:
- 如何有意义地设置这些圆的半径?有没有办法从投影的 CRS 中的坐标绘制一定距离(以公里为单位)的形状?到目前为止,我根据经度和纬度来定义半径,但距离会更有用。
- 在 WGS84 中投影和映射后,我的圆圈似乎变成了椭圆。有什么办法可以防止这种情况发生吗?
我很乐意考虑其他方法。谢谢!
library(sf)
library(ggplot2)
library(maps)
#Two functions to create coordinate quartered circle polygons
#x = long, y = lay, r = radius, theta_rotate = rotation
st_wedge <- function(x,y,r,start,width, theta_rotate){
n <- 20
theta = seq(start+theta_rotate, start+width+theta_rotate, length=n)
xarc = x + r*sin(theta)
yarc = y + r*cos(theta)
xc = c(x, xarc, x)
yc = c(y, yarc, y)
st_polygon(list(cbind(xc,yc)))
}
st_wedges <- function(x, y, r, nsegs, theta_rotatex){
width = (2*pi)/nsegs
starts = (1:nsegs)*width
polys = lapply(starts, function(s){st_wedge(x,y,r,s,width, theta_rotatex)})
#Cast to crs 4326, WGS84
mpoly = st_cast((st_sfc(polys, crs = 4326)), "MULTIPOLYGON")
mpoly
}
#Create quartered sf circle polygon
custom_circle_sf <- st_wedges(x = -76, y = 43, r = .3, nsegs = 4, theta_rotatex = 200) %>%
st_sf() %>%
mutate(group = row_number()) %>% dplyr::select(group, geometry)
#Create New York State sf polygon
ny_map_sf <- map_data("state", region="new york") %>%
st_as_sf(coords = c("long", "lat"), crs = 4326) %>%
group_by(group) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
#Plot results
ggplot() +
geom_sf(data=ny_map_sf,
size = 1,
colour = "blue",
fill = "white") +
geom_sf(data=custom_circle_sf,
size = .1,
aes(fill=group),
colour = "white")
【问题讨论】:
-
我还没有运行你的代码,但看起来你让它变得比它需要的更复杂。您可以将您的几何图形转换为以米为单位的美国 CRS —EPSG:4269 是一。然后只需使用
sf::st_buffer制作一个大小合适的圆圈。可能是一种更简单的方法,也可以使用一些sf函数将其分解为楔形,可能是通过在缓冲区和边界框部分之间进行交叉。我理解对了吗? -
另外,最好将第二个问题分成自己的帖子
-
谢谢卡米尔。我被认为是沿着这些思路的解决方案(您理解正确)。我相信您所描述的方法的想法是 1)创建一个以圆心为中心的 2x2“棋盘”; 2)给每个复选框一个等于圆半径的长度;和 3) 找到一种方法,使这个棋盘围绕原点(即圆心)旋转给定的度数。
-
我想我可以使用 st_bbox 创建边界框,然后使用 st_split 将框分成四个象限。还有什么听起来更可取的吗?
-
是的,除了使用
st_buffer来获得圈子,这就是我的想象。不确定我能否找到完整的答案,但我会继续考虑这个问题。
标签: r maps geospatial sf