我有一个世界国家的 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
但以南美洲为中心。谢谢你的帮助!
最佳答案
给 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)
关于r - 在正交投影中绘制世界地图给出 "non finite points",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26102012/