在正投影中绘制世界地图给出了“非有限点”

时间:2014-09-29 14:15:35

标签: 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”来自哪里?我需要更改任何参数吗?我想像这样绘制地图

orthographic projection

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

1 个答案:

答案 0 :(得分:4)

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

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