以太平洋为中心的罗宾逊投影与R

时间:2015-09-15 16:42:45

标签: r dictionary ggplot2 map-projections

我试图用Rgplot在R中创建一个以太平洋为中心的罗宾逊投影...

使用spTransform将shapefile转换为Robinson CRS并将经度设置为150度不起作用,并且fortify出错。

像这样:

world_robin <- spTransform(world2, CRS("+proj=robin +lon_0=150 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))
plot(world_robin, col = "khaki", bg = "azure2")

在为ggmap设置投影时,似乎没有办法在以后的过程中执行此操作: 即,

coord_map("mollweide", orientation=c(90, 0, 150)) 

这似乎是最好的,但它并不完全存在。

1 个答案:

答案 0 :(得分:2)

你需要GDAL / rgdal,这是180 vs 150但你应该能够推断。 GIS SO FTW!

library(ggplot2)
library(ggthemes)
library(sp)
library(rgdal)

# assumes you are in the ne_110m... directory
# split the world and stitch it back together again

system("ogr2ogr world_part1.shp ne_110m_admin_0_countries.shp -clipsrc -180 -90 0 90")
system("ogr2ogr world_part2.shp ne_110m_admin_0_countries.shp -clipsrc 0 -90 180 90")
system('ogr2ogr world_part1_shifted.shp world_part1.shp -dialect sqlite -sql "SELECT ShiftCoords(geometry,360,0), admin FROM world_part1"')
system("ogr2ogr world_0_360_raw.shp world_part2.shp")
system("ogr2ogr -update -append world_0_360_raw.shp world_part1_shifted.shp -nln world_0_360_raw")

world <- readOGR("ne_110m_admin_0_countries/world_0_360_raw.shp", "world_0_360_raw")
world_robin <- spTransform(world, CRS("+proj=robin +lon_0=180 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))

world_dat <- fortify(world_robin)

gg <- ggplot()
gg <- gg + geom_map(data=world_dat, map=world_dat,
                    aes(x=long, y=lat, map_id=id),
                    fill="khaki", color="black", size=0.25)
gg <- gg + coord_equal()
gg <- gg + theme_map()
gg <- gg + theme(plot.background=element_rect(fill="azure2"))
gg

enter image description here

您也可以使用gdalUtils,但它只调用系统二进制文件,您必须使用众所周知的字符串指定剪切多边形(因此system调用的字符短几个这条线。)

仅供参考:这意味着您必须在使用ggplot2进行绘图之前移动并投影所有点/形状。