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

标签 r map plot projection orthographic

我有一个世界国家的 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/

相关文章:

r - 循环中 Plotly 中的 add_trace

在序列中每隔 n 个重复第 n 个元素

c++ - 在 C++ 中为 Rcpp 的 NumericMatrix 使用循环是一个很好的理想吗?

recursion - 如何实现惰性 "reducing map"函数?

java - Java 中的 Arduino Map 等效函数

r - 使用 R 构建特定的时间序列图

r - 针对另一个分类变量绘制分类变量

r - 如何在 R 中绘制置信区间

r - 其中(vector1 <vector2)

r - 无法在 ggplot2 上绘制比例尺或指北针