R 在正投影中绘制世界地图是给;“非有限点”;

R 在正投影中绘制世界地图是给;“非有限点”;,r,map,plot,projection,orthographic,R,Map,Plot,Projection,Orthographic,我有一个世界各国的形状文件,从下载。我可以用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)) 有时在第三个多边形中,有时在第七个多边形中。那些“Inf”来自哪里?我需要更改任何参数吗?我想这样画地图 但以南美洲

我有一个世界各国的形状文件,从下载。我可以用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))
有时在第三个多边形中,有时在第七个多边形中。那些“Inf”来自哪里?我需要更改任何参数吗?我想这样画地图


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

试试
地图
软件包。它会对无法投影的点发出警告,但不会给出错误并关闭进程。只需稍加修改,即设置海洋的填充颜色(答案帮助解决了该问题),我就能够模拟您附带的地图,并添加了几行:

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)
库(地图)
##开始打印&从正交地图中提取坐标

o您正在尝试投影从-180到180以及从-90到90的所有坐标。但是,这是不可能的那种投影你正试图使用。首先尝试裁剪到您希望看到的投影区域。我强烈建议你阅读一些有关地理投影的文献。另请参阅:获取在何处进行裁剪的经验法则。谢谢,帕斯卡。我想画出整个半个世界,就像上面的图片一样。我想我只需要中心的lat/long,算法会在需要的地方切割。谢谢,plannapus,我会尝试使用这个公式来裁剪点。虽然我觉得这很愚蠢。应该有一种更简单的方法来自动绘制这种图……在第一个例子()中,他们不需要按照你说的做。这证明有一个更简单的方法,还是没有?谢谢保罗,它正在起作用。我在做一个插图,给出另一张更大地图的位置。如何将另一个地图的边框投影为该球体上的矩形?(它不是一个矩形,而是一个弯曲的矩形…)我可以用mapproject和rect来做,但是我得到了一个非弯曲的矩形。可能有更简单的方法,但我会手动构建一个矩形的坐标,使用
mapproject
进行投影,然后使用
多边形
添加它:
x是的,当然,我怎么没想到呢?;)再次感谢!
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
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)