在正投影中绘制世界地图是给出“非有限点” [英] Plotting world map in orthographic projection is giving "non finite points"

查看:192
本文介绍了在正投影中绘制世界地图是给出“非有限点”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个世界国家的形状文件,从答案有助于解决这个问题),我能够模拟你附加的几行的地图:

 图书馆(地图)

##开始绘图&安培;从正交图中提取坐标
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)])))

##围绕着色海洋的点绘制圆圈
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)


I have a shapefile of world countries, downloaded from here. I can plot it in R using

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))

Now I wanna plot it in orthographic projection (Earth seen from outer space), so I'm trying

countries <- spTransform(countries,CRS("+proj=ortho +lat_0=-10 +lon_0=-60"))

I also played with the x_0 and y_0 parameters (as stated here), but I always get the error:

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

sometimes in the 3rd polygon, sometimes in the 7th. Where are those "Inf" coming from? I need to change any parameter? I want to plot the map like this

but centered above South America. Thanks for your help!

解决方案

Give the maps package a try. It gives a warning about the points that cannot be projected, but it does not give an error and shut the process down. With a little fiddling, namely setting the fill color for the ocean (this answer helped solve that problem), I was able to emulate the map you attached with a couple lines:

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)

这篇关于在正投影中绘制世界地图是给出“非有限点”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆