2012-07-15 146 views
6

如何防止国家多边形在不同预测下被切断?防止海岸线的局部映射

在下面的例子中,我想做一个南极洲的立体投影地图,包括纬度< -45°S。通过将我的y限制设置为这个范围,绘图区域是正确的,但是国家多边形也在这些极限处裁剪。有没有办法将海岸线绘制到绘图区域的边缘?

感谢您的任何建议。

library(maps) 
library(mapproj) 

ylim=c(-90,-45) 
orientation=c(-90, 0, 0) 

x11() 
par(mar=c(1,1,1,1)) 
m <- map("world", plot=FALSE) 
map("world",project="stereographic", orientation=orientation, ylim=ylim) 
map.grid(m, nx=18,ny=18, col=8) 
box() 

enter image description here

回答

7

的问题是,因为你是一个specifing最大的-45 ylim,数据正在以纬度精确地切割。很明显,情节的实际界限是以一种单独的方式计算的,这可能是基于由此产生的预计限制(但是我没有探索源代码我一无所知)进行某种保守的假设。

您可以避免通过建立一个虚拟的情节不绘制海岸线,然后添加数据的顶部增加ylim问题:

library(maps) 
library(mapproj) 

ylim = c(-90,-45) 
orientation=c(-90, 0, 0) 

x11() 
par(mar=c(1,1,1,1)) 
m <- map("world", plot=FALSE) 
map("world",project="stereographic", orientation=orientation, ylim=ylim, col = "transparent") 
map("world",project="stereographic", orientation=orientation, ylim=ylim + c(-5, 5), add = TRUE) 
map.grid(m, nx=18,ny=18, col=8) 
box() 

顺便说一句,这个策略不会为工作所有的预测,因为一些意味着重叠的一些数据限制,但极地立体摄影只是从中心延伸出来,所以这里没有这样的问题。

此外,将会有一个更新的方式来做到这一点与maptools,rgdal和rgeos,这将允许您使用数据共享一个合适的PROJ.4立体投影(但我还没有弄清楚削减步)。 mapproj中的预测是“仅用于形状”,将其他数据转化为afaik将是一项工作。

+0

非常好 - 非常感谢。很棒! – 2012-07-15 09:39:24

3

我意识到另一种选择是定义绘图区域的限制而不是地图本身。这可能给确定绘图区域(即xaxs =“i”和yaxs =“i”)提供一定的灵活性。您还可以保证绘制所有的多边形 - 例如,在@mdsumner的示例中,澳大利亚缺失,并且需要扩展y限制才能正确绘制其多边形。

orientation=c(-90, 0, 0) 

ylim <- c(mapproject(x=-180,y=-45, project="stereographic", orientation=orientation)$y, mapproject(x=0,y=-45, project="stereographic", orientation=orientation)$y) 
xlim <- c(mapproject(x=-90,y=-45, project="stereographic", orientation=orientation)$x, mapproject(x=90,y=-45, project="stereographic", orientation=orientation)$x) 

x11(width=6,height=6) 
par(mar=c(1,1,1,1)) 
plot(0,0, t="n", ylim=ylim, xlim=xlim, xaxs="i", yaxs="i", xlab="", ylab="", xaxt="n", yaxt="n") 
map("world",project="stereographic", orientation=orientation, add=TRUE) 
map.grid(nx=18,ny=18, col=8) 
box() 
3

另一种方法是使用实​​际的PROJ.4投影并使用maptools包中的数据集。这是代码,在南极大陆,海洋海岸线在-90达到极点仍然存在问题(这有点烦人,并且需要找到该坐标并将其从转换后的结果中移除,或者通过拓扑工具运行以查找条子)。

library(maptools) 
data(wrld_simpl) 
xrange <- c(-180, 180, 0, 0) 
yrange <- c(-90, -45, -90, -45) 

stere <- "+proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs" 

library(rgdal) 

w <- spTransform(wrld_simpl, CRS(stere)) 

xy <- project(cbind(xrange, yrange), stere) 
plot(w, xlim = range(xy[,1]), ylim = range(xy[,2])) 
box()