gpt4 book ai didi

r - 在正交投影中绘制世界地图给出 "non finite points"

转载 作者:行者123 更新时间:2023-12-04 20:05:27 27 4
gpt4 key购买 nike

我有一个世界国家的 shapefile,从 here 下载.我可以在 R 中使用

countries <- readOGR("shp","TM_WORLD_BORDERS-0.3",encoding="UTF-8",stringsAsFactors=F)
par(mar=c(0,0,0,0),bg=rgb(0.3,0.4,1))
plot(countries,col=rgb(1,0.8,0.4))

现在我想在正交投影(从外太空看到的地球)中绘制它,所以我正在尝试
countries <- spTransform(countries,CRS("+proj=ortho +lat_0=-10 +lon_0=-60"))

我也玩过 x_0 和 y_0 参数(如 here 所述),但我总是得到错误:
non finite transformation detected:
[1] 45.08332 39.76804 Inf Inf
Erro em .spTransform_Polygon(input[[i]], to_args = to_args, from_args = from_args, :
failure in Polygons 3 Polygon 1 points 1
Além disso: Mensagens de aviso perdidas:
In .spTransform_Polygon(input[[i]], to_args = to_args, from_args = from_args, :
108 projected point(s) not finite

有时在第 3 个多边形中,有时在第 7 个多边形中。那些“Inf”来自哪里?我需要更改任何参数吗?我想像这样绘制 map

orthographic projection

但以南美洲为中心。谢谢你的帮助!

最佳答案

maps打包一试。它会针对无法投影的点发出警告,但不会给出错误并关闭进程。稍微摆弄一下,即设置海洋的填充颜色(this 答案有助于解决该问题),我能够用几行来模拟您附加的 map :

library(maps)

## start plot & extract coordinates from orthographic map
o <- c(-10,-60,0) # oreantation
xy <- map("world",proj="orthographic", orientation=o, bg="black")
xy <- na.omit(data.frame(do.call(cbind, xy[c("x","y")])))

## draw a circle around the points for coloring the ocean
polygon(max(xy$x)*sin(seq(0,2*pi,length.out=100)),max(xy$y)*cos(seq(0,2*pi,length.out=100)),
col="blue4", border=rgb(1,1,1,0.5), lwd=2)

## overlay world map
colRamp <- colorRampPalette(c("lemonchiffon", "orangered"))
map("world",proj="orthographic", orientation=o,
fill=TRUE, col=colRamp(5), add=TRUE)

enter image description here

关于r - 在正交投影中绘制世界地图给出 "non finite points",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26102012/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com