如何在R中正确投影和绘制栅格 [英] How to properly project and plot raster in R

查看:81
本文介绍了如何在R中正确投影和绘制栅格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在等面积的Behrmann投影中有一个栅格,我想将其投影到Mollweide投影和绘图中.

但是,当我使用以下代码进行此操作时,绘图似乎不正确,因为地图延伸到了侧面,并且有我不希望看到的各种陆块的轮廓.超出绘图窗口.

任何人都可以帮助我让它很好地绘制吗?

谢谢!

可以从页似乎正常工作,我试图尽可能地模仿它尽可能.我认为出现问题是因为光栅图像的最左侧和最右侧重叠.如示例中所示,通过裁剪和中间投影到Lat-Lon似乎可以解决您的问题.

也许这种解决方法可以作为直接解决问题的更优雅解决方案的基础,因为对栅格进行两次重新投影并不是有益的.

 #个软件包图书馆(rgdal)库(maptools)图书馆(光栅)#定义投影mollCRS<-CRS('+ proj = moll')behrmannCRS<-CRS('+ proj = cea + lat_ts = 30')#读取数据数据(wrld_simpl)sst<-raster(〜/Downloads/sst.tif",crs = behrmannCRS)#尽量避免在接缝上重叠world_ext = projectExtent(wrld_simpl,crs = behrmannCRS)sst_crop =作物(x = sst,y = world_ext,snap ='in')#将sst转换为longlat(类似于测试文件)#以某种方式摆脱了椭圆外的多余像素sst_longlat = projectRaster(sst_crop,crs =('+ proj = longlat'))#然后转换为mollweidesst_moll<-projectRaster(sst_longlat,crs = mollCRS,over = T)wrld<-spTransform(wrld_simpl,mollCRS)#绘图结果情节(sst_moll)情节(wrld,add = TRUE) 

I have a raster in an equal area Behrmann projection and I would like to project it to the Mollweide projection and plot.

When I do this with the following code, however, the plotting doesn't seem right, as the map extends to the sides, and there are outlines of various landmasses where I wouldn't expect them.Also, the map extends beyond the plot window.

Can anyone please help me get this to plot nicely?

Thanks!

The data file used can be downloaded from this link.

Here is the code I have so far:

require(rgdal)
require(maptools)
require(raster)

data(wrld_simpl)

mollCRS <- CRS('+proj=moll')
behrmannCRS <- CRS('+proj=cea +lat_ts=30')

sst <- raster("~/Dropbox/Public/sst.tif", crs=behrmannCRS)

sst_moll <- projectRaster(sst, crs=mollCRS)
wrld <- spTransform(wrld_simpl, mollCRS)

plot(sst_moll)
plot(wrld, add=TRUE)

解决方案

Alright, since the example at this page seems to work, I tried to mimic it as much as possible. I think problems arise because the far left and far right side of the raster image overlap. Cropping and an intermediate reprojection to Lat-Lon as in the example seem to solve your problem.

Perhaps this workaround can be a basis for a more elegant solution that directly addresses the problem, as it is not benificial to reproject a raster twice.

# packages
library(rgdal)
library(maptools)
library(raster)

# define projections
mollCRS <- CRS('+proj=moll')
behrmannCRS <- CRS('+proj=cea +lat_ts=30')

# read data
data(wrld_simpl)
sst <- raster("~/Downloads/sst.tif", crs=behrmannCRS)

# crop sst to extent of world to avoid overlap on the seam
world_ext = projectExtent(wrld_simpl, crs = behrmannCRS)
sst_crop = crop(x = sst, y=world_ext, snap='in')

# convert sst to longlat (similar to test file)
# somehow this gets rid of the unwanted pixels outside the ellipse
sst_longlat = projectRaster(sst_crop, crs = ('+proj=longlat'))

# then convert to mollweide
sst_moll <- projectRaster(sst_longlat, crs=mollCRS, over=T)
wrld <- spTransform(wrld_simpl, mollCRS)

# plot results
plot(sst_moll)
plot(wrld, add=TRUE)

这篇关于如何在R中正确投影和绘制栅格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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